mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 03:58:47 +02:00
Nav: Track nav input source more generally (gamepad vs keyboard) (#787) + update todos and demo tweaks
This commit is contained in:
28
imgui.cpp
28
imgui.cpp
@ -2811,12 +2811,12 @@ static void ImGui::NavUpdateWindowing()
|
||||
g.NavWindowingTarget = window->RootWindowForTabbing;
|
||||
g.NavWindowingHighlightTimer = g.NavWindowingHighlightAlpha = 0.0f;
|
||||
g.NavWindowingToggleLayer = start_windowing_with_keyboard ? false : true;
|
||||
g.NavWindowingInputSource = start_windowing_with_keyboard ? ImGuiInputSource_NavKeyboard : ImGuiInputSource_NavGamepad;
|
||||
g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_NavKeyboard : ImGuiInputSource_NavGamepad;
|
||||
}
|
||||
|
||||
// Gamepad update
|
||||
g.NavWindowingHighlightTimer += g.IO.DeltaTime;
|
||||
if (g.NavWindowingTarget && g.NavWindowingInputSource == ImGuiInputSource_NavGamepad)
|
||||
if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavGamepad)
|
||||
{
|
||||
// Highlight only appears after a brief time holding the button, so that a fast tap on PadMenu (to toggle NavLayer) doesn't add visual noise
|
||||
g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingHighlightTimer - 0.20f) / 0.05f));
|
||||
@ -2842,7 +2842,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
}
|
||||
|
||||
// Keyboard: Focus
|
||||
if (g.NavWindowingTarget && g.NavWindowingInputSource == ImGuiInputSource_NavKeyboard)
|
||||
if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavKeyboard)
|
||||
{
|
||||
// Visuals only appears after a brief time after pressing TAB the first time, so that a fast CTRL+TAB doesn't add visual noise
|
||||
g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingHighlightTimer - 0.15f) / 0.04f)); // 1.0f
|
||||
@ -2862,9 +2862,9 @@ static void ImGui::NavUpdateWindowing()
|
||||
if (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoMove))
|
||||
{
|
||||
ImVec2 move_delta;
|
||||
if (g.NavWindowingInputSource == ImGuiInputSource_NavKeyboard && !g.IO.KeyShift)
|
||||
if (g.NavInputSource == ImGuiInputSource_NavKeyboard && !g.IO.KeyShift)
|
||||
move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard, ImGuiInputReadMode_Down);
|
||||
if (g.NavWindowingInputSource == ImGuiInputSource_NavGamepad)
|
||||
if (g.NavInputSource == ImGuiInputSource_NavGamepad)
|
||||
move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiInputReadMode_Down);
|
||||
if (move_delta.x != 0.0f || move_delta.y != 0.0f)
|
||||
{
|
||||
@ -2957,11 +2957,14 @@ static void ImGui::NavUpdate()
|
||||
if (g.NavScoringCount > 0) printf("[%05d] NavScoringCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.FrameCount, g.NavScoringCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
|
||||
#endif
|
||||
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad)
|
||||
if (g.IO.NavInputs[ImGuiNavInput_Activate] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Input] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Cancel] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Menu] > 0.0f)
|
||||
g.NavInputSource = ImGuiInputSource_NavGamepad;
|
||||
|
||||
// Update Keyboard->Nav inputs mapping
|
||||
memset(g.IO.NavInputs + ImGuiNavInput_InternalStart_, 0, (ImGuiNavInput_COUNT - ImGuiNavInput_InternalStart_) * sizeof(g.IO.NavInputs[0]));
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard)
|
||||
{
|
||||
#define NAV_MAP_KEY(_KEY, _NAV_INPUT) if (g.IO.KeyMap[_KEY] != -1 && IsKeyDown(g.IO.KeyMap[_KEY])) g.IO.NavInputs[_NAV_INPUT] = 1.0f;
|
||||
#define NAV_MAP_KEY(_KEY, _NAV_INPUT) if (IsKeyDown(g.IO.KeyMap[_KEY])) { g.IO.NavInputs[_NAV_INPUT] = 1.0f; g.NavInputSource = ImGuiInputSource_NavKeyboard; }
|
||||
NAV_MAP_KEY(ImGuiKey_Space, ImGuiNavInput_Activate );
|
||||
NAV_MAP_KEY(ImGuiKey_Enter, ImGuiNavInput_Input );
|
||||
NAV_MAP_KEY(ImGuiKey_Escape, ImGuiNavInput_Cancel );
|
||||
@ -2972,7 +2975,7 @@ static void ImGui::NavUpdate()
|
||||
if (g.IO.KeyCtrl) g.IO.NavInputs[ImGuiNavInput_TweakSlow] = 1.0f;
|
||||
if (g.IO.KeyShift) g.IO.NavInputs[ImGuiNavInput_TweakFast] = 1.0f;
|
||||
if (g.IO.KeyAlt) g.IO.NavInputs[ImGuiNavInput_KeyMenu_] = 1.0f;
|
||||
#undef NAV_MAP_KEY
|
||||
#undef NAV_MAP_KEY
|
||||
}
|
||||
|
||||
memcpy(g.IO.NavInputsDownDurationPrev, g.IO.NavInputsDownDuration, sizeof(g.IO.NavInputsDownDuration));
|
||||
@ -5513,13 +5516,13 @@ static void ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
|
||||
}
|
||||
PopID();
|
||||
|
||||
// Navigation/gamepad resize
|
||||
// Navigation resize (keyboard/gamepad)
|
||||
if (g.NavWindowingTarget == window)
|
||||
{
|
||||
ImVec2 nav_resize_delta;
|
||||
if (g.NavWindowingInputSource == ImGuiInputSource_NavKeyboard && g.IO.KeyShift)
|
||||
if (g.NavInputSource == ImGuiInputSource_NavKeyboard && g.IO.KeyShift)
|
||||
nav_resize_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard, ImGuiInputReadMode_Down);
|
||||
if (g.NavWindowingInputSource == ImGuiInputSource_NavGamepad)
|
||||
if (g.NavInputSource == ImGuiInputSource_NavGamepad)
|
||||
nav_resize_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_Down);
|
||||
if (nav_resize_delta.x != 0.0f || nav_resize_delta.y != 0.0f)
|
||||
{
|
||||
@ -13246,7 +13249,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
}
|
||||
if (ImGui::TreeNode("Internal state"))
|
||||
{
|
||||
const char* input_source_names[] = { "None", "Mouse", "Nav", "NavGamepad", "NavKeyboard" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT);
|
||||
const char* input_source_names[] = { "None", "Mouse", "Nav", "NavKeyboard", "NavGamepad" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT);
|
||||
ImGui::Text("HoveredWindow: '%s'", g.HoveredWindow ? g.HoveredWindow->Name : "NULL");
|
||||
ImGui::Text("HoveredRootWindow: '%s'", g.HoveredRootWindow ? g.HoveredRootWindow->Name : "NULL");
|
||||
ImGui::Text("HoveredId: 0x%08X/0x%08X (%.2f sec)", g.HoveredId, g.HoveredIdPreviousFrame, g.HoveredIdTimer); // Data is "in-flight" so depending on when the Metrics window is called we may see current frame information or not
|
||||
@ -13254,6 +13257,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
ImGui::Text("ActiveIdWindow: '%s'", g.ActiveIdWindow ? g.ActiveIdWindow->Name : "NULL");
|
||||
ImGui::Text("NavWindow: '%s'", g.NavWindow ? g.NavWindow->Name : "NULL");
|
||||
ImGui::Text("NavId: 0x%08X, NavLayer: %d", g.NavId, g.NavLayer);
|
||||
ImGui::Text("NavInputSource: %s", input_source_names[g.NavInputSource]);
|
||||
ImGui::Text("NavActive: %d, NavVisible: %d", g.IO.NavActive, g.IO.NavVisible);
|
||||
ImGui::Text("NavActivateId: 0x%08X, NavInputId: 0x%08X", g.NavActivateId, g.NavInputId);
|
||||
ImGui::Text("NavDisableHighlight: %d, NavDisableMouseHover: %d", g.NavDisableHighlight, g.NavDisableMouseHover);
|
||||
|
Reference in New Issue
Block a user