@@ -10266,6 +10266,10 @@ static void ImGui::NavUpdate()
10266
10266
for (ImGuiKey key : nav_keyboard_keys_to_change_source)
10267
10267
if (IsKeyDown(key))
10268
10268
g.NavInputSource = ImGuiInputSource_Keyboard;
10269
+ if (!nav_gamepad_active && g.NavInputSource == ImGuiInputSource_Gamepad)
10270
+ g.NavInputSource = ImGuiInputSource_None;
10271
+ if (!nav_keyboard_active && g.NavInputSource == ImGuiInputSource_Keyboard)
10272
+ g.NavInputSource = ImGuiInputSource_None;
10269
10273
10270
10274
// Process navigation init request (select first/default focus)
10271
10275
if (g.NavInitResultId != 0)
@@ -10310,10 +10314,10 @@ static void ImGui::NavUpdate()
10310
10314
g.NavActivateFlags = ImGuiActivateFlags_None;
10311
10315
if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
10312
10316
{
10313
- const bool activate_down = IsKeyDown(ImGuiKey_Space) || IsKeyDown(ImGuiKey_NavGamepadActivate);
10314
- const bool activate_pressed = activate_down && (IsKeyPressed(ImGuiKey_Space, false) || IsKeyPressed(ImGuiKey_NavGamepadActivate, false));
10315
- const bool input_down = IsKeyDown(ImGuiKey_Enter) || IsKeyDown(ImGuiKey_NavGamepadInput);
10316
- const bool input_pressed = input_down && (IsKeyPressed(ImGuiKey_Enter, false) || IsKeyPressed(ImGuiKey_NavGamepadInput, false));
10317
+ const bool activate_down = (nav_keyboard_active && IsKeyDown(ImGuiKey_Space)) || (nav_gamepad_active && IsKeyDown(ImGuiKey_NavGamepadActivate) );
10318
+ const bool activate_pressed = activate_down && ((nav_keyboard_active && IsKeyPressed(ImGuiKey_Space, false)) || (nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadActivate, false) ));
10319
+ const bool input_down = (nav_keyboard_active && IsKeyDown(ImGuiKey_Enter)) || (nav_gamepad_active && IsKeyDown(ImGuiKey_NavGamepadInput) );
10320
+ const bool input_pressed = input_down && ((nav_keyboard_active && IsKeyPressed(ImGuiKey_Enter, false)) || (nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadInput, false) ));
10317
10321
if (g.ActiveId == 0 && activate_pressed)
10318
10322
{
10319
10323
g.NavActivateId = g.NavId;
@@ -10368,14 +10372,17 @@ static void ImGui::NavUpdate()
10368
10372
SetScrollY(window, ImFloor(window->Scroll.y + ((move_dir == ImGuiDir_Up) ? -1.0f : +1.0f) * scroll_speed));
10369
10373
}
10370
10374
10371
- // *Normal* Manual scroll with NavScrollXXX keys
10375
+ // *Normal* Manual scroll with LStick
10372
10376
// Next movement request will clamp the NavId reference rectangle to the visible area, so navigation will resume within those bounds.
10373
- const ImVec2 scroll_dir = GetKeyVector2d(ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp, ImGuiKey_GamepadLStickDown);
10374
- const float tweak_factor = IsKeyDown(ImGuiKey_NavGamepadTweakSlow) ? 1.0f / 10.0f : IsKeyDown(ImGuiKey_NavGamepadTweakFast) ? 10.0f : 1.0f;
10375
- if (scroll_dir.x != 0.0f && window->ScrollbarX)
10376
- SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed * tweak_factor));
10377
- if (scroll_dir.y != 0.0f)
10378
- SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed * tweak_factor));
10377
+ if (nav_gamepad_active)
10378
+ {
10379
+ const ImVec2 scroll_dir = GetKeyVector2d(ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp, ImGuiKey_GamepadLStickDown);
10380
+ const float tweak_factor = IsKeyDown(ImGuiKey_NavGamepadTweakSlow) ? 1.0f / 10.0f : IsKeyDown(ImGuiKey_NavGamepadTweakFast) ? 10.0f : 1.0f;
10381
+ if (scroll_dir.x != 0.0f && window->ScrollbarX)
10382
+ SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed * tweak_factor));
10383
+ if (scroll_dir.y != 0.0f)
10384
+ SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed * tweak_factor));
10385
+ }
10379
10386
}
10380
10387
10381
10388
// Always prioritize mouse highlight if navigation is disabled
@@ -10427,6 +10434,8 @@ void ImGui::NavUpdateCreateMoveRequest()
10427
10434
ImGuiContext& g = *GImGui;
10428
10435
ImGuiIO& io = g.IO;
10429
10436
ImGuiWindow* window = g.NavWindow;
10437
+ const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
10438
+ const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
10430
10439
10431
10440
if (g.NavMoveForwardToNextFrame && window != NULL)
10432
10441
{
@@ -10445,18 +10454,17 @@ void ImGui::NavUpdateCreateMoveRequest()
10445
10454
if (window && !g.NavWindowingTarget && !(window->Flags & ImGuiWindowFlags_NoNavInputs))
10446
10455
{
10447
10456
const ImGuiInputFlags repeat_mode = ImGuiInputFlags_Repeat | ImGuiInputFlags_RepeatRateNavMove;
10448
- if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && (IsKeyPressedEx(ImGuiKey_GamepadDpadLeft, repeat_mode) || IsKeyPressedEx(ImGuiKey_LeftArrow, repeat_mode))) { g.NavMoveDir = ImGuiDir_Left; }
10449
- if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && (IsKeyPressedEx(ImGuiKey_GamepadDpadRight, repeat_mode) || IsKeyPressedEx(ImGuiKey_RightArrow, repeat_mode))) { g.NavMoveDir = ImGuiDir_Right; }
10450
- if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && (IsKeyPressedEx(ImGuiKey_GamepadDpadUp, repeat_mode) || IsKeyPressedEx(ImGuiKey_UpArrow, repeat_mode))) { g.NavMoveDir = ImGuiDir_Up; }
10451
- if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && (IsKeyPressedEx(ImGuiKey_GamepadDpadDown, repeat_mode) || IsKeyPressedEx(ImGuiKey_DownArrow, repeat_mode))) { g.NavMoveDir = ImGuiDir_Down; }
10457
+ if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && ((nav_gamepad_active && IsKeyPressedEx(ImGuiKey_GamepadDpadLeft, repeat_mode)) || (nav_keyboard_active && IsKeyPressedEx(ImGuiKey_LeftArrow, repeat_mode) ))) { g.NavMoveDir = ImGuiDir_Left; }
10458
+ if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && ((nav_gamepad_active && IsKeyPressedEx(ImGuiKey_GamepadDpadRight, repeat_mode)) || (nav_keyboard_active && IsKeyPressedEx(ImGuiKey_RightArrow, repeat_mode) ))) { g.NavMoveDir = ImGuiDir_Right; }
10459
+ if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && ((nav_gamepad_active && IsKeyPressedEx(ImGuiKey_GamepadDpadUp, repeat_mode)) || (nav_keyboard_active && IsKeyPressedEx(ImGuiKey_UpArrow, repeat_mode) ))) { g.NavMoveDir = ImGuiDir_Up; }
10460
+ if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && ((nav_gamepad_active && IsKeyPressedEx(ImGuiKey_GamepadDpadDown, repeat_mode)) || (nav_keyboard_active && IsKeyPressedEx(ImGuiKey_DownArrow, repeat_mode) ))) { g.NavMoveDir = ImGuiDir_Down; }
10452
10461
}
10453
10462
g.NavMoveClipDir = g.NavMoveDir;
10454
10463
g.NavScoringNoClipRect = ImRect(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX);
10455
10464
}
10456
10465
10457
10466
// Update PageUp/PageDown/Home/End scroll
10458
10467
// FIXME-NAV: Consider enabling those keys even without the master ImGuiConfigFlags_NavEnableKeyboard flag?
10459
- const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
10460
10468
float scoring_rect_offset_y = 0.0f;
10461
10469
if (window && g.NavMoveDir == ImGuiDir_None && nav_keyboard_active)
10462
10470
scoring_rect_offset_y = NavUpdatePageUpPageDown();
@@ -10654,7 +10662,9 @@ void ImGui::NavMoveRequestApplyResult()
10654
10662
static void ImGui::NavUpdateCancelRequest()
10655
10663
{
10656
10664
ImGuiContext& g = *GImGui;
10657
- if (!IsKeyPressed(ImGuiKey_Escape, false) && !IsKeyPressed(ImGuiKey_NavGamepadCancel, false))
10665
+ const bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
10666
+ const bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
10667
+ if (!(nav_keyboard_active && IsKeyPressed(ImGuiKey_Escape, false)) && !(nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadCancel, false)))
10658
10668
return;
10659
10669
10660
10670
IMGUI_DEBUG_LOG_NAV("[nav] NavUpdateCancelRequest()\n");
@@ -10906,8 +10916,10 @@ static void ImGui::NavUpdateWindowing()
10906
10916
}
10907
10917
10908
10918
// Start CTRL+Tab or Square+L/R window selection
10909
- const bool start_windowing_with_gamepad = allow_windowing && !g.NavWindowingTarget && IsKeyPressed(ImGuiKey_NavGamepadMenu, false);
10910
- const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && io.KeyCtrl && IsKeyPressed(ImGuiKey_Tab, false);
10919
+ const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
10920
+ const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
10921
+ const bool start_windowing_with_gamepad = allow_windowing && nav_gamepad_active && !g.NavWindowingTarget && IsKeyPressed(ImGuiKey_NavGamepadMenu, false);
10922
+ const bool start_windowing_with_keyboard = allow_windowing && nav_keyboard_active && !g.NavWindowingTarget && io.KeyCtrl && IsKeyPressed(ImGuiKey_Tab, false);
10911
10923
if (start_windowing_with_gamepad || start_windowing_with_keyboard)
10912
10924
if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1))
10913
10925
{
@@ -10959,7 +10971,6 @@ static void ImGui::NavUpdateWindowing()
10959
10971
// Keyboard: Press and Release ALT to toggle menu layer
10960
10972
// - Testing that only Alt is tested prevents Alt+Shift or AltGR from toggling menu layer.
10961
10973
// - AltGR is normally Alt+Ctrl but we can't reliably detect it (not all backends/systems/layout emit it as Alt+Ctrl). But even on keyboards without AltGR we don't want Alt+Ctrl to open menu anyway.
10962
- const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
10963
10974
if (nav_keyboard_active && IsKeyPressed(ImGuiKey_ModAlt))
10964
10975
{
10965
10976
g.NavWindowingToggleLayer = true;
0 commit comments