Skip to content

Commit dcff032

Browse files
committed
Nav: Moving all nav inputs to io.NavInputs[] float array, new enum labelled for gamepad. (#323)
1 parent 4ccc87c commit dcff032

File tree

4 files changed

+136
-108
lines changed

4 files changed

+136
-108
lines changed

imgui.cpp

+103-85
Original file line numberDiff line numberDiff line change
@@ -873,10 +873,9 @@ ImGuiIO::ImGuiIO()
873873
MousePos = ImVec2(-1,-1);
874874
MousePosPrev = ImVec2(-1,-1);
875875
MouseDragThreshold = 6.0f;
876-
for (int i = 0; i < IM_ARRAYSIZE(MouseDownDuration); i++)
877-
MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f;
878-
for (int i = 0; i < IM_ARRAYSIZE(KeysDownDuration); i++)
879-
KeysDownDuration[i] = KeysDownDurationPrev[i] = -1.0f;
876+
for (int i = 0; i < IM_ARRAYSIZE(MouseDownDuration); i++) MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f;
877+
for (int i = 0; i < IM_ARRAYSIZE(KeysDownDuration); i++) KeysDownDuration[i] = KeysDownDurationPrev[i] = -1.0f;
878+
for (int i = 0; i < IM_ARRAYSIZE(NavInputsDownDuration); i++) NavInputsDownDuration[i] = -1.0f;
880879

881880
// Set OS X style defaults based on __APPLE__ compile time flag
882881
#ifdef __APPLE__
@@ -2378,6 +2377,60 @@ static ImGuiWindow* FindWindowNavigable(int i_start, int i_stop, int dir) // FIX
23782377
return NULL;
23792378
}
23802379

2380+
enum ImGuiNavReadMode
2381+
{
2382+
ImGuiNavReadMode_Down,
2383+
ImGuiNavReadMode_Pressed,
2384+
ImGuiNavReadMode_Repeat,
2385+
ImGuiNavReadMode_RepeatSlow,
2386+
ImGuiNavReadMode_RepeatFast
2387+
};
2388+
2389+
// FIXME-NAVIGATION: Expose navigation repeat delay/rate
2390+
static float GetNavInputAmount(ImGuiNavInput n, ImGuiNavReadMode mode)
2391+
{
2392+
ImGuiContext& g = *GImGui;
2393+
if (mode == ImGuiNavReadMode_Down)
2394+
return g.IO.NavInputs[n]; // Instant, read analog input (0.0f..1.0f, as provided by user)
2395+
const float t = g.IO.NavInputsDownDuration[n]; // Duration pressed
2396+
if (mode == ImGuiNavReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input (we don't need it for Pressed logic)
2397+
return (t == 0.0f) ? 1.0f : 0.0f;
2398+
if (mode == ImGuiNavReadMode_Repeat)
2399+
return (float)ImGui::CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.80f);
2400+
if (mode == ImGuiNavReadMode_RepeatSlow)
2401+
return (float)ImGui::CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 1.00f, g.IO.KeyRepeatRate * 2.00f);
2402+
if (mode == ImGuiNavReadMode_RepeatFast)
2403+
return (float)ImGui::CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.30f);
2404+
return 0.0f;
2405+
}
2406+
2407+
// Equivalent of IsKeyDown() for NavInputs[]
2408+
static bool IsNavInputDown(ImGuiNavInput n)
2409+
{
2410+
return GImGui->IO.NavInputs[n] > 0.0f;
2411+
}
2412+
2413+
// Equivalent of IsKeyPressed() for NavInputs[]
2414+
static bool IsNavInputPressed(ImGuiNavInput n, ImGuiNavReadMode mode)// = ImGuiNavReadMode_Re)
2415+
{
2416+
return GetNavInputAmount(n, mode) > 0.0f;
2417+
}
2418+
2419+
static ImVec2 GetNavInputAmount2d(int stick_no, ImGuiNavReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f)
2420+
{
2421+
IM_ASSERT(ImGuiNavInput_PadScrollUp == ImGuiNavInput_PadUp + 4);
2422+
IM_ASSERT(stick_no >= 0 && stick_no < 2);
2423+
2424+
ImVec2 delta;
2425+
delta.x = GetNavInputAmount(ImGuiNavInput_PadRight + stick_no*4, mode) - GetNavInputAmount(ImGuiNavInput_PadLeft + stick_no*4, mode);
2426+
delta.y = GetNavInputAmount(ImGuiNavInput_PadDown + stick_no*4, mode) - GetNavInputAmount(ImGuiNavInput_PadUp + stick_no*4, mode);
2427+
if (slow_factor != 0.0f && IsNavInputDown(ImGuiNavInput_PadTweakSlow))
2428+
delta *= slow_factor;
2429+
if (fast_factor != 0.0f && IsNavInputDown(ImGuiNavInput_PadTweakFast))
2430+
delta *= fast_factor;
2431+
return delta;
2432+
}
2433+
23812434
static void NavUpdate()
23822435
{
23832436
ImGuiContext& g = *GImGui;
@@ -2452,7 +2505,7 @@ static void NavUpdate()
24522505
}
24532506

24542507
// Navigation windowing mode (change focus, move/resize window)
2455-
if (!g.NavWindowingTarget && IsKeyPressedMap(ImGuiKey_NavMenu, false))
2508+
if (!g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_PadMenu, ImGuiNavReadMode_Pressed))
24562509
{
24572510
ImGuiWindow* window = g.NavWindow;
24582511
if (!window)
@@ -2467,13 +2520,13 @@ static void NavUpdate()
24672520
if (g.NavWindowingTarget)
24682521
{
24692522
// Visuals only appears after a brief time holding the button, so that a fast tap (to toggle NavLayer) doesn't add visual noise
2470-
const float pressed_duration = g.IO.KeysDownDuration[g.IO.KeyMap[ImGuiKey_NavMenu]];
2523+
const float pressed_duration = g.IO.NavInputsDownDuration[ImGuiNavInput_PadMenu];
24712524
g.NavWindowingDisplayAlpha = ImMax(g.NavWindowingDisplayAlpha, ImSaturate((pressed_duration - 0.20f) / 0.05f));
24722525
g.NavWindowingToggleLayer &= (g.NavWindowingDisplayAlpha < 1.0f); // Once button is held long enough we don't consider it a tag-to-toggle-layer press anymore.
24732526

24742527
// Select window to focus
24752528
// FIXME-NAVIGATION: Need to clarify input semantic, naming is misleading/incorrect here.
2476-
int focus_change_dir = IsKeyPressedMap(ImGuiKey_NavTweakFaster, true) ? -1 : IsKeyPressedMap(ImGuiKey_NavTweakSlower, true) ? +1 : 0;
2529+
const int focus_change_dir = (int)IsNavInputPressed(ImGuiNavInput_PadFocusPrev, ImGuiNavReadMode_RepeatSlow) - (int)IsNavInputPressed(ImGuiNavInput_PadFocusNext, ImGuiNavReadMode_RepeatSlow);
24772530
if (focus_change_dir != 0 && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_Modal))
24782531
{
24792532
const int i_current = FindWindowIndex(g.NavWindowingTarget);
@@ -2488,7 +2541,7 @@ static void NavUpdate()
24882541
// Move window
24892542
if (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoMove))
24902543
{
2491-
const ImVec2 move_delta = ImGui::NavGetMovingDir(1);
2544+
const ImVec2 move_delta = GetNavInputAmount2d(1, ImGuiNavReadMode_Down);
24922545
if (move_delta.x != 0.0f || move_delta.y != 0.0f)
24932546
{
24942547
const float move_speed = ImFloor(600 * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y));
@@ -2498,7 +2551,7 @@ static void NavUpdate()
24982551
}
24992552
}
25002553

2501-
if (!IsKeyDownMap(ImGuiKey_NavMenu))
2554+
if (!IsNavInputDown(ImGuiNavInput_PadMenu))
25022555
{
25032556
// Apply actual focus only when releasing the NavMenu button (until then the window was merely rendered front-most)
25042557
if (g.NavWindowingTarget && !g.NavWindowingToggleLayer && (!g.NavWindow || g.NavWindowingTarget != g.NavWindow->RootNonPopupWindow))
@@ -2532,7 +2585,7 @@ static void NavUpdate()
25322585
g.IO.NavActive = (g.IO.NavUsable && g.NavId != 0 && !g.NavDisableHighlight) || (g.NavWindowingTarget != NULL) || g.NavInitDefaultRequest;
25332586

25342587
// Process NavCancel input (to close a popup, get back to parent, clear focus)
2535-
if (IsKeyPressedMap(ImGuiKey_NavCancel))
2588+
if (IsNavInputPressed(ImGuiNavInput_PadCancel, ImGuiNavReadMode_Pressed))
25362589
{
25372590
if (g.ActiveId != 0)
25382591
{
@@ -2577,8 +2630,8 @@ static void NavUpdate()
25772630
}
25782631
}
25792632

2580-
g.NavActivateId = (g.NavId && !g.NavDisableHighlight && !g.NavWindowingTarget && g.ActiveId == 0 && IsKeyPressedMap(ImGuiKey_NavActivate)) ? g.NavId : 0;
2581-
g.NavInputId = (g.NavId && !g.NavDisableHighlight && !g.NavWindowingTarget && g.ActiveId == 0 && IsKeyPressedMap(ImGuiKey_NavInput)) ? g.NavId : 0;
2633+
g.NavActivateId = (g.NavId && !g.NavDisableHighlight && !g.NavWindowingTarget && g.ActiveId == 0 && IsNavInputPressed(ImGuiNavInput_PadActivate, ImGuiNavReadMode_Repeat)) ? g.NavId : 0;
2634+
g.NavInputId = (g.NavId && !g.NavDisableHighlight && !g.NavWindowingTarget && g.ActiveId == 0 && IsNavInputPressed(ImGuiNavInput_PadInput, ImGuiNavReadMode_Repeat)) ? g.NavId : 0;
25822635
if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
25832636
{
25842637
g.NavActivateId = g.NavInputId = 0;
@@ -2591,10 +2644,10 @@ static void NavUpdate()
25912644
g.NavMoveDir = ImGuiNavDir_None;
25922645
if (g.NavWindow && !g.NavWindowingTarget && allowed_dir_flags && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
25932646
{
2594-
if ((allowed_dir_flags & (1<<ImGuiNavDir_Left)) && IsKeyPressedMap(ImGuiKey_NavLeft, true)) g.NavMoveDir = ImGuiNavDir_Left;
2595-
if ((allowed_dir_flags & (1<<ImGuiNavDir_Right)) && IsKeyPressedMap(ImGuiKey_NavRight, true)) g.NavMoveDir = ImGuiNavDir_Right;
2596-
if ((allowed_dir_flags & (1<<ImGuiNavDir_Up)) && IsKeyPressedMap(ImGuiKey_NavUp, true)) g.NavMoveDir = ImGuiNavDir_Up;
2597-
if ((allowed_dir_flags & (1<<ImGuiNavDir_Down)) && IsKeyPressedMap(ImGuiKey_NavDown, true)) g.NavMoveDir = ImGuiNavDir_Down;
2647+
if ((allowed_dir_flags & (1<<ImGuiNavDir_Left)) && IsNavInputPressed(ImGuiNavInput_PadLeft, ImGuiNavReadMode_Repeat)) g.NavMoveDir = ImGuiNavDir_Left;
2648+
if ((allowed_dir_flags & (1<<ImGuiNavDir_Right)) && IsNavInputPressed(ImGuiNavInput_PadRight, ImGuiNavReadMode_Repeat)) g.NavMoveDir = ImGuiNavDir_Right;
2649+
if ((allowed_dir_flags & (1<<ImGuiNavDir_Up)) && IsNavInputPressed(ImGuiNavInput_PadUp, ImGuiNavReadMode_Repeat)) g.NavMoveDir = ImGuiNavDir_Up;
2650+
if ((allowed_dir_flags & (1<<ImGuiNavDir_Down)) && IsNavInputPressed(ImGuiNavInput_PadDown, ImGuiNavReadMode_Repeat)) g.NavMoveDir = ImGuiNavDir_Down;
25982651
}
25992652
if (g.NavMoveDir != ImGuiNavDir_None)
26002653
g.NavMoveRequest = true;
@@ -2608,7 +2661,7 @@ static void NavUpdate()
26082661
SetWindowScrollY(g.NavWindow, ImFloor(g.NavWindow->Scroll.y + ((g.NavMoveDir == ImGuiNavDir_Up) ? -1.0f : +1.0f) * scroll_speed));
26092662

26102663
// Manual scroll with NavScrollXXX keys
2611-
ImVec2 scroll_dir = ImGui::NavGetMovingDir(1, 1.0f/10.0f, 10.0f);
2664+
ImVec2 scroll_dir = GetNavInputAmount2d(1, ImGuiNavReadMode_Down, 1.0f/10.0f, 10.0f);
26122665
if (scroll_dir.x != 0.0f && g.NavWindow->ScrollbarX)
26132666
{
26142667
SetWindowScrollX(g.NavWindow, ImFloor(g.NavWindow->Scroll.x + scroll_dir.x * scroll_speed));
@@ -2695,6 +2748,9 @@ void ImGui::NewFrame()
26952748
memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration));
26962749
for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
26972750
g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f;
2751+
memcpy(g.IO.NavInputsPrev, g.IO.NavInputs, sizeof(g.IO.NavInputs));
2752+
for (int i = 0; i < IM_ARRAYSIZE(g.IO.NavInputs); i++)
2753+
g.IO.NavInputsDownDuration[i] = (g.IO.NavInputs[i] > 0.0f) ? (g.IO.NavInputsDownDuration[i] < 0.0f ? 0.0f : g.IO.NavInputsDownDuration[i] + g.IO.DeltaTime) : -1.0f;
26982754

26992755
// Update directional navigation which may override MousePos if 'NavMovesMouse=true'
27002756
NavUpdate();
@@ -3708,20 +3764,23 @@ bool ImGui::IsKeyDown(int key_index)
37083764
return GImGui->IO.KeysDown[key_index];
37093765
}
37103766

3767+
int ImGui::CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_delay, float repeat_rate)
3768+
{
3769+
if (t == 0.0f)
3770+
return 1;
3771+
if (t <= repeat_delay || repeat_rate <= 0.0f)
3772+
return 0;
3773+
const int count = (int)((t - repeat_delay) / repeat_rate) - (int)((t_prev - repeat_delay) / repeat_rate);
3774+
return (count > 0) ? count : 0;
3775+
}
3776+
37113777
int ImGui::GetKeyPressedAmount(int key_index, float repeat_delay, float repeat_rate)
37123778
{
37133779
ImGuiContext& g = *GImGui;
37143780
if (key_index < 0) return false;
37153781
IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
37163782
const float t = g.IO.KeysDownDuration[key_index];
3717-
if (t == 0.0f)
3718-
return 1;
3719-
if (t > repeat_delay && repeat_rate > 0.0f)
3720-
{
3721-
int count = (int)((t - repeat_delay) / repeat_rate) - (int)((t - repeat_delay - g.IO.DeltaTime) / repeat_rate);
3722-
return (count > 0) ? count : 0;
3723-
}
3724-
return 0;
3783+
return CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, repeat_delay, repeat_rate);
37253784
}
37263785

37273786
bool ImGui::IsKeyPressed(int key_index, bool repeat)
@@ -4823,9 +4882,13 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
48234882
ImVec2 nav_resize_delta(0.0f, 0.0f);
48244883
if (g.NavWindowingTarget == window)
48254884
{
4826-
const float resize_speed = ImFloor(600 * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y));
4827-
nav_resize_delta = NavGetMovingDir(0) * resize_speed;
4828-
held |= (nav_resize_delta.x != 0.0f || nav_resize_delta.y != 0.0f); // For coloring
4885+
nav_resize_delta = GetNavInputAmount2d(0, ImGuiNavReadMode_Down);
4886+
if (nav_resize_delta.x != 0.0f || nav_resize_delta.y != 0.0f)
4887+
{
4888+
nav_resize_delta *= ImFloor(600 * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y));
4889+
g.NavDisableMouseHover = true;
4890+
held = true; // For coloring
4891+
}
48294892
}
48304893

48314894
ImVec2 size_target(FLT_MAX,FLT_MAX);
@@ -6267,13 +6330,13 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
62676330
{
62686331
// We report navigated item as hovered but we don't set g.HoveredId to not interfere with mouse
62696332
hovered = true;
6270-
if (!g.NavWindowingTarget && IsKeyDownMap(ImGuiKey_NavActivate))
6333+
if (!g.NavWindowingTarget && IsNavInputDown(ImGuiNavInput_PadActivate))
62716334
{
62726335
// Set active id so it can be queried by user via IsItemActive(), etc. but don't react to it ourselves
6273-
g.NavActivateId = g.NavId;
6274-
SetActiveID(g.NavId, window);
6336+
g.NavActivateId = id;
6337+
SetActiveID(id, window);
62756338
g.ActiveIdAllowNavDirFlags = (1 << ImGuiNavDir_Left) | (1 << ImGuiNavDir_Right) | (1 << ImGuiNavDir_Up) | (1 << ImGuiNavDir_Down);
6276-
if (IsKeyPressedMap(ImGuiKey_NavActivate, (flags & ImGuiButtonFlags_Repeat) != 0))
6339+
if (IsNavInputPressed(ImGuiNavInput_PadActivate, (flags & ImGuiButtonFlags_Repeat) ? ImGuiNavReadMode_Repeat : ImGuiNavReadMode_Pressed))
62776340
pressed = true;
62786341
}
62796342
}
@@ -6296,7 +6359,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
62966359
g.NavDisableHighlight = true;
62976360
}
62986361
if (g.ActiveId == id && g.ActiveIdSource == ImGuiInputSource_Nav)
6299-
if (!IsKeyDownMap(ImGuiKey_NavActivate))
6362+
if (!IsNavInputDown(ImGuiNavInput_PadActivate))
63006363
SetActiveID(0);
63016364

63026365
// AllowOverlap mode (rarely used) requires previous frame HoveredId to be null or to match. This allows using patterns where a later submitted widget overlaps a previous one.
@@ -7136,47 +7199,6 @@ int ImGui::ParseFormatPrecision(const char* fmt, int default_precision)
71367199
return precision;
71377200
}
71387201

7139-
ImVec2 ImGui::NavGetMovingDir(int stick_no, float slow_factor, float fast_factor)
7140-
{
7141-
IM_ASSERT(stick_no >= 0 && stick_no < 2);
7142-
ImVec2 dir(0.0f, 0.0f);
7143-
if (stick_no == 0)
7144-
{
7145-
if (IsKeyDownMap(ImGuiKey_NavLeft)) dir.x -= 1.0f;
7146-
if (IsKeyDownMap(ImGuiKey_NavRight)) dir.x += 1.0f;
7147-
if (IsKeyDownMap(ImGuiKey_NavUp)) dir.y -= 1.0f;
7148-
if (IsKeyDownMap(ImGuiKey_NavDown)) dir.y += 1.0f;
7149-
}
7150-
if (stick_no == 1)
7151-
{
7152-
if (IsKeyDownMap(ImGuiKey_NavScrollLeft)) dir.x -= 1.0f;
7153-
if (IsKeyDownMap(ImGuiKey_NavScrollRight)) dir.x += 1.0f;
7154-
if (IsKeyDownMap(ImGuiKey_NavScrollUp)) dir.y -= 1.0f;
7155-
if (IsKeyDownMap(ImGuiKey_NavScrollDown)) dir.y += 1.0f;
7156-
}
7157-
if (slow_factor != 0.0f && IsKeyDownMap(ImGuiKey_NavTweakSlower))
7158-
dir *= slow_factor;
7159-
if (fast_factor != 0.0f && IsKeyDownMap(ImGuiKey_NavTweakFaster))
7160-
dir *= fast_factor;
7161-
return dir;
7162-
}
7163-
7164-
// Adjustment delta for slider/drag/etc.
7165-
// FIXME-NAVIGATION: Accelerate over time? Expose more settings? Handle faster/slower modifiers here instead of widget level?
7166-
ImVec2 ImGui::NavGetTweakDelta()
7167-
{
7168-
ImGuiContext& g = *GImGui;
7169-
float repeat_delay = g.IO.KeyRepeatDelay * 0.80f;
7170-
float repeat_rate = g.IO.KeyRepeatRate * 0.30f;
7171-
7172-
ImVec2 delta(0.0f, 0.0f);
7173-
if (int count = GetKeyPressedAmount(g.IO.KeyMap[ImGuiKey_NavLeft], repeat_delay, repeat_rate)) delta.x = (float)-count;
7174-
if (int count = GetKeyPressedAmount(g.IO.KeyMap[ImGuiKey_NavRight], repeat_delay, repeat_rate)) delta.x = (float)+count;
7175-
if (int count = GetKeyPressedAmount(g.IO.KeyMap[ImGuiKey_NavUp], repeat_delay, repeat_rate)) delta.y = (float)-count;
7176-
if (int count = GetKeyPressedAmount(g.IO.KeyMap[ImGuiKey_NavDown], repeat_delay, repeat_rate)) delta.y = (float)+count;
7177-
return delta;
7178-
}
7179-
71807202
static float GetMinimumStepAtDecimalPrecision(int decimal_precision)
71817203
{
71827204
static const float min_steps[10] = { 1.0f, 0.1f, 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, 0.000000001f };
@@ -7275,26 +7297,26 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v
72757297
normalized_pos = 1.0f - normalized_pos;
72767298
set_new_value = true;
72777299
}
7278-
else if (g.ActiveIdSource == ImGuiInputSource_Nav && IsKeyDownMap(ImGuiKey_NavActivate))
7300+
else if (g.ActiveIdSource == ImGuiInputSource_Nav && IsNavInputDown(ImGuiNavInput_PadActivate))
72797301
{
7280-
const ImVec2 delta2 = NavGetTweakDelta();
7302+
const ImVec2 delta2 = GetNavInputAmount2d(0, ImGuiNavReadMode_RepeatFast, 0.0f, 0.0f);
72817303
if (float delta = is_horizontal ? delta2.x : -delta2.y)
72827304
{
72837305
normalized_pos = SliderBehaviorCalcRatioFromValue(*v, v_min, v_max, power, linear_zero_pos);
72847306
if (decimal_precision == 0 && !is_non_linear)
72857307
{
7286-
if (fabsf(v_max - v_min) <= 100.0f || IsKeyDownMap(ImGuiKey_NavTweakSlower))
7308+
if (fabsf(v_max - v_min) <= 100.0f || IsNavInputDown(ImGuiNavInput_PadTweakSlow))
72877309
delta = ((delta < 0.0f) ? -1.0f : +1.0f) / (v_max - v_min); // Gamepad/keyboard tweak speeds in integer steps
72887310
else
72897311
delta /= 100.0f;
72907312
}
72917313
else
72927314
{
72937315
delta /= 100.0f; // Gamepad/keyboard tweak speeds in % of slider bounds
7294-
if (IsKeyDownMap(ImGuiKey_NavTweakSlower))
7316+
if (IsNavInputDown(ImGuiNavInput_PadTweakSlow))
72957317
delta /= 10.0f;
72967318
}
7297-
if (IsKeyDownMap(ImGuiKey_NavTweakFaster))
7319+
if (IsNavInputDown(ImGuiNavInput_PadTweakFast))
72987320
delta *= 10.0f;
72997321
normalized_pos = ImSaturate(normalized_pos + delta); // FIXME-NAVIGATION: todo: cancel adjustment if current value already past edge and we are moving in edge direction, to avoid clamping value to edge.
73007322
set_new_value = true;
@@ -7602,7 +7624,7 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
76027624
// Process clicking on the drag
76037625
if (g.ActiveId == id)
76047626
{
7605-
if (g.IO.MouseDown[0] || IsKeyDownMap(ImGuiKey_NavActivate))
7627+
if (g.IO.MouseDown[0] || IsNavInputDown(ImGuiNavInput_PadActivate))
76067628
{
76077629
if (g.ActiveIdIsJustActivated)
76087630
{
@@ -7627,11 +7649,7 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
76277649
}
76287650
if (g.ActiveIdSource == ImGuiInputSource_Nav)
76297651
{
7630-
adjust_delta = NavGetTweakDelta().x;
7631-
if (IsKeyDownMap(ImGuiKey_NavTweakFaster))
7632-
adjust_delta *= 10.0f;
7633-
if (IsKeyDownMap(ImGuiKey_NavTweakSlower))
7634-
adjust_delta /= 10.0f;
7652+
adjust_delta = GetNavInputAmount2d(0, ImGuiNavReadMode_RepeatFast, 1.0f/10.0f, 1.0f).x;
76357653
}
76367654
adjust_delta *= v_speed;
76377655
g.DragLastMouseDelta.x = mouse_drag_delta.x;

0 commit comments

Comments
 (0)