// Important: unlike legacy IsKeyPressed(ImGuiKey, bool repeat=true) which DEFAULT to repeat, this requires EXPLICIT repeat.
// [Internal] 2022/07: Do not call this directly! It is a temporary entry point which we will soon replace with an overload for IsKeyPressed() when we introduce key ownership.
IM_ASSERT(io.NavInputs[n]==0.0f&&"Backend needs to either only use io.AddKeyEvent()/io.AddKeyAnalogEvent(), either only fill legacy io.NavInputs[]. Not both!");
#define NAV_MAP_KEY(_KEY, _NAV_INPUT, _ACTIVATE_NAV) do { io.NavInputs[_NAV_INPUT] = io.KeysData[_KEY - ImGuiKey_KeysData_OFFSET].AnalogValue; if (_ACTIVATE_NAV && io.NavInputs[_NAV_INPUT] > 0.0f) { g.NavInputSource = ImGuiInputSource_Gamepad; } } while (0)
// Single press toggles NavLayer, long press with L/R apply actual focus on release (until then the window was merely rendered top-most)
if(!IsNavInputDown(ImGuiNavInput_Menu))
if(!IsKeyDown(ImGuiKey_NavGamepadMenu))
{
g.NavWindowingToggleLayer&=(g.NavWindowingHighlightAlpha<1.0f);// Once button was held long enough we don't consider it a tap-to-toggle-layer press anymore.
Text("HoveredId: 0x%08X (%.2f sec), AllowOverlap: %d",g.HoveredIdPreviousFrame,g.HoveredIdTimer,g.HoveredIdAllowOverlap);// Not displaying g.HoveredId as it is update mid-frame
// (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)
ImGuiKey_GamepadFaceLeft,// X (Xbox) Y (Switch) Square (PS) // Tap: Toggle Menu. Hold: Windowing mode (Focus/Move/Resize windows)
ImGuiKey_GamepadFaceRight,// B (Xbox) A (Switch) Circle (PS) // Cancel / Close / Exit
ImGuiKey_GamepadFaceUp,// Y (Xbox) X (Switch) Triangle (PS) // Text Input / On-screen Keyboard
ImGuiKey_GamepadFaceDown,// A (Xbox) B (Switch) Cross (PS) // Activate / Open / Toggle / Tweak
ImGuiKey_GamepadDpadLeft,// D-pad Left // Move / Tweak / Resize Window (in Windowing mode)
ImGuiKey_GamepadDpadRight,// D-pad Right // Move / Tweak / Resize Window (in Windowing mode)
ImGuiKey_GamepadDpadUp,// D-pad Up // Move / Tweak / Resize Window (in Windowing mode)
ImGuiKey_GamepadDpadDown,// D-pad Down // Move / Tweak / Resize Window (in Windowing mode)
ImGuiKey_GamepadL1,// L Bumper (Xbox) L (Switch) L1 (PS) // Tweak Slower / Focus Previous (in Windowing mode)
ImGuiKey_GamepadR1,// R Bumper (Xbox) R (Switch) R1 (PS) // Tweak Faster / Focus Next (in Windowing mode)
ImGuiKey_GamepadL2,// L Trig. (Xbox) ZL (Switch) L2 (PS) [Analog]
ImGuiKey_GamepadR2,// R Trig. (Xbox) ZR (Switch) R2 (PS) [Analog]
ImGuiKey_GamepadL3,// L Stick (Xbox) L3 (Switch) L3 (PS)
ImGuiKey_GamepadR3,// R Stick (Xbox) R3 (Switch) R3 (PS)
ImGuiKey_GamepadLStickLeft,// [Analog] // Move Window (in Windowing mode)
ImGuiKey_GamepadLStickRight,// [Analog] // Move Window (in Windowing mode)
ImGuiKey_GamepadLStickUp,// [Analog] // Move Window (in Windowing mode)
ImGuiKey_GamepadLStickDown,// [Analog] // Move Window (in Windowing mode)
ImGuiKey_GamepadRStickLeft,// [Analog]
ImGuiKey_GamepadRStickRight,// [Analog]
ImGuiKey_GamepadRStickUp,// [Analog]
@ -1463,46 +1463,24 @@ enum ImGuiModFlags_
ImGuiModFlags_Super=1<<3,// Cmd/Super/Windows key
};
// Gamepad/Keyboard navigation
// Since >= 1.87 backends you generally don't need to care about this enum since io.NavInputs[] is setup automatically. This might become private/internal some day.
// 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_
{
// Gamepad Mapping
ImGuiNavInput_Activate,// Activate / Open / Toggle / Tweak value // e.g. Cross (PS4), A (Xbox), A (Switch), Space (Keyboard)
ImGuiNavInput_Cancel,// Cancel / Close / Exit // e.g. Circle (PS4), B (Xbox), B (Switch), Escape (Keyboard)
ImGuiNavInput_Input,// Text input / On-Screen keyboard // e.g. Triang.(PS4), Y (Xbox), X (Switch), Return (Keyboard)
ImGuiNavInput_Menu,// Tap: Toggle menu / Hold: Focus, Move, Resize // e.g. Square (PS4), X (Xbox), Y (Switch), Alt (Keyboard)
ImGuiNavInput_LStickLeft,// Scroll / Move window (w/ PadMenu) // e.g. Left Analog Stick Left/Right/Up/Down
ImGuiNavInput_LStickRight,//
ImGuiNavInput_LStickUp,//
ImGuiNavInput_LStickDown,//
ImGuiNavInput_FocusPrev,// Focus Next window (w/ PadMenu) // e.g. L1 or L2 (PS4), LB or LT (Xbox), L or ZL (Switch)
ImGuiNavInput_FocusNext,// Focus Prev window (w/ PadMenu) // e.g. R1 or R2 (PS4), RB or RT (Xbox), R or ZL (Switch)
ImGuiNavInput_TweakSlow,// Slower tweaks // e.g. L1 or L2 (PS4), LB or LT (Xbox), L or ZL (Switch)
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 keyboard keys instead of io.NavInputs[].
ImGuiNavInput_KeyLeft_,// Move left // = Arrow keys
ImGuiNavInput_KeyRight_,// Move right
ImGuiNavInput_KeyUp_,// Move up
ImGuiNavInput_KeyDown_,// Move down
ImGuiNavInput_COUNT
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
// OBSOLETED in 1.88 (from July 2022): ImGuiNavInput and io.NavInputs[].
// Official backends between 1.60 and 1.86: will keep working and feed gamepad inputs as long as IMGUI_DISABLE_OBSOLETE_KEYIO is not set.
// Custom backends: feed gamepad inputs via io.AddKeyEvent() and ImGuiKey_GamepadXXX enums.
// Configuration flags stored in io.ConfigFlags. Set by user/application.
enumImGuiConfigFlags_
{
ImGuiConfigFlags_None=0,
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_NavEnableGamepad=1<<1,// Master gamepad navigation enable flag. 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.
ImGuiConfigFlags_NoMouse=1<<4,// Instruct imgui to clear mouse position/buttons in NewFrame(). This allows ignoring the mouse information set by the backend.
@ -2011,6 +1989,7 @@ struct ImGuiIO
#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[ImGuiKey_COUNT];// [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). This used to be [512] sized. It is now ImGuiKey_COUNT to allow legacy io.KeysDown[GetKeyIndex(...)] to work without an overflow.
floatNavInputs[ImGuiNavInput_COUNT];// [LEGACY] Since 1.88, NavInputs[] was removed. Backends from 1.60 to 1.86 won't build. Feed gamepad inputs via io.AddKeyEvent() and ImGuiKey_GamepadXXX enums.
floatNavInputs[ImGuiNavInput_COUNT];// Gamepad inputs. Cleared back to zero by EndFrame(). Keyboard keys will be auto-mapped and be written here by NewFrame().
// Other state maintained from data above + IO function calls
ImGuiModFlagsKeyMods;// Key mods flags (same as io.KeyCtrl/KeyShift/KeyAlt/KeySuper but merged into flags), updated by NewFrame()
@ -2047,8 +2025,6 @@ struct ImGuiIO
floatMouseDownDuration[5];// Duration the mouse button has been down (0.0f == just clicked)
floatMouseDownDurationPrev[5];// Previous time the mouse button has been down
floatMouseDragMaxDistanceSqr[5];// Squared maximum distance of how much mouse has traveled from the clicking point (used for moving thresholds)
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.
// FIXME-NAV: Clarify/expose various repeat delay/rate
enumImGuiNavReadMode
// Flags for IsKeyPressedEx(). In upcoming feature this will be used more (and IsKeyPressedEx() renamed)
// Don't mistake with ImGuiInputTextFlags! (for ImGui::InputText() function)
enumImGuiInputReadFlags_
{
ImGuiNavReadMode_Down,
ImGuiNavReadMode_Repeat,
ImGuiNavReadMode_RepeatSlow,
ImGuiNavReadMode_RepeatFast,
// Flags for IsKeyPressedEx()
ImGuiInputReadFlags_None=0,
ImGuiInputReadFlags_Repeat=1<<0,// Return true on successive repeats. Default for legacy IsKeyPressed(). NOT Default for legacy IsMouseClicked(). MUST BE == 1.
ImGuiNavLayer_Menu=1,// Menu layer (access with Alt/ImGuiNavInput_Menu)
ImGuiNavLayer_Menu=1,// Menu layer (access with Alt)
ImGuiNavLayer_COUNT
};
@ -1645,8 +1653,10 @@ struct ImGuiContext
// Input Ownership
boolActiveIdUsingMouseWheel;// Active widget will want to read mouse wheel. Blocks scrolling the underlying window.
ImU32ActiveIdUsingNavDirMask;// Active widget will want to read those nav move requests (e.g. can activate a button and move away from it)
ImU32ActiveIdUsingNavInputMask;// Active widget will want to read those nav inputs.
ImBitArrayForNamedKeysActiveIdUsingKeyInputMask;// Active widget will want to read those key inputs. When we grow the ImGuiKey enum we'll need to either to order the enum to make useful keys come first, either redesign this into e.g. a small array.
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
ImU32ActiveIdUsingNavInputMask;// If you used this. Since (IMGUI_VERSION_NUM >= 18804) : 'g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel);' becomes 'SetActiveIdUsingKey(ImGuiKey_Escape); SetActiveIdUsingKey(ImGuiKey_NavGamepadCancel);'
ImGuiIDNavActivateInputId;// ~~ IsNavInputPressed(ImGuiNavInput_Input) ? NavId : 0; ImGuiActivateFlags_PreferInput will be set and NavActivateId will be 0.
ImGuiIDNavActivateId;// ~~ (g.ActiveId == 0) && (IsKeyPressed(ImGuiKey_Space) || IsKeyPressed(ImGuiKey_NavGamepadActivate)) ? NavId : 0, also set when calling ActivateItem()
ImGuiIDNavActivateInputId;// ~~ IsKeyPressed(ImGuiKey_Enter) || IsKeyPressed(ImGuiKey_NavGamepadInput) ? NavId : 0; ImGuiActivateFlags_PreferInput will be set and NavActivateId will be 0.
ImGuiActivateFlagsNavActivateFlags;
ImGuiIDNavJustMovedToId;// Just navigated to this id (result of a successfully MoveRequest).
ImGuiIDNavJustMovedToFocusScopeId;// Just navigated to this focus scope id (result of a successfully MoveRequest).
IMGUI_APIvoidActivateItem(ImGuiIDid);// Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again.
// We allow validate/cancel with Nav source (gamepad) to makes it easier to undo an accidental NavInput press with no keyboard wired, but otherwise it isn't very useful.