//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.86: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
//---- Disable all of Dear ImGui or don't implement standard windows.
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
IM_ASSERT(ImGui::IsNamedKey(key));// Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API.
// Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
IM_ASSERT((BackendUsingLegacyKeyArrays==-1||BackendUsingLegacyKeyArrays==0)&&"Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
IM_ASSERT(key >=ImGuiKey_NamedKey_BEGIN&&key<ImGuiKey_NamedKey_END&&"Support for user key indices was dropped in favor of ImGuiKey. Please update backend and user code.");
IM_ASSERT(IsNamedKey(key)&&"Support for user key indices was dropped in favor of ImGuiKey. Please update backend and user code.");
// Note that dear imgui doesn't know the semantic of each entry of io.KeysDown[]!
// Use your own indices/enums according to how your backend/engine stored them into io.KeysDown[]!
// Note that Dear ImGui doesn't know the meaning/semantic of ImGuiKey from 0..511: they are legacy native keycodes.
// Consider transitioning from 'IsKeyDown(MY_ENGINE_KEY_A)' (<1.87) to IsKeyDown(ImGuiKey_A) (>= 1.87)
boolImGui::IsKeyDown(ImGuiKeykey)
{
#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO
IM_ASSERT(key>=ImGuiKey_NamedKey_BEGIN&&key<ImGuiKey_NamedKey_END&&"Support for user key indices was dropped in favor of ImGuiKey. Please update backend & user code.");
IM_ASSERT(key>=ImGuiKey_NamedKey_BEGIN&&key<ImGuiKey_NamedKey_END&&"Support for user key indices was dropped in favor of ImGuiKey. Please update backend & user code.");
IM_ASSERT(key>=ImGuiKey_NamedKey_BEGIN&&key<ImGuiKey_NamedKey_END&&"Support for user key indices was dropped in favor of ImGuiKey. Please update backend & user code.");
IM_ASSERT(key>=ImGuiKey_NamedKey_BEGIN&&key<ImGuiKey_NamedKey_END&&"Support for user key indices was dropped in favor of ImGuiKey. Please update backend & user code.");
IM_ASSERT(g.IO.KeyMap[n]>=-1&&g.IO.KeyMap[n]<IM_ARRAYSIZE(g.IO.KeysDown)&&"io.KeyMap[] contains an out of bound value (need to be 0..512, or -1 for unmapped key)");
IM_ASSERT(g.IO.KeyMap[n]>=-1&&g.IO.KeyMap[n]<IM_ARRAYSIZE(g.IO.KeysDown)&&"io.KeyMap[] contains an out of bound value (need to be 0..511, or -1 for unmapped key)");
// Check: required key mapping (we intentionally do NOT check all keys to not pressure user into setting up everything, but Space is required and was only added in 1.60 WIP)
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
// - For 'ImGuiKey key' you can use your own indices/enums according to how your backend/engine stored them in io.KeysDown[].
// - We don't know the meaning of those value. You can use GetKeyIndex() to map a ImGuiKey_ value into the user index.
// With: IMGUI_DISABLE_OBSOLETE_KEYIO:
// - `ImGuiKey key` will assert when key < 512 will be passed, previously reserved as user keys indices
// Without IMGUI_DISABLE_OBSOLETE_KEYIO: (legacy support)
// - For 'ImGuiKey key' you can still use your legacy native/user indices according to how your backend/engine stored them in io.KeysDown[].
// With IMGUI_DISABLE_OBSOLETE_KEYIO: (this is the way forward)
// - Any use of 'ImGuiKey' will assert when key < 512 will be passed, previously reserved as native/user keys indices
// - GetKeyIndex() is pass-through and therefore deprecated (gone if IMGUI_DISABLE_OBSOLETE_KEYIO is defined)
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
IMGUI_APIintGetKeyIndex(ImGuiKeykey);// map ImGuiKey_* values into user's key index. == io.KeyMap[key]
#endif
IMGUI_APIconstchar*GetKeyName(ImGuiKeykey);// returns English name of the key
IMGUI_APIboolIsKeyDown(ImGuiKeykey);// is key being held. == io.KeysData[key - ImGuiKey_FirstKey].Down.
IMGUI_APIboolIsKeyDown(ImGuiKeykey);// is key being held.
IMGUI_APIboolIsKeyPressed(ImGuiKeykey,boolrepeat=true);// was key pressed (went from !Down to Down)? if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate
IMGUI_APIboolIsKeyReleased(ImGuiKeykey);// was key released (went from Down to !Down)?
IMGUI_APIintGetKeyPressedAmount(intkey,floatrepeat_delay,floatrate);// uses provided repeat rate/delay. return a count, most often 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate
IMGUI_APIintGetKeyPressedAmount(ImGuiKeykey,floatrepeat_delay,floatrate);// uses provided repeat rate/delay. return a count, most often 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate
IMGUI_APIconstchar*GetKeyName(ImGuiKeykey);// [DEBUG] returns English name of the key. Those names a provided for debugging purpose and are not meant to be saved persistently not compared.
IMGUI_APIvoidCaptureKeyboardFromApp(boolwant_capture_keyboard_value=true);// attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). e.g. force capture keyboard when your widget is being hovered. This is equivalent to setting "io.WantCaptureKeyboard = want_capture_keyboard_value"; after the next NewFrame() call.
// Inputs Utilities: Mouse
@ -1359,14 +1356,7 @@ enum ImGuiSortDirection_
enumImGuiKey_
{
ImGuiKey_None=0,
// Reserve range used by legacy io.KeyMap[]. Prior to 1.86 we required user to fill io.KeysDown[512] using their own native index.
// We are ditching this method but keeping a legacy path for user code doing e.g. IsKeyPressed(MY_NATIVE_KEY_CODE)
ImGuiKey_LegacyNativeKey_BEGIN=0,
ImGuiKey_LegacyNativeKey_END=512,// First index after valid range
ImGuiKey_NamedKey_BEGIN=512,
ImGuiKey_Tab=512,
ImGuiKey_Tab=512,// == ImGuiKey_NamedKey_BEGIN
ImGuiKey_LeftArrow,
ImGuiKey_RightArrow,
ImGuiKey_UpArrow,
@ -1473,17 +1463,20 @@ enum ImGuiKey_
ImGuiKey_F12,
ImGuiKey_COUNT,// No valid ImGuiKey is ever greater than this value
// Legacy range used by legacy io.KeyMap[]. Prior to 1.87 we required user to fill io.KeysDown[512] using their own native index.
// We are ditching this method but keeping a legacy path for user code doing e.g. IsKeyPressed(MY_NATIVE_KEY_CODE)
ImGuiKey_LegacyNativeKey_BEGIN=0,
ImGuiKey_LegacyNativeKey_END=512,// First index after valid range
,ImGuiKey_KeyPadEnter=ImGuiKey_KeypadEnter// Renamed in 1.87
@ -1501,7 +1494,7 @@ enum ImGuiKeyModFlags_
};
// Gamepad/Keyboard navigation
// Keyboard: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays.
// Keyboard: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. NewFrame() will automatically fill io.NavInputs[] based on your io.AddKeyEvent() calls.
// Gamepad: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. Backend: set ImGuiBackendFlags_HasGamepad and fill the io.NavInputs[] fields before calling NewFrame(). Note that io.NavInputs[] is cleared by EndFrame().
// Read instructions in imgui.cpp for more details. Download PNG/PSD at http://dearimgui.org/controls_sheets.
enumImGuiNavInput_
@ -1525,7 +1518,7 @@ enum ImGuiNavInput_
ImGuiNavInput_TweakFast,// Faster tweaks // e.g. R1 or R2 (PS4), RB or RT (Xbox), R or ZL (Switch)
// [Internal] Don't use directly! This is used internally to differentiate keyboard from gamepad inputs for behaviors that require to differentiate them.
// Keyboard behavior that have no corresponding gamepad mapping (e.g. CTRL+TAB) will be directly reading from io.KeysDown[] instead of io.NavInputs[].
// Keyboard behavior that have no corresponding gamepad mapping (e.g. CTRL+TAB) will be directly reading from keyboard keys instead of io.NavInputs[].
ImGuiNavInput_KeyLeft_,// Move left // = Arrow keys
ImGuiNavInput_KeyRight_,// Move right
ImGuiNavInput_KeyUp_,// Move up
@ -1538,7 +1531,7 @@ enum ImGuiNavInput_
enumImGuiConfigFlags_
{
ImGuiConfigFlags_None=0,
ImGuiConfigFlags_NavEnableKeyboard=1<<0,// Master keyboard navigation enable flag. NewFrame() will automatically fill io.NavInputs[] based on io.KeysDown[].
ImGuiConfigFlags_NavEnableKeyboard=1<<0,// Master keyboard navigation enable flag. NewFrame() will automatically fill io.NavInputs[] based on io.AddKeyEvent() calls
ImGuiConfigFlags_NavEnableGamepad=1<<1,// Master gamepad navigation enable flag. This is mostly to instruct your imgui backend to fill io.NavInputs[]. Backend also needs to set ImGuiBackendFlags_HasGamepad.
ImGuiConfigFlags_NavEnableSetMousePos=1<<2,// Instruct navigation to move the mouse cursor. May be useful on TV/console systems where moving a virtual mouse is awkward. Will update io.MousePos and set io.WantSetMousePos=true. If enabled you MUST honor io.WantSetMousePos requests in your backend, otherwise ImGui will react as if the mouse is jumping around back and forth.
ImGuiConfigFlags_NavNoCaptureKeyboard=1<<3,// Instruct navigation to not set the io.WantCaptureKeyboard flag when io.NavActive is set.
@ -1927,11 +1920,13 @@ struct ImGuiStyle
// Access via ImGui::GetIO(). Read 'Programmer guide' section in .cpp file for general usage.
// [Internal] Storage used by IsKeyDown(), IsKeyPressed() etc functions.
// If prior to 1.87 you used io.KeysDownDuration[] (which was marked as internal), you should use GetKeyData(key)->DownDuration and not io.KeysData[key]->DownDuration.
structImGuiKeyData
{
boolDown;// True for if key is down
floatDownDuration;// Duration the keyboard key has been down (0.0f == just pressed)
floatDownDurationPrev;// Previous duration the key has been down
floatDownDuration;// Duration the key has been down (<0.0f: not pressed, 0.0f: just pressed, >0.0f: time held)
floatDownDurationPrev;// Last frame duration the key has been down
};
structImGuiIO
@ -2011,23 +2006,14 @@ struct ImGuiIO
floatNavInputs[ImGuiNavInput_COUNT];// Gamepad inputs. Cleared back to zero by EndFrame(). Keyboard keys will be auto-mapped and be written here by NewFrame().
// Input Functions
IMGUI_APIvoidAddKeyEvent(ImGuiKeykey,booldown, intnative_keycode=-1,intnative_scancode=-1);// Notify Dear ImGui of key down/up event
IMGUI_APIvoidAddKeyEvent(ImGuiKeykey,booldown);// Queue a new key down/up event. Key should be "translated" (as in, generally ImGuiKey_A matches the key end-user would use to emit an 'A' character)
IMGUI_APIvoidAddFocusEvent(boolfocused);// Queue an hosting application/platform windows gain or loss of focus
IMGUI_APIvoidAddInputCharacter(unsignedintc);// Queue new character input
IMGUI_APIvoidAddInputCharacterUTF16(ImWchar16c);// Queue new character input from an UTF-16 character, it can be a surrogate
IMGUI_APIvoidAddInputCharactersUTF8(constchar*str);// Queue new characters input from an UTF-8 string
IMGUI_APIvoidClearInputCharacters();// [Internal] Clear the text input buffer manually
IMGUI_APIvoidClearInputKeys();// [Internal] Release all keys
intKeyMap[ImGuiKey_COUNT];// [LEGACY] Input: map of indices into the KeysDown[512] entries array which represent your "native" keyboard state. The first 512 are now unused and should be kept zero. Legacy backend will write into KeyMap[] using ImGuiKey_ indices which are always >512.
boolKeysDown[512];// [LEGACY] Input: Keyboard keys that are pressed (ideally left in the "native" order your engine has access to keyboard keys, so you can use your own defines/enums for keys).
#endif
IMGUI_APIvoidSetKeyEventNativeData(ImGuiKeykey,intnative_keycode,intnative_scancode,intnative_legacy_index=-1);// [Optional] Specify index for legacy <1.87 IsKeyXXX() functions with native indices + specify native keycode, scancode.
// Output - Updated by NewFrame() or EndFrame()/Render()
@ -2050,13 +2036,20 @@ struct ImGuiIO
intMetricsActiveAllocations;// Number of active allocations, updated by MemAlloc/MemFree based on current context. May be off if you have multiple imgui contexts.
ImVec2MouseDelta;// Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta.
// Legacy: before 1.87, we required backend to fill io.KeyMap[] (imgui->native map) during initialization and io.KeysDown[] (native indices) every frame.
// This is still temporarily supported as a legacy feature. However the new preferred scheme is for backend to call io.AddKeyEvent().
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
intKeyMap[ImGuiKey_COUNT];// [LEGACY] Input: map of indices into the KeysDown[512] entries array which represent your "native" keyboard state. The first 512 are now unused and should be kept zero. Legacy backend will write into KeyMap[] using ImGuiKey_ indices which are always >512.
boolKeysDown[512];// [LEGACY] Input: Keyboard keys that are pressed (ideally left in the "native" order your engine has access to keyboard keys, so you can use your own defines/enums for keys).
ImGuiKeyDataKeysData[ImGuiKey_KeyIndex_COUNT];// Key state for all known keys.
ImGuiKeyDataKeysData[ImGuiKey_KeysData_SIZE];// Key state for all known keys. Use IsKeyXXX() functions to access this.
boolWantCaptureMouseUnlessPopupClose;// Alternative to WantCaptureMouse: (WantCaptureMouse == true && WantCaptureMouseUnlessPopupClose == false) when a click over void is expected to close a popup.
ImVec2MousePosPrev;// Previous mouse position (note that MouseDelta is not necessary == MousePos-MousePosPrev, in case either position is invalid)
staticinlineintGetKeyIndex(ImGuiKeykey){IM_ASSERT(key>=ImGuiKey_NamedKey_BEGIN&&key<ImGuiKey_NamedKey_END&&"ImGuiKey and user_key_index was merged together and user_key_index is disabled by IMGUI_DISABLE_OBSOLETE_KEYIO. Please switch to ImGuiKey.");returnkey;}
staticinlineintGetKeyIndex(ImGuiKeykey){IM_ASSERT(key>=ImGuiKey_NamedKey_BEGIN&&key<ImGuiKey_NamedKey_END&&"ImGuiKey and native_index was merged together and native_index is disabled by IMGUI_DISABLE_OBSOLETE_KEYIO. Please switch to ImGuiKey.");returnkey;}
#endif
}
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
namespaceImGui
{
// OBSOLETED in 1.86 (from November 2021)
IMGUI_APIvoidCalcListClipping(intitems_count,floatitems_height,int*out_items_display_start,int*out_items_display_end);// Calculate coarse clipping for large list of evenly sized items. Prefer using ImGuiListClipper.
structfuncs{staticboolIsNativeDupe(ImGuiKeykey){returnkey<ImGuiKey_LegacyNativeKey_END&&ImGui::GetIO().KeyMap[key]!=-1;}};// Hide Native<>ImGuiKey duplicates when both exists in the array
ImGui::Text("Chars queue:");for(inti=0;i<io.InputQueueCharacters.Size;i++){ImWcharc=io.InputQueueCharacters[i];ImGui::SameLine();ImGui::Text("\'%c\' (0x%04X)",(c>''&&c<=255)?(char)c:'?',c);}// FIXME: We should convert 'c' to UTF-8 here but the functions are not public.