mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-24 07:40:22 +01:00
Removed io.NavInputs[] and ImGuiNavInput enum. Kept inline redirection code. (#4921, #4858, #787, #1599, #323)
This commit is contained in:
parent
a7a25ee19d
commit
8b8a61bdf9
@ -37,6 +37,21 @@ HOW TO UPDATE?
|
||||
|
||||
Breaking changes:
|
||||
|
||||
- Removed io.NavInputs[] and ImGuiNavInput enum that were used to feed gamepad inputs.
|
||||
Basically 1.87 already obsoleted them from the backend's point of view, but internally
|
||||
our navigation code still used this array and enum, so they were still present.
|
||||
Not anymore! (#4921, #4858, #787, #1599, #323)
|
||||
Transition guide:
|
||||
- Official backends from 1.87+ -> no issue.
|
||||
- Official backends from 1.60 to 1.86 -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need updating!
|
||||
- Custom backends not writing to io.NavInputs[] -> no issue.
|
||||
- Custom backends writing to io.NavInputs[] -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need fixing!
|
||||
- TL;DR: Backends should call io.AddKeyEvent()/io.AddKeyAnalogEvent() with ImGuiKey_GamepadXXX values instead of filling io.NavInput[].
|
||||
That data was essentially 1.60's attempt to combine keyboard and gamepad inputs with named
|
||||
semantic, but the additional indirection and copy added complexity and got in the way of other
|
||||
incoming work. User's code (other than backends) should not be affected, unless you have custom
|
||||
widgets intercepting navigation events via the named enums (in which case you can upgrade your code).
|
||||
|
||||
Other Changes:
|
||||
|
||||
- InputText: added experimental io.ConfigInputTextEnterKeepActive feature to make pressing
|
||||
|
267
imgui.cpp
267
imgui.cpp
@ -132,7 +132,7 @@ CODE
|
||||
- ESCAPE to revert text to its original value.
|
||||
- Controls are automatically adjusted for OSX to match standard OSX text editing operations.
|
||||
- General Keyboard controls: enable with ImGuiConfigFlags_NavEnableKeyboard.
|
||||
- General Gamepad controls: enable with ImGuiConfigFlags_NavEnableGamepad. See suggested mappings in imgui.h ImGuiNavInput_ + download PNG/PSD at http://dearimgui.org/controls_sheets
|
||||
- General Gamepad controls: enable with ImGuiConfigFlags_NavEnableGamepad. Download controller mapping PNG/PSD at http://dearimgui.org/controls_sheets
|
||||
|
||||
|
||||
PROGRAMMER GUIDE
|
||||
@ -345,12 +345,10 @@ CODE
|
||||
USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS
|
||||
------------------------------------------
|
||||
- The gamepad/keyboard navigation is fairly functional and keeps being improved.
|
||||
- Gamepad support is particularly useful to use Dear ImGui on a console system (e.g. PS4, Switch, XB1) without a mouse!
|
||||
- You can ask questions and report issues at https://github.com/ocornut/imgui/issues/787
|
||||
- Gamepad support is particularly useful to use Dear ImGui on a console system (e.g. PlayStation, Switch, Xbox) without a mouse!
|
||||
- The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable.
|
||||
- Keyboard:
|
||||
- Application: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable.
|
||||
- Internally: NewFrame() will automatically fill io.NavInputs[] based on backend's io.AddKeyEvent() calls.
|
||||
- When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard),
|
||||
the io.WantCaptureKeyboard flag will be set. For more advanced uses, you may want to read from:
|
||||
- io.NavActive: true when a window is focused and it doesn't have the ImGuiWindowFlags_NoNavInputs flag set.
|
||||
@ -362,8 +360,7 @@ CODE
|
||||
- Backend: Set io.BackendFlags |= ImGuiBackendFlags_HasGamepad + call io.AddKeyEvent/AddKeyAnalogEvent() with ImGuiKey_Gamepad_XXX keys.
|
||||
For analog values (0.0f to 1.0f), backend is responsible to handling a dead-zone and rescaling inputs accordingly.
|
||||
Backend code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.).
|
||||
- Internally: NewFrame() will automatically fill io.NavInputs[] based on backend's io.AddKeyEvent() + io.AddKeyAnalogEvent() calls.
|
||||
- BEFORE 1.87, BACKENDS USED TO WRITE DIRECTLY TO io.NavInputs[]. This is going to be obsoleted in the future. Please call io functions instead!
|
||||
- BEFORE 1.87, BACKENDS USED TO WRITE TO io.NavInputs[]. This is now obsolete. Please call io functions instead!
|
||||
- You can download PNG/PSD files depicting the gamepad controls for common controllers at: http://dearimgui.org/controls_sheets
|
||||
- If you need to share inputs between your game and the Dear ImGui interface, the easiest approach is to go all-or-nothing,
|
||||
with a buttons combo to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved.
|
||||
@ -387,6 +384,12 @@ CODE
|
||||
When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
|
||||
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
|
||||
|
||||
- 2022/07/08 (1.88) - inputs: removed io.NavInputs[] and ImGuiNavInput enum (following 1.87 changes).
|
||||
- Official backends from 1.87+ -> no issue.
|
||||
- Official backends from 1.60 to 1.86 -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need updating!
|
||||
- Custom backends not writing to io.NavInputs[] -> no issue.
|
||||
- Custom backends writing to io.NavInputs[] -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need fixing!
|
||||
- TL;DR: Backends should call io.AddKeyEvent()/io.AddKeyAnalogEvent() with ImGuiKey_GamepadXXX values instead of filling io.NavInput[].
|
||||
- 2022/06/15 (1.88) - renamed IMGUI_DISABLE_METRICS_WINDOW to IMGUI_DISABLE_DEBUG_TOOLS for correctness. kept support for old define (will obsolete).
|
||||
- 2022/05/03 (1.88) - backends: osx: removed ImGui_ImplOSX_HandleEvent() from backend API in favor of backend automatically handling event capture. All ImGui_ImplOSX_HandleEvent() calls should be removed as they are now unnecessary.
|
||||
- 2022/04/05 (1.88) - inputs: renamed ImGuiKeyModFlags to ImGuiModFlags. Kept inline redirection enums (will obsolete). This was never used in public API functions but technically present in imgui.h and ImGuiIO.
|
||||
@ -1171,7 +1174,6 @@ ImGuiIO::ImGuiIO()
|
||||
MouseDragThreshold = 6.0f;
|
||||
for (int i = 0; i < IM_ARRAYSIZE(MouseDownDuration); i++) MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f;
|
||||
for (int i = 0; i < IM_ARRAYSIZE(KeysData); i++) { KeysData[i].DownDuration = KeysData[i].DownDurationPrev = -1.0f; }
|
||||
for (int i = 0; i < IM_ARRAYSIZE(NavInputsDownDuration); i++) NavInputsDownDuration[i] = -1.0f;
|
||||
AppAcceptingEvents = true;
|
||||
BackendUsingLegacyKeyArrays = (ImS8)-1;
|
||||
BackendUsingLegacyNavInputArray = true; // assume using legacy array until proven wrong
|
||||
@ -1262,8 +1264,6 @@ void ImGuiIO::ClearInputKeys()
|
||||
}
|
||||
KeyCtrl = KeyShift = KeyAlt = KeySuper = false;
|
||||
KeyMods = ImGuiModFlags_None;
|
||||
for (int n = 0; n < IM_ARRAYSIZE(NavInputsDownDuration); n++)
|
||||
NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f;
|
||||
}
|
||||
|
||||
// Queue a new key down/up event.
|
||||
@ -3425,8 +3425,10 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
|
||||
// (Please note that this is WIP and not all keys/inputs are thoroughly declared by all widgets yet)
|
||||
g.ActiveIdUsingMouseWheel = false;
|
||||
g.ActiveIdUsingNavDirMask = 0x00;
|
||||
g.ActiveIdUsingNavInputMask = 0x00;
|
||||
g.ActiveIdUsingKeyInputMask.ClearAllBits();
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
g.ActiveIdUsingNavInputMask = 0x00;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ImGui::ClearActiveID()
|
||||
@ -4005,6 +4007,31 @@ static void ImGui::UpdateKeyboardInputs()
|
||||
io.KeysData[ImGuiKey_ModSuper].Down = io.KeySuper;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
|
||||
if (io.BackendUsingLegacyNavInputArray && nav_gamepad_active)
|
||||
{
|
||||
#define MAP_LEGACY_NAV_INPUT_TO_KEY1(_KEY, _NAV1) do { io.KeysData[_KEY].Down = (io.NavInputs[_NAV1] > 0.0f); io.KeysData[_KEY].AnalogValue = io.NavInputs[_NAV1]; } while (0)
|
||||
#define MAP_LEGACY_NAV_INPUT_TO_KEY2(_KEY, _NAV1, _NAV2) do { io.KeysData[_KEY].Down = (io.NavInputs[_NAV1] > 0.0f) || (io.NavInputs[_NAV2] > 0.0f); io.KeysData[_KEY].AnalogValue = ImMax(io.NavInputs[_NAV1], io.NavInputs[_NAV2]); } while (0)
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceDown, ImGuiNavInput_Activate);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceRight, ImGuiNavInput_Cancel);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceLeft, ImGuiNavInput_Menu);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceUp, ImGuiNavInput_Input);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadLeft, ImGuiNavInput_DpadLeft);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadRight, ImGuiNavInput_DpadRight);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadUp, ImGuiNavInput_DpadUp);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadDown, ImGuiNavInput_DpadDown);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY2(ImGuiKey_GamepadL1, ImGuiNavInput_FocusPrev, ImGuiNavInput_TweakSlow);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY2(ImGuiKey_GamepadR1, ImGuiNavInput_FocusNext, ImGuiNavInput_TweakFast);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickLeft, ImGuiNavInput_LStickLeft);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickRight, ImGuiNavInput_LStickRight);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickUp, ImGuiNavInput_LStickUp);
|
||||
MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickDown, ImGuiNavInput_LStickDown);
|
||||
#undef NAV_MAP_KEY
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Synchronize io.KeyMods with individual modifiers io.KeyXXX bools
|
||||
@ -4384,7 +4411,6 @@ void ImGui::NewFrame()
|
||||
if (g.ActiveId == 0)
|
||||
{
|
||||
g.ActiveIdUsingNavDirMask = 0x00;
|
||||
g.ActiveIdUsingNavInputMask = 0x00;
|
||||
g.ActiveIdUsingKeyInputMask.ClearAllBits();
|
||||
}
|
||||
|
||||
@ -4902,7 +4928,6 @@ void ImGui::EndFrame()
|
||||
// Clear Input data for next frame
|
||||
g.IO.MouseWheel = g.IO.MouseWheelH = 0.0f;
|
||||
g.IO.InputQueueCharacters.resize(0);
|
||||
memset(g.IO.NavInputs, 0, sizeof(g.IO.NavInputs));
|
||||
|
||||
CallContextHooks(&g, ImGuiContextHookType_EndFramePost);
|
||||
}
|
||||
@ -5175,7 +5200,6 @@ void ImGui::SetActiveIdUsingNavAndKeys()
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(g.ActiveId != 0);
|
||||
g.ActiveIdUsingNavDirMask = ~(ImU32)0;
|
||||
g.ActiveIdUsingNavInputMask = ~(ImU32)0;
|
||||
g.ActiveIdUsingKeyInputMask.SetAllBits();
|
||||
NavMoveRequestCancel();
|
||||
}
|
||||
@ -5719,9 +5743,9 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
|
||||
{
|
||||
ImVec2 nav_resize_dir;
|
||||
if (g.NavInputSource == ImGuiInputSource_Keyboard && g.IO.KeyShift)
|
||||
nav_resize_dir = ImVec2((float)IsKeyDown(ImGuiKey_RightArrow) - (float)IsKeyDown(ImGuiKey_LeftArrow), (float)IsKeyDown(ImGuiKey_DownArrow) - (float)IsKeyDown(ImGuiKey_UpArrow));
|
||||
nav_resize_dir = GetKeyVector2d(ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_UpArrow, ImGuiKey_DownArrow);
|
||||
if (g.NavInputSource == ImGuiInputSource_Gamepad)
|
||||
nav_resize_dir = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadDPad, ImGuiNavReadMode_Down);
|
||||
nav_resize_dir = GetKeyVector2d(ImGuiKey_GamepadDpadLeft, ImGuiKey_GamepadDpadRight, ImGuiKey_GamepadDpadUp, ImGuiKey_GamepadDpadDown);
|
||||
if (nav_resize_dir.x != 0.0f || nav_resize_dir.y != 0.0f)
|
||||
{
|
||||
const float NAV_RESIZE_SPEED = 600.0f;
|
||||
@ -6609,7 +6633,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
/*
|
||||
//if (g.NavWindow == window && g.ActiveId == 0)
|
||||
if (g.ActiveId == window->MoveId)
|
||||
if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C))
|
||||
if (g.IO.KeyCtrl && IsKeyPressed(ImGuiKey_C))
|
||||
LogToClipboard();
|
||||
*/
|
||||
|
||||
@ -7668,6 +7692,19 @@ int ImGui::CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, flo
|
||||
return count;
|
||||
}
|
||||
|
||||
void ImGui::GetTypematicRepeatRate(ImGuiInputReadFlags flags, float* repeat_delay, float* repeat_rate)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
switch (flags & ImGuiInputReadFlags_RepeatRateMask_)
|
||||
{
|
||||
case ImGuiInputReadFlags_RepeatRateNavMove: *repeat_delay = g.IO.KeyRepeatDelay * 0.72f; *repeat_rate = g.IO.KeyRepeatRate * 0.80f; return;
|
||||
case ImGuiInputReadFlags_RepeatRateNavTweak: *repeat_delay = g.IO.KeyRepeatDelay * 0.72f; *repeat_rate = g.IO.KeyRepeatRate * 0.30f; return;
|
||||
case ImGuiInputReadFlags_RepeatRateDefault: default: *repeat_delay = g.IO.KeyRepeatDelay * 1.00f; *repeat_rate = g.IO.KeyRepeatRate * 1.00f; return;
|
||||
}
|
||||
}
|
||||
|
||||
// Return value representing the number of presses in the last time period, for the given repeat rate
|
||||
// (most often returns 0 or 1. The result is generally only >1 when RepeatRate is smaller than DeltaTime, aka large DeltaTime or fast RepeatRate)
|
||||
int ImGui::GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float repeat_rate)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -7676,6 +7713,14 @@ int ImGui::GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float repeat_ra
|
||||
return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, repeat_delay, repeat_rate);
|
||||
}
|
||||
|
||||
// Return 2D vector representing the combination of four cardinal direction, with analog value support (for e.g. ImGuiKey_GamepadLStick* values).
|
||||
ImVec2 ImGui::GetKeyVector2d(ImGuiKey key_left, ImGuiKey key_right, ImGuiKey key_up, ImGuiKey key_down)
|
||||
{
|
||||
return ImVec2(
|
||||
GetKeyData(key_right)->AnalogValue - GetKeyData(key_left)->AnalogValue,
|
||||
GetKeyData(key_down)->AnalogValue - GetKeyData(key_up)->AnalogValue);
|
||||
}
|
||||
|
||||
// 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)
|
||||
bool ImGui::IsKeyDown(ImGuiKey key)
|
||||
@ -7688,12 +7733,26 @@ bool ImGui::IsKeyDown(ImGuiKey key)
|
||||
|
||||
bool ImGui::IsKeyPressed(ImGuiKey key, bool repeat)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
return IsKeyPressedEx(key, repeat ? ImGuiInputReadFlags_Repeat : ImGuiInputReadFlags_None);
|
||||
}
|
||||
|
||||
// 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.
|
||||
bool ImGui::IsKeyPressedEx(ImGuiKey key, ImGuiInputReadFlags flags)
|
||||
{
|
||||
const ImGuiKeyData* key_data = GetKeyData(key);
|
||||
const float t = key_data->DownDuration;
|
||||
if (t < 0.0f)
|
||||
return false;
|
||||
const bool pressed = (t == 0.0f) || (repeat && t > g.IO.KeyRepeatDelay && GetKeyPressedAmount(key, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0);
|
||||
|
||||
bool pressed = (t == 0.0f);
|
||||
if (!pressed && ((flags & ImGuiInputReadFlags_Repeat) != 0))
|
||||
{
|
||||
float repeat_delay, repeat_rate;
|
||||
GetTypematicRepeatRate(flags, &repeat_delay, &repeat_rate);
|
||||
pressed = (t > repeat_delay) && GetKeyPressedAmount(key, repeat_delay, repeat_rate) > 0;
|
||||
}
|
||||
|
||||
if (!pressed)
|
||||
return false;
|
||||
return true;
|
||||
@ -10119,55 +10178,27 @@ static ImVec2 ImGui::NavCalcPreferredRefPos()
|
||||
}
|
||||
}
|
||||
|
||||
const char* ImGui::GetNavInputName(ImGuiNavInput n)
|
||||
{
|
||||
static const char* names[] =
|
||||
{
|
||||
"Activate", "Cancel", "Input", "Menu", "DpadLeft", "DpadRight", "DpadUp", "DpadDown", "LStickLeft", "LStickRight", "LStickUp", "LStickDown",
|
||||
"FocusPrev", "FocusNext", "TweakSlow", "TweakFast", "KeyLeft", "KeyRight", "KeyUp", "KeyDown"
|
||||
};
|
||||
IM_ASSERT(IM_ARRAYSIZE(names) == ImGuiNavInput_COUNT);
|
||||
IM_ASSERT(n >= 0 && n < ImGuiNavInput_COUNT);
|
||||
return names[n];
|
||||
}
|
||||
|
||||
float ImGui::GetNavInputAmount(ImGuiNavInput n, ImGuiNavReadMode mode)
|
||||
float ImGui::GetNavTweakPressedAmount(ImGuiAxis axis)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiIO& io = g.IO;
|
||||
if (mode == ImGuiNavReadMode_Down) // Instant, read analog input (0.0f..1.0f, as provided by user)
|
||||
return io.NavInputs[n];
|
||||
const float t = io.NavInputsDownDuration[n];
|
||||
if (t < 0.0f)
|
||||
return 0.0f;
|
||||
switch (mode)
|
||||
{
|
||||
case ImGuiNavReadMode_Repeat:
|
||||
return (float)CalcTypematicRepeatAmount(t - io.DeltaTime, t, io.KeyRepeatDelay * 0.72f, io.KeyRepeatRate * 0.80f);
|
||||
case ImGuiNavReadMode_RepeatSlow:
|
||||
return (float)CalcTypematicRepeatAmount(t - io.DeltaTime, t, io.KeyRepeatDelay * 1.25f, io.KeyRepeatRate * 2.00f);
|
||||
case ImGuiNavReadMode_RepeatFast:
|
||||
return (float)CalcTypematicRepeatAmount(t - io.DeltaTime, t, io.KeyRepeatDelay * 0.72f, io.KeyRepeatRate * 0.30f);
|
||||
default:
|
||||
IM_ASSERT(0);
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
float repeat_delay, repeat_rate;
|
||||
GetTypematicRepeatRate(ImGuiInputReadFlags_RepeatRateNavTweak, &repeat_delay, &repeat_rate);
|
||||
|
||||
ImVec2 ImGui::GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiNavReadMode mode, float slow_factor, float fast_factor)
|
||||
ImGuiKey key_less, key_more;
|
||||
if (g.NavInputSource == ImGuiInputSource_Gamepad)
|
||||
{
|
||||
ImVec2 delta(0.0f, 0.0f);
|
||||
if (dir_sources & ImGuiNavDirSourceFlags_Keyboard) // Number of presses during the frame, according to repeat rate
|
||||
delta += ImVec2(GetNavInputAmount(ImGuiNavInput_KeyRight_, mode) - GetNavInputAmount(ImGuiNavInput_KeyLeft_, mode), GetNavInputAmount(ImGuiNavInput_KeyDown_, mode) - GetNavInputAmount(ImGuiNavInput_KeyUp_, mode));
|
||||
if (dir_sources & ImGuiNavDirSourceFlags_PadDPad)
|
||||
delta += ImVec2(GetNavInputAmount(ImGuiNavInput_DpadRight, mode) - GetNavInputAmount(ImGuiNavInput_DpadLeft, mode), GetNavInputAmount(ImGuiNavInput_DpadDown, mode) - GetNavInputAmount(ImGuiNavInput_DpadUp, mode));
|
||||
if (dir_sources & ImGuiNavDirSourceFlags_PadLStick)
|
||||
delta += ImVec2(GetNavInputAmount(ImGuiNavInput_LStickRight, mode) - GetNavInputAmount(ImGuiNavInput_LStickLeft, mode), GetNavInputAmount(ImGuiNavInput_LStickDown, mode) - GetNavInputAmount(ImGuiNavInput_LStickUp, mode));
|
||||
if (slow_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakSlow))
|
||||
delta *= slow_factor;
|
||||
if (fast_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakFast))
|
||||
delta *= fast_factor;
|
||||
return delta;
|
||||
key_less = (axis == ImGuiAxis_X) ? ImGuiKey_GamepadDpadLeft : ImGuiKey_GamepadDpadUp;
|
||||
key_more = (axis == ImGuiAxis_X) ? ImGuiKey_GamepadDpadRight : ImGuiKey_GamepadDpadDown;
|
||||
}
|
||||
else
|
||||
{
|
||||
key_less = (axis == ImGuiAxis_X) ? ImGuiKey_LeftArrow : ImGuiKey_UpArrow;
|
||||
key_more = (axis == ImGuiAxis_X) ? ImGuiKey_RightArrow : ImGuiKey_DownArrow;
|
||||
}
|
||||
float amount = (float)GetKeyPressedAmount(key_more, repeat_delay, repeat_rate) - (float)GetKeyPressedAmount(key_less, repeat_delay, repeat_rate);
|
||||
if (amount != 0.0f && IsKeyDown(key_less) && IsKeyDown(key_more)) // Cancel when opposite directions are held, regardless of repeat phase
|
||||
amount = 0.0f;
|
||||
return amount;
|
||||
}
|
||||
|
||||
static void ImGui::NavUpdate()
|
||||
@ -10178,54 +10209,20 @@ static void ImGui::NavUpdate()
|
||||
io.WantSetMousePos = false;
|
||||
//if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG_NAV("[nav] NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
|
||||
|
||||
// Update Gamepad->Nav inputs mapping
|
||||
// Set input source as Gamepad when buttons are pressed (as some features differs when used with Gamepad vs Keyboard)
|
||||
// Set input source based on which keys are last pressed (as some features differs when used with Gamepad vs Keyboard)
|
||||
// FIXME-NAV: Now that keys are separated maybe we can get rid of NavInputSource?
|
||||
const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
|
||||
if (nav_gamepad_active && g.IO.BackendUsingLegacyNavInputArray == false)
|
||||
{
|
||||
for (int n = 0; n < ImGuiNavInput_COUNT; n++)
|
||||
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)
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadFaceDown, ImGuiNavInput_Activate, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadFaceRight, ImGuiNavInput_Cancel, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadFaceLeft, ImGuiNavInput_Menu, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadFaceUp, ImGuiNavInput_Input, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadDpadLeft, ImGuiNavInput_DpadLeft, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadDpadRight, ImGuiNavInput_DpadRight, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadDpadUp, ImGuiNavInput_DpadUp, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadDpadDown, ImGuiNavInput_DpadDown, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadL1, ImGuiNavInput_FocusPrev, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadR1, ImGuiNavInput_FocusNext, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadL1, ImGuiNavInput_TweakSlow, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadR1, ImGuiNavInput_TweakFast, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadLStickLeft, ImGuiNavInput_LStickLeft, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadLStickRight, ImGuiNavInput_LStickRight, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadLStickUp, ImGuiNavInput_LStickUp, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadLStickDown, ImGuiNavInput_LStickDown, false);
|
||||
#undef NAV_MAP_KEY
|
||||
}
|
||||
|
||||
// Update Keyboard->Nav inputs mapping
|
||||
const ImGuiKey nav_gamepad_keys_to_change_source[] = { ImGuiKey_GamepadFaceRight, ImGuiKey_GamepadFaceLeft, ImGuiKey_GamepadFaceUp, ImGuiKey_GamepadFaceDown, ImGuiKey_GamepadDpadRight, ImGuiKey_GamepadDpadLeft, ImGuiKey_GamepadDpadUp, ImGuiKey_GamepadDpadDown };
|
||||
if (nav_gamepad_active)
|
||||
for (ImGuiKey key : nav_gamepad_keys_to_change_source)
|
||||
if (IsKeyDown(key))
|
||||
g.NavInputSource = ImGuiInputSource_Gamepad;
|
||||
const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
|
||||
const ImGuiKey nav_keyboard_keys_to_change_source[] = { ImGuiKey_Space, ImGuiKey_Enter, ImGuiKey_Escape, ImGuiKey_RightArrow, ImGuiKey_LeftArrow, ImGuiKey_UpArrow, ImGuiKey_DownArrow };
|
||||
if (nav_keyboard_active)
|
||||
{
|
||||
#define NAV_MAP_KEY(_KEY, _NAV_INPUT) do { if (IsKeyDown(_KEY)) { io.NavInputs[_NAV_INPUT] = 1.0f; g.NavInputSource = ImGuiInputSource_Keyboard; } } while (0)
|
||||
NAV_MAP_KEY(ImGuiKey_Space, ImGuiNavInput_Activate );
|
||||
NAV_MAP_KEY(ImGuiKey_Enter, ImGuiNavInput_Input );
|
||||
NAV_MAP_KEY(ImGuiKey_Escape, ImGuiNavInput_Cancel );
|
||||
NAV_MAP_KEY(ImGuiKey_LeftArrow, ImGuiNavInput_KeyLeft_ );
|
||||
NAV_MAP_KEY(ImGuiKey_RightArrow,ImGuiNavInput_KeyRight_);
|
||||
NAV_MAP_KEY(ImGuiKey_UpArrow, ImGuiNavInput_KeyUp_ );
|
||||
NAV_MAP_KEY(ImGuiKey_DownArrow, ImGuiNavInput_KeyDown_ );
|
||||
if (io.KeyCtrl)
|
||||
io.NavInputs[ImGuiNavInput_TweakSlow] = 1.0f;
|
||||
if (io.KeyShift)
|
||||
io.NavInputs[ImGuiNavInput_TweakFast] = 1.0f;
|
||||
#undef NAV_MAP_KEY
|
||||
}
|
||||
memcpy(io.NavInputsDownDurationPrev, io.NavInputsDownDuration, sizeof(io.NavInputsDownDuration));
|
||||
for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++)
|
||||
io.NavInputsDownDuration[i] = (io.NavInputs[i] > 0.0f) ? (io.NavInputsDownDuration[i] < 0.0f ? 0.0f : io.NavInputsDownDuration[i] + io.DeltaTime) : -1.0f;
|
||||
for (ImGuiKey key : nav_keyboard_keys_to_change_source)
|
||||
if (IsKeyDown(key))
|
||||
g.NavInputSource = ImGuiInputSource_Keyboard;
|
||||
|
||||
// Process navigation init request (select first/default focus)
|
||||
if (g.NavInitResultId != 0)
|
||||
@ -10270,10 +10267,10 @@ static void ImGui::NavUpdate()
|
||||
g.NavActivateFlags = ImGuiActivateFlags_None;
|
||||
if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
|
||||
{
|
||||
bool activate_down = IsNavInputDown(ImGuiNavInput_Activate);
|
||||
bool input_down = IsNavInputDown(ImGuiNavInput_Input);
|
||||
bool activate_pressed = activate_down && IsNavInputPressed(ImGuiNavInput_Activate);
|
||||
bool input_pressed = input_down && IsNavInputPressed(ImGuiNavInput_Input);
|
||||
const bool activate_down = IsKeyDown(ImGuiKey_Space) || IsKeyDown(ImGuiKey_NavGamepadActivate);
|
||||
const bool activate_pressed = activate_down && (IsKeyPressed(ImGuiKey_Space, false) || IsKeyPressed(ImGuiKey_NavGamepadActivate, false));
|
||||
const bool input_down = IsKeyDown(ImGuiKey_Enter) || IsKeyDown(ImGuiKey_NavGamepadInput);
|
||||
const bool input_pressed = input_down && (IsKeyPressed(ImGuiKey_Enter, false) || IsKeyPressed(ImGuiKey_NavGamepadInput, false));
|
||||
if (g.ActiveId == 0 && activate_pressed)
|
||||
{
|
||||
g.NavActivateId = g.NavId;
|
||||
@ -10330,11 +10327,12 @@ static void ImGui::NavUpdate()
|
||||
|
||||
// *Normal* Manual scroll with NavScrollXXX keys
|
||||
// Next movement request will clamp the NavId reference rectangle to the visible area, so navigation will resume within those bounds.
|
||||
ImVec2 scroll_dir = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiNavReadMode_Down, 1.0f / 10.0f, 10.0f);
|
||||
const ImVec2 scroll_dir = GetKeyVector2d(ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp, ImGuiKey_GamepadLStickDown);
|
||||
const float tweak_factor = IsKeyDown(ImGuiKey_NavGamepadTweakSlow) ? 1.0f / 10.0f : IsKeyDown(ImGuiKey_NavGamepadTweakFast) ? 10.0f : 1.0f;
|
||||
if (scroll_dir.x != 0.0f && window->ScrollbarX)
|
||||
SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed));
|
||||
SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed * tweak_factor));
|
||||
if (scroll_dir.y != 0.0f)
|
||||
SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed));
|
||||
SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed * tweak_factor));
|
||||
}
|
||||
|
||||
// Always prioritize mouse highlight if navigation is disabled
|
||||
@ -10403,11 +10401,11 @@ void ImGui::NavUpdateCreateMoveRequest()
|
||||
g.NavMoveScrollFlags = ImGuiScrollFlags_None;
|
||||
if (window && !g.NavWindowingTarget && !(window->Flags & ImGuiWindowFlags_NoNavInputs))
|
||||
{
|
||||
const ImGuiNavReadMode read_mode = ImGuiNavReadMode_Repeat;
|
||||
if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && (IsNavInputTest(ImGuiNavInput_DpadLeft, read_mode) || IsNavInputTest(ImGuiNavInput_KeyLeft_, read_mode))) { g.NavMoveDir = ImGuiDir_Left; }
|
||||
if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && (IsNavInputTest(ImGuiNavInput_DpadRight, read_mode) || IsNavInputTest(ImGuiNavInput_KeyRight_, read_mode))) { g.NavMoveDir = ImGuiDir_Right; }
|
||||
if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && (IsNavInputTest(ImGuiNavInput_DpadUp, read_mode) || IsNavInputTest(ImGuiNavInput_KeyUp_, read_mode))) { g.NavMoveDir = ImGuiDir_Up; }
|
||||
if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && (IsNavInputTest(ImGuiNavInput_DpadDown, read_mode) || IsNavInputTest(ImGuiNavInput_KeyDown_, read_mode))) { g.NavMoveDir = ImGuiDir_Down; }
|
||||
const ImGuiInputReadFlags repeat_mode = ImGuiInputReadFlags_Repeat | ImGuiInputReadFlags_RepeatRateNavMove;
|
||||
if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && (IsKeyPressedEx(ImGuiKey_GamepadDpadLeft, repeat_mode) || IsKeyPressedEx(ImGuiKey_LeftArrow, repeat_mode))) { g.NavMoveDir = ImGuiDir_Left; }
|
||||
if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && (IsKeyPressedEx(ImGuiKey_GamepadDpadRight, repeat_mode) || IsKeyPressedEx(ImGuiKey_RightArrow, repeat_mode))) { g.NavMoveDir = ImGuiDir_Right; }
|
||||
if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && (IsKeyPressedEx(ImGuiKey_GamepadDpadUp, repeat_mode) || IsKeyPressedEx(ImGuiKey_UpArrow, repeat_mode))) { g.NavMoveDir = ImGuiDir_Up; }
|
||||
if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && (IsKeyPressedEx(ImGuiKey_GamepadDpadDown, repeat_mode) || IsKeyPressedEx(ImGuiKey_DownArrow, repeat_mode))) { g.NavMoveDir = ImGuiDir_Down; }
|
||||
}
|
||||
g.NavMoveClipDir = g.NavMoveDir;
|
||||
g.NavScoringNoClipRect = ImRect(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX);
|
||||
@ -10613,13 +10611,22 @@ void ImGui::NavMoveRequestApplyResult()
|
||||
static void ImGui::NavUpdateCancelRequest()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (!IsNavInputPressed(ImGuiNavInput_Cancel))
|
||||
if (!IsKeyPressed(ImGuiKey_Escape, false) && !IsKeyPressed(ImGuiKey_NavGamepadCancel, false))
|
||||
return;
|
||||
|
||||
IMGUI_DEBUG_LOG_NAV("[nav] ImGuiNavInput_Cancel\n");
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
// If your custom widget code used: { g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel); }
|
||||
// Since IMGUI_VERSION_NUM >= 18804 it should be: { SetActiveIdUsingKey(ImGuiKey_Escape); SetActiveIdUsingKey(ImGuiKey_NavGamepadCancel); }
|
||||
if (g.ActiveIdUsingNavInputMask & (1 << ImGuiNavInput_Cancel))
|
||||
SetActiveIdUsingKey(ImGuiKey_Escape);
|
||||
if (g.ActiveIdUsingNavInputMask & ~(1 << ImGuiNavInput_Cancel))
|
||||
IM_ASSERT(0); // Other values unsupported
|
||||
#endif
|
||||
|
||||
IMGUI_DEBUG_LOG_NAV("[nav] NavUpdateCancelRequest()\n");
|
||||
if (g.ActiveId != 0)
|
||||
{
|
||||
if (!IsActiveIdUsingNavInput(ImGuiNavInput_Cancel))
|
||||
if (!IsActiveIdUsingKey(ImGuiKey_Escape) && !IsActiveIdUsingKey(ImGuiKey_NavGamepadCancel))
|
||||
ClearActiveID();
|
||||
}
|
||||
else if (g.NavLayer != ImGuiNavLayer_Main)
|
||||
@ -10865,8 +10872,8 @@ static void ImGui::NavUpdateWindowing()
|
||||
}
|
||||
|
||||
// Start CTRL+Tab or Square+L/R window selection
|
||||
const bool start_windowing_with_gamepad = allow_windowing && !g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_Menu);
|
||||
const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && io.KeyCtrl && IsKeyPressed(ImGuiKey_Tab);
|
||||
const bool start_windowing_with_gamepad = allow_windowing && !g.NavWindowingTarget && IsKeyPressed(ImGuiKey_NavGamepadMenu, false);
|
||||
const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && io.KeyCtrl && IsKeyPressed(ImGuiKey_Tab, false);
|
||||
if (start_windowing_with_gamepad || start_windowing_with_keyboard)
|
||||
if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1))
|
||||
{
|
||||
@ -10885,7 +10892,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f));
|
||||
|
||||
// Select window to focus
|
||||
const int focus_change_dir = (int)IsNavInputTest(ImGuiNavInput_FocusPrev, ImGuiNavReadMode_RepeatSlow) - (int)IsNavInputTest(ImGuiNavInput_FocusNext, ImGuiNavReadMode_RepeatSlow);
|
||||
const int focus_change_dir = (int)IsKeyPressed(ImGuiKey_GamepadL1) - (int)IsKeyPressed(ImGuiKey_GamepadR1);
|
||||
if (focus_change_dir != 0)
|
||||
{
|
||||
NavUpdateWindowingHighlightWindow(focus_change_dir);
|
||||
@ -10893,7 +10900,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
}
|
||||
|
||||
// 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.
|
||||
if (g.NavWindowingToggleLayer && g.NavWindow)
|
||||
@ -10946,9 +10953,9 @@ static void ImGui::NavUpdateWindowing()
|
||||
{
|
||||
ImVec2 nav_move_dir;
|
||||
if (g.NavInputSource == ImGuiInputSource_Keyboard && !io.KeyShift)
|
||||
nav_move_dir = ImVec2((float)IsKeyDown(ImGuiKey_RightArrow) - (float)IsKeyDown(ImGuiKey_LeftArrow), (float)IsKeyDown(ImGuiKey_DownArrow) - (float)IsKeyDown(ImGuiKey_UpArrow));
|
||||
nav_move_dir = GetKeyVector2d(ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_UpArrow, ImGuiKey_DownArrow);
|
||||
if (g.NavInputSource == ImGuiInputSource_Gamepad)
|
||||
nav_move_dir = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiNavReadMode_Down);
|
||||
nav_move_dir = GetKeyVector2d(ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp, ImGuiKey_GamepadLStickDown);
|
||||
if (nav_move_dir.x != 0.0f || nav_move_dir.y != 0.0f)
|
||||
{
|
||||
const float NAV_MOVE_SPEED = 800.0f;
|
||||
@ -12667,7 +12674,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
int active_id_using_key_input_count = 0;
|
||||
for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++)
|
||||
active_id_using_key_input_count += g.ActiveIdUsingKeyInputMask[n] ? 1 : 0;
|
||||
Text("ActiveIdUsing: Wheel: %d, NavDirMask: %X, NavInputMask: %X, KeyInputMask: %d key(s)", g.ActiveIdUsingMouseWheel, g.ActiveIdUsingNavDirMask, g.ActiveIdUsingNavInputMask, active_id_using_key_input_count);
|
||||
Text("ActiveIdUsing: Wheel: %d, NavDirMask: %X, KeyInputMask: %d key(s)", g.ActiveIdUsingMouseWheel, g.ActiveIdUsingNavDirMask, active_id_using_key_input_count);
|
||||
Text("HoveredId: 0x%08X (%.2f sec), AllowOverlap: %d", g.HoveredIdPreviousFrame, g.HoveredIdTimer, g.HoveredIdAllowOverlap); // Not displaying g.HoveredId as it is update mid-frame
|
||||
Text("DragDrop: %d, SourceId = 0x%08X, Payload \"%s\" (%d bytes)", g.DragDropActive, g.DragDropPayload.SourceId, g.DragDropPayload.DataType, g.DragDropPayload.DataSize);
|
||||
Unindent();
|
||||
|
94
imgui.h
94
imgui.h
@ -65,7 +65,7 @@ Index of this file:
|
||||
// Version
|
||||
// (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)
|
||||
#define IMGUI_VERSION "1.89 WIP"
|
||||
#define IMGUI_VERSION_NUM 18803
|
||||
#define IMGUI_VERSION_NUM 18804
|
||||
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
|
||||
#define IMGUI_HAS_TABLE
|
||||
|
||||
@ -171,7 +171,6 @@ typedef int ImGuiCond; // -> enum ImGuiCond_ // Enum: A
|
||||
typedef int ImGuiDataType; // -> enum ImGuiDataType_ // Enum: A primary data type
|
||||
typedef int ImGuiDir; // -> enum ImGuiDir_ // Enum: A cardinal direction
|
||||
typedef int ImGuiKey; // -> enum ImGuiKey_ // Enum: A key identifier
|
||||
typedef int ImGuiNavInput; // -> enum ImGuiNavInput_ // Enum: An input identifier for navigation
|
||||
typedef int ImGuiMouseButton; // -> enum ImGuiMouseButton_ // Enum: A mouse button identifier (0=left, 1=right, 2=middle)
|
||||
typedef int ImGuiMouseCursor; // -> enum ImGuiMouseCursor_ // Enum: A mouse cursor identifier
|
||||
typedef int ImGuiSortDirection; // -> enum ImGuiSortDirection_ // Enum: A sorting direction (ascending or descending)
|
||||
@ -1396,27 +1395,28 @@ enum ImGuiKey_
|
||||
ImGuiKey_KeypadEnter,
|
||||
ImGuiKey_KeypadEqual,
|
||||
|
||||
// Gamepad (some of those are analog values, 0.0f to 1.0f) // NAVIGATION action
|
||||
ImGuiKey_GamepadStart, // Menu (Xbox) + (Switch) Start/Options (PS) // --
|
||||
ImGuiKey_GamepadBack, // View (Xbox) - (Switch) Share (PS) // --
|
||||
ImGuiKey_GamepadFaceLeft, // X (Xbox) Y (Switch) Square (PS) // -> ImGuiNavInput_Menu
|
||||
ImGuiKey_GamepadFaceRight, // B (Xbox) A (Switch) Circle (PS) // -> ImGuiNavInput_Cancel
|
||||
ImGuiKey_GamepadFaceUp, // Y (Xbox) X (Switch) Triangle (PS) // -> ImGuiNavInput_Input
|
||||
ImGuiKey_GamepadFaceDown, // A (Xbox) B (Switch) Cross (PS) // -> ImGuiNavInput_Activate
|
||||
ImGuiKey_GamepadDpadLeft, // D-pad Left // -> ImGuiNavInput_DpadLeft
|
||||
ImGuiKey_GamepadDpadRight, // D-pad Right // -> ImGuiNavInput_DpadRight
|
||||
ImGuiKey_GamepadDpadUp, // D-pad Up // -> ImGuiNavInput_DpadUp
|
||||
ImGuiKey_GamepadDpadDown, // D-pad Down // -> ImGuiNavInput_DpadDown
|
||||
ImGuiKey_GamepadL1, // L Bumper (Xbox) L (Switch) L1 (PS) // -> ImGuiNavInput_FocusPrev + ImGuiNavInput_TweakSlow
|
||||
ImGuiKey_GamepadR1, // R Bumper (Xbox) R (Switch) R1 (PS) // -> ImGuiNavInput_FocusNext + ImGuiNavInput_TweakFast
|
||||
ImGuiKey_GamepadL2, // L Trigger (Xbox) ZL (Switch) L2 (PS) [Analog]
|
||||
ImGuiKey_GamepadR2, // R Trigger (Xbox) ZR (Switch) R2 (PS) [Analog]
|
||||
ImGuiKey_GamepadL3, // L Thumbstick (Xbox) L3 (Switch) L3 (PS)
|
||||
ImGuiKey_GamepadR3, // R Thumbstick (Xbox) R3 (Switch) R3 (PS)
|
||||
ImGuiKey_GamepadLStickLeft, // [Analog] // -> ImGuiNavInput_LStickLeft
|
||||
ImGuiKey_GamepadLStickRight, // [Analog] // -> ImGuiNavInput_LStickRight
|
||||
ImGuiKey_GamepadLStickUp, // [Analog] // -> ImGuiNavInput_LStickUp
|
||||
ImGuiKey_GamepadLStickDown, // [Analog] // -> ImGuiNavInput_LStickDown
|
||||
// Gamepad (some of those are analog values, 0.0f to 1.0f) // GAME NAVIGATION ACTION
|
||||
// (download controller mapping PNG/PSD at http://dearimgui.org/controls_sheets)
|
||||
ImGuiKey_GamepadStart, // Menu (Xbox) + (Switch) Start/Options (PS)
|
||||
ImGuiKey_GamepadBack, // View (Xbox) - (Switch) Share (PS)
|
||||
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.
|
||||
enum ImGuiNavInput_
|
||||
#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.
|
||||
enum ImGuiNavInput
|
||||
{
|
||||
// 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_DpadLeft, // Move / Tweak / Resize window (w/ PadMenu) // e.g. D-pad Left/Right/Up/Down (Gamepads), Arrow keys (Keyboard)
|
||||
ImGuiNavInput_DpadRight, //
|
||||
ImGuiNavInput_DpadUp, //
|
||||
ImGuiNavInput_DpadDown, //
|
||||
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
|
||||
ImGuiNavInput_Activate, ImGuiNavInput_Cancel, ImGuiNavInput_Input, ImGuiNavInput_Menu, ImGuiNavInput_DpadLeft, ImGuiNavInput_DpadRight, ImGuiNavInput_DpadUp, ImGuiNavInput_DpadDown,
|
||||
ImGuiNavInput_LStickLeft, ImGuiNavInput_LStickRight, ImGuiNavInput_LStickUp, ImGuiNavInput_LStickDown, ImGuiNavInput_FocusPrev, ImGuiNavInput_FocusNext, ImGuiNavInput_TweakSlow, ImGuiNavInput_TweakFast,
|
||||
ImGuiNavInput_COUNT,
|
||||
};
|
||||
#endif
|
||||
|
||||
// Configuration flags stored in io.ConfigFlags. Set by user/application.
|
||||
enum ImGuiConfigFlags_
|
||||
{
|
||||
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_NavEnableKeyboard = 1 << 0, // Master keyboard navigation enable flag.
|
||||
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
|
||||
int KeyMap[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.
|
||||
bool KeysDown[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.
|
||||
float NavInputs[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.
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------
|
||||
@ -2028,7 +2007,6 @@ struct ImGuiIO
|
||||
bool KeyShift; // Keyboard modifier down: Shift
|
||||
bool KeyAlt; // Keyboard modifier down: Alt
|
||||
bool KeySuper; // Keyboard modifier down: Cmd/Super/Windows
|
||||
float NavInputs[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
|
||||
ImGuiModFlags KeyMods; // Key mods flags (same as io.KeyCtrl/KeyShift/KeyAlt/KeySuper but merged into flags), updated by NewFrame()
|
||||
@ -2047,8 +2025,6 @@ struct ImGuiIO
|
||||
float MouseDownDuration[5]; // Duration the mouse button has been down (0.0f == just clicked)
|
||||
float MouseDownDurationPrev[5]; // Previous time the mouse button has been down
|
||||
float MouseDragMaxDistanceSqr[5]; // Squared maximum distance of how much mouse has traveled from the clicking point (used for moving thresholds)
|
||||
float NavInputsDownDuration[ImGuiNavInput_COUNT];
|
||||
float NavInputsDownDurationPrev[ImGuiNavInput_COUNT];
|
||||
float PenPressure; // Touch/Pen pressure (0.0f to 1.0f, should be >0.0f only when MouseDown[0] == true). Helper storage currently unused by Dear ImGui.
|
||||
bool AppFocusLost; // Only modify via AddFocusEvent()
|
||||
bool AppAcceptingEvents; // Only modify via SetAppAcceptingEvents()
|
||||
|
@ -5733,8 +5733,6 @@ static void ShowDemoWindowMisc()
|
||||
ImGui::Text("Keys released:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyReleased(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } }
|
||||
ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : "");
|
||||
ImGui::Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = 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.
|
||||
ImGui::Text("NavInputs down:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputs[i] > 0.0f) { ImGui::SameLine(); ImGui::Text("[%d] %.2f (%.02f secs)", i, io.NavInputs[i], io.NavInputsDownDuration[i]); }
|
||||
ImGui::Text("NavInputs pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputsDownDuration[i] == 0.0f) { ImGui::SameLine(); ImGui::Text("[%d]", i); }
|
||||
|
||||
// Draw an arbitrary US keyboard layout to visualize translated keys
|
||||
{
|
||||
|
@ -148,11 +148,11 @@ struct ImGuiWindowSettings; // Storage for a window .ini settings (we ke
|
||||
typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical
|
||||
typedef int ImGuiActivateFlags; // -> enum ImGuiActivateFlags_ // Flags: for navigation/focus function (will be for ActivateItem() later)
|
||||
typedef int ImGuiDebugLogFlags; // -> enum ImGuiDebugLogFlags_ // Flags: for ShowDebugLogWindow(), g.DebugLogFlags
|
||||
typedef int ImGuiInputReadFlags; // -> enum ImGuiInputReadFlags_ // Flags: for IsKeyPressedEx()
|
||||
typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag()
|
||||
typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for DC.LastItemStatusFlags
|
||||
typedef int ImGuiOldColumnFlags; // -> enum ImGuiOldColumnFlags_ // Flags: for BeginColumns()
|
||||
typedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight()
|
||||
typedef int ImGuiNavDirSourceFlags; // -> enum ImGuiNavDirSourceFlags_ // Flags: for GetNavInputAmount2d()
|
||||
typedef int ImGuiNavMoveFlags; // -> enum ImGuiNavMoveFlags_ // Flags: for navigation requests
|
||||
typedef int ImGuiNextItemDataFlags; // -> enum ImGuiNextItemDataFlags_ // Flags: for SetNextItemXXX() functions
|
||||
typedef int ImGuiNextWindowDataFlags; // -> enum ImGuiNextWindowDataFlags_// Flags: for SetNextWindowXXX() functions
|
||||
@ -1177,6 +1177,16 @@ enum ImGuiKeyPrivate_
|
||||
ImGuiKey_LegacyNativeKey_END = 512,
|
||||
ImGuiKey_Gamepad_BEGIN = ImGuiKey_GamepadStart,
|
||||
ImGuiKey_Gamepad_END = ImGuiKey_GamepadRStickDown + 1,
|
||||
|
||||
// [Internal] Named shortcuts for Navigation
|
||||
ImGuiKey_NavKeyboardTweakSlow = ImGuiKey_ModCtrl,
|
||||
ImGuiKey_NavKeyboardTweakFast = ImGuiKey_ModShift,
|
||||
ImGuiKey_NavGamepadTweakSlow = ImGuiKey_GamepadL1,
|
||||
ImGuiKey_NavGamepadTweakFast = ImGuiKey_GamepadR1,
|
||||
ImGuiKey_NavGamepadActivate = ImGuiKey_GamepadFaceDown,
|
||||
ImGuiKey_NavGamepadCancel = ImGuiKey_GamepadFaceRight,
|
||||
ImGuiKey_NavGamepadMenu = ImGuiKey_GamepadFaceLeft,
|
||||
ImGuiKey_NavGamepadInput = ImGuiKey_GamepadFaceUp,
|
||||
};
|
||||
|
||||
enum ImGuiInputEventType
|
||||
@ -1229,13 +1239,19 @@ struct ImGuiInputEvent
|
||||
ImGuiInputEvent() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
// FIXME-NAV: Clarify/expose various repeat delay/rate
|
||||
enum ImGuiNavReadMode
|
||||
// Flags for IsKeyPressedEx(). In upcoming feature this will be used more (and IsKeyPressedEx() renamed)
|
||||
// Don't mistake with ImGuiInputTextFlags! (for ImGui::InputText() function)
|
||||
enum ImGuiInputReadFlags_
|
||||
{
|
||||
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.
|
||||
|
||||
// Repeat rate
|
||||
ImGuiInputReadFlags_RepeatRateDefault = 1 << 1, // Regular
|
||||
ImGuiInputReadFlags_RepeatRateNavMove = 1 << 2, // Fast
|
||||
ImGuiInputReadFlags_RepeatRateNavTweak = 1 << 3, // Faster
|
||||
ImGuiInputReadFlags_RepeatRateMask_ = ImGuiInputReadFlags_RepeatRateDefault | ImGuiInputReadFlags_RepeatRateNavMove | ImGuiInputReadFlags_RepeatRateNavTweak,
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1303,14 +1319,6 @@ enum ImGuiNavHighlightFlags_
|
||||
ImGuiNavHighlightFlags_NoRounding = 1 << 3,
|
||||
};
|
||||
|
||||
enum ImGuiNavDirSourceFlags_
|
||||
{
|
||||
ImGuiNavDirSourceFlags_None = 0,
|
||||
ImGuiNavDirSourceFlags_Keyboard = 1 << 0,
|
||||
ImGuiNavDirSourceFlags_PadDPad = 1 << 1,
|
||||
ImGuiNavDirSourceFlags_PadLStick = 1 << 2,
|
||||
};
|
||||
|
||||
enum ImGuiNavMoveFlags_
|
||||
{
|
||||
ImGuiNavMoveFlags_None = 0,
|
||||
@ -1332,7 +1340,7 @@ enum ImGuiNavMoveFlags_
|
||||
enum ImGuiNavLayer
|
||||
{
|
||||
ImGuiNavLayer_Main = 0, // Main scrolling layer
|
||||
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
|
||||
bool ActiveIdUsingMouseWheel; // Active widget will want to read mouse wheel. Blocks scrolling the underlying window.
|
||||
ImU32 ActiveIdUsingNavDirMask; // Active widget will want to read those nav move requests (e.g. can activate a button and move away from it)
|
||||
ImU32 ActiveIdUsingNavInputMask; // Active widget will want to read those nav inputs.
|
||||
ImBitArrayForNamedKeys ActiveIdUsingKeyInputMask; // 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
|
||||
ImU32 ActiveIdUsingNavInputMask; // If you used this. Since (IMGUI_VERSION_NUM >= 18804) : 'g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel);' becomes 'SetActiveIdUsingKey(ImGuiKey_Escape); SetActiveIdUsingKey(ImGuiKey_NavGamepadCancel);'
|
||||
#endif
|
||||
|
||||
// Next window/item data
|
||||
ImGuiItemFlags CurrentItemFlags; // == g.ItemFlagsStack.back()
|
||||
@ -1672,10 +1682,10 @@ struct ImGuiContext
|
||||
ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusedWindow'
|
||||
ImGuiID NavId; // Focused item for navigation
|
||||
ImGuiID NavFocusScopeId; // Identify a selection scope (selection code often wants to "clear other items" when landing on an item of the selection set)
|
||||
ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0, also set when calling ActivateItem()
|
||||
ImGuiID NavActivateDownId; // ~~ IsNavInputDown(ImGuiNavInput_Activate) ? NavId : 0
|
||||
ImGuiID NavActivatePressedId; // ~~ IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0
|
||||
ImGuiID NavActivateInputId; // ~~ IsNavInputPressed(ImGuiNavInput_Input) ? NavId : 0; ImGuiActivateFlags_PreferInput will be set and NavActivateId will be 0.
|
||||
ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && (IsKeyPressed(ImGuiKey_Space) || IsKeyPressed(ImGuiKey_NavGamepadActivate)) ? NavId : 0, also set when calling ActivateItem()
|
||||
ImGuiID NavActivateDownId; // ~~ IsKeyDown(ImGuiKey_Space) || IsKeyDown(ImGuiKey_NavGamepadActivate) ? NavId : 0
|
||||
ImGuiID NavActivatePressedId; // ~~ IsKeyPressed(ImGuiKey_Space) || IsKeyPressed(ImGuiKey_NavGamepadActivate) ? NavId : 0 (no repeat)
|
||||
ImGuiID NavActivateInputId; // ~~ IsKeyPressed(ImGuiKey_Enter) || IsKeyPressed(ImGuiKey_NavGamepadInput) ? NavId : 0; ImGuiActivateFlags_PreferInput will be set and NavActivateId will be 0.
|
||||
ImGuiActivateFlags NavActivateFlags;
|
||||
ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest).
|
||||
ImGuiID NavJustMovedToFocusScopeId; // Just navigated to this focus scope id (result of a successfully MoveRequest).
|
||||
@ -1888,8 +1898,10 @@ struct ImGuiContext
|
||||
|
||||
ActiveIdUsingMouseWheel = false;
|
||||
ActiveIdUsingNavDirMask = 0x00;
|
||||
ActiveIdUsingNavInputMask = 0x00;
|
||||
ActiveIdUsingKeyInputMask.ClearAllBits();
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
ActiveIdUsingNavInputMask = 0x00;
|
||||
#endif
|
||||
|
||||
CurrentItemFlags = ImGuiItemFlags_None;
|
||||
BeginMenuCount = 0;
|
||||
@ -2671,10 +2683,6 @@ namespace ImGui
|
||||
IMGUI_API void NavMoveRequestCancel();
|
||||
IMGUI_API void NavMoveRequestApplyResult();
|
||||
IMGUI_API void NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags);
|
||||
IMGUI_API const char* GetNavInputName(ImGuiNavInput n);
|
||||
IMGUI_API float GetNavInputAmount(ImGuiNavInput n, ImGuiNavReadMode mode);
|
||||
IMGUI_API ImVec2 GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiNavReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f);
|
||||
IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate);
|
||||
IMGUI_API void ActivateItem(ImGuiID id); // 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.
|
||||
IMGUI_API void SetNavWindow(ImGuiWindow* window);
|
||||
IMGUI_API void SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel);
|
||||
@ -2696,20 +2704,19 @@ namespace ImGui
|
||||
IMGUI_API void SetItemUsingMouseWheel();
|
||||
IMGUI_API void SetActiveIdUsingNavAndKeys();
|
||||
inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; }
|
||||
inline bool IsActiveIdUsingNavInput(ImGuiNavInput input) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavInputMask & (1 << input)) != 0; }
|
||||
inline bool IsActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; return g.ActiveIdUsingKeyInputMask[key]; }
|
||||
inline void SetActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; g.ActiveIdUsingKeyInputMask.SetBit(key); }
|
||||
IMGUI_API bool IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold = -1.0f);
|
||||
IMGUI_API ImGuiModFlags GetMergedModFlags();
|
||||
IMGUI_API ImVec2 GetKeyVector2d(ImGuiKey key_left, ImGuiKey key_right, ImGuiKey key_up, ImGuiKey key_down);
|
||||
IMGUI_API float GetNavTweakPressedAmount(ImGuiAxis axis);
|
||||
IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate);
|
||||
IMGUI_API void GetTypematicRepeatRate(ImGuiInputReadFlags flags, float* repeat_delay, float* repeat_rate);
|
||||
IMGUI_API bool IsKeyPressedEx(ImGuiKey key, ImGuiInputReadFlags flags = 0);
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { IM_ASSERT(IsNamedKey(key)); return IsKeyPressed(key, repeat); } // [removed in 1.87]
|
||||
#endif
|
||||
|
||||
// Inputs: Navigation
|
||||
inline bool IsNavInputDown(ImGuiNavInput n) { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; }
|
||||
inline bool IsNavInputPressed(ImGuiNavInput n) { ImGuiContext& g = *GImGui; return g.IO.NavInputsDownDuration[n] == 0.0f; }
|
||||
inline bool IsNavInputTest(ImGuiNavInput n, ImGuiNavReadMode read_mode) { return (GetNavInputAmount(n, read_mode) > 0.0f); }
|
||||
|
||||
// Drag and Drop
|
||||
IMGUI_API bool IsDragDropActive();
|
||||
IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id);
|
||||
|
@ -611,7 +611,15 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
|
||||
if (g.NavActivateDownId == id)
|
||||
{
|
||||
bool nav_activated_by_code = (g.NavActivateId == id);
|
||||
bool nav_activated_by_inputs = (flags & ImGuiButtonFlags_Repeat) ? IsNavInputTest(ImGuiNavInput_Activate, ImGuiNavReadMode_Repeat) : IsNavInputPressed(ImGuiNavInput_Activate);
|
||||
bool nav_activated_by_inputs = (g.NavActivatePressedId == id);
|
||||
if (!nav_activated_by_inputs && (flags & ImGuiButtonFlags_Repeat))
|
||||
{
|
||||
// Avoid pressing both keys from triggering double amount of repeat events
|
||||
const ImGuiKeyData* key1 = GetKeyData(ImGuiKey_Space);
|
||||
const ImGuiKeyData* key2 = GetKeyData(ImGuiKey_NavGamepadActivate);
|
||||
const float t1 = ImMax(key1->DownDuration, key2->DownDuration);
|
||||
nav_activated_by_inputs = CalcTypematicRepeatAmount(t1 - g.IO.DeltaTime, t1, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0;
|
||||
}
|
||||
if (nav_activated_by_code || nav_activated_by_inputs)
|
||||
{
|
||||
// Set active id so it can be queried by user via IsItemActive(), equivalent of holding the mouse button.
|
||||
@ -2182,7 +2190,10 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
||||
else if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
||||
{
|
||||
const int decimal_precision = is_floating_point ? ImParseFormatPrecision(format, 3) : 0;
|
||||
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard | ImGuiNavDirSourceFlags_PadDPad, ImGuiNavReadMode_RepeatFast, 1.0f / 10.0f, 10.0f)[axis];
|
||||
const bool tweak_slow = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakSlow : ImGuiKey_NavKeyboardTweakSlow);
|
||||
const bool tweak_fast = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakFast : ImGuiKey_NavKeyboardTweakFast);
|
||||
const float tweak_factor = tweak_slow ? 1.0f / 1.0f : tweak_fast ? 10.0f : 1.0f;
|
||||
adjust_delta = GetNavTweakPressedAmount(axis) * tweak_factor;
|
||||
v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
|
||||
}
|
||||
adjust_delta *= v_speed;
|
||||
@ -2789,12 +2800,11 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ
|
||||
g.SliderCurrentAccumDirty = false;
|
||||
}
|
||||
|
||||
const ImVec2 input_delta2 = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard | ImGuiNavDirSourceFlags_PadDPad, ImGuiNavReadMode_RepeatFast);
|
||||
float input_delta = (axis == ImGuiAxis_X) ? input_delta2.x : -input_delta2.y;
|
||||
float input_delta = (axis == ImGuiAxis_X) ? GetNavTweakPressedAmount(axis) : -GetNavTweakPressedAmount(axis);
|
||||
if (input_delta != 0.0f)
|
||||
{
|
||||
const bool tweak_slow = IsNavInputDown(ImGuiNavInput_TweakSlow);
|
||||
const bool tweak_fast = IsNavInputDown(ImGuiNavInput_TweakFast);
|
||||
const bool tweak_slow = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakSlow : ImGuiKey_NavKeyboardTweakSlow);
|
||||
const bool tweak_fast = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakFast : ImGuiKey_NavKeyboardTweakFast);
|
||||
const int decimal_precision = is_floating_point ? ImParseFormatPrecision(format, 3) : 0;
|
||||
if (decimal_precision > 0)
|
||||
{
|
||||
@ -4143,11 +4153,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
FocusWindow(window);
|
||||
|
||||
// Declare our inputs
|
||||
IM_ASSERT(ImGuiNavInput_COUNT < 32);
|
||||
g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right);
|
||||
if (is_multiline || (flags & ImGuiInputTextFlags_CallbackHistory))
|
||||
g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down);
|
||||
g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel);
|
||||
SetActiveIdUsingKey(ImGuiKey_Escape);
|
||||
SetActiveIdUsingKey(ImGuiKey_NavGamepadCancel);
|
||||
SetActiveIdUsingKey(ImGuiKey_Home);
|
||||
SetActiveIdUsingKey(ImGuiKey_End);
|
||||
if (is_multiline)
|
||||
@ -4341,9 +4351,9 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
const bool is_select_all = is_shortcut_key && IsKeyPressed(ImGuiKey_A);
|
||||
|
||||
// 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.
|
||||
const bool is_enter_pressed = IsKeyPressed(ImGuiKey_Enter) || IsKeyPressed(ImGuiKey_KeypadEnter);
|
||||
const bool is_validate_nav = (IsNavInputPressed(ImGuiNavInput_Activate) && !IsKeyPressed(ImGuiKey_Space)) || IsNavInputPressed(ImGuiNavInput_Input);
|
||||
const bool is_cancel = IsKeyPressed(ImGuiKey_Escape) || IsNavInputPressed(ImGuiNavInput_Cancel);
|
||||
const bool is_enter_pressed = IsKeyPressed(ImGuiKey_Enter, true) || IsKeyPressed(ImGuiKey_KeypadEnter, true);
|
||||
const bool is_gamepad_validate = IsKeyPressed(ImGuiKey_NavGamepadActivate, false) || IsKeyPressed(ImGuiKey_NavGamepadInput, false);
|
||||
const bool is_cancel = IsKeyPressed(ImGuiKey_Escape, false) || IsKeyPressed(ImGuiKey_NavGamepadCancel, false);
|
||||
|
||||
if (IsKeyPressed(ImGuiKey_LeftArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINESTART : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDLEFT : STB_TEXTEDIT_K_LEFT) | k_mask); }
|
||||
else if (IsKeyPressed(ImGuiKey_RightArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINEEND : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDRIGHT : STB_TEXTEDIT_K_RIGHT) | k_mask); }
|
||||
@ -4365,11 +4375,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
}
|
||||
state->OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask);
|
||||
}
|
||||
else if (is_enter_pressed)
|
||||
else if (is_enter_pressed || is_gamepad_validate)
|
||||
{
|
||||
// Determine if we turn Enter into a \n character
|
||||
bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0;
|
||||
if (!is_multiline || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl))
|
||||
if (!is_multiline || is_gamepad_validate || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl))
|
||||
{
|
||||
validated = true;
|
||||
if (io.ConfigInputTextEnterKeepActive && !is_multiline)
|
||||
@ -4384,11 +4394,6 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
state->OnKeyPressed((int)c);
|
||||
}
|
||||
}
|
||||
else if (is_validate_nav)
|
||||
{
|
||||
IM_ASSERT(!is_enter_pressed);
|
||||
validated = clear_active_id = true;
|
||||
}
|
||||
else if (is_cancel)
|
||||
{
|
||||
clear_active_id = cancel_edit = true;
|
||||
|
Loading…
Reference in New Issue
Block a user