Nav: added io.ConfigNavEscapeClearFocusWindow to clear focused window on Escape. (#3200)

+ pressing escape to hide nav highlight doesn't clear location from when ctrl+tabbing back into same window later.
This commit is contained in:
ocornut 2024-10-14 16:57:34 +02:00
parent ba5161740e
commit b001038901
4 changed files with 11 additions and 2 deletions

View file

@ -67,6 +67,9 @@ Other changes:
state to draw callbacks. (#6969, #5834, #7468, #3590)
- IO: WantCaptureKeyboard is never set when ImGuiConfigFlags_NoKeyboard is enabled. (#4921)
- Error Handling: turned a few more functions into recoverable errors. (#1651)
- Nav: added io.ConfigNavEscapeClearFocusWindow to clear focused window on Escape. (#3200)
- Nav: pressing escape to hide nav highlight doesn't clear location from when ctrl+tabbing back
into same window later.
- DrawList: AddCallback() added an optional size parameter allowing to copy and
store any amount of user data for usage by callbacks: (#6969, #4770, #7665)
- If userdata_size == 0: we copy/store the 'userdata' argument as-is (existing behavior).

View file

@ -1408,6 +1408,7 @@ ImGuiIO::ImGuiIO()
ConfigNavSwapGamepadButtons = false;
ConfigNavMoveSetMousePos = false;
ConfigNavCaptureKeyboard = true;
ConfigNavEscapeClearFocusWindow = false;
ConfigInputTrickleEventQueue = true;
ConfigInputTextCursorBlink = true;
ConfigInputTextEnterKeepActive = false;
@ -13316,7 +13317,7 @@ void ImGui::NavMoveRequestApplyResult()
NavRestoreHighlightAfterMove();
}
// Process NavCancel input (to close a popup, get back to parent, clear focus)
// Process Escape/NavCancel input (to close a popup, get back to parent, clear focus)
// FIXME: In order to support e.g. Escape to clear a selection we'll need:
// - either to store the equivalent of ActiveIdUsingKeyInputMask for a FocusScope and test for it.
// - either to move most/all of those tests to the epilogue/end functions of the scope they are dealing with (e.g. exit child window in EndChild()) or in EndFrame(), to allow an earlier intercept
@ -13358,11 +13359,13 @@ static void ImGui::NavUpdateCancelRequest()
{
// Clear NavLastId for popups but keep it for regular child window so we can leave one and come back where we were
// FIXME-NAV: This should happen on window appearing.
if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow)))
if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup)))// || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow)))
g.NavWindow->NavLastIds[0] = 0;
// Clear nav focus
g.NavId = 0;
if (g.IO.ConfigNavEscapeClearFocusWindow)
FocusWindow(NULL);
}
}

View file

@ -2250,6 +2250,7 @@ struct ImGuiIO
bool ConfigNavSwapGamepadButtons; // = false // Swap Activate<>Cancel (A<>B) buttons, matching typical "Nintendo/Japanese style" gamepad layout.
bool ConfigNavMoveSetMousePos; // = false // Directional/tabbing navigation teleports the mouse cursor. May be useful on TV/console systems where moving a virtual mouse is difficult. Will update io.MousePos and set io.WantSetMousePos=true.
bool ConfigNavCaptureKeyboard; // = true // Sets io.WantCaptureKeyboard when io.NavActive is set.
bool ConfigNavEscapeClearFocusWindow;// = false // Pressing Escape (when no item is active, no popup open etc.) clears focused window + navigation id/highlight.
bool ConfigInputTrickleEventQueue; // = true // Enable input queue trickling: some types of events submitted during the same frame (e.g. button down + up) will be spread over multiple frames, improving interactions with low framerates.
bool ConfigInputTextCursorBlink; // = true // Enable blinking cursor (optional as some users consider it to be distracting).
bool ConfigInputTextEnterKeepActive; // = false // [BETA] Pressing Enter will keep item active and select contents (single-line only).

View file

@ -532,6 +532,8 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::Checkbox("io.ConfigNavMoveSetMousePos", &io.ConfigNavMoveSetMousePos);
ImGui::SameLine(); HelpMarker("Directional/tabbing navigation teleports the mouse cursor. May be useful on TV/console systems where moving a virtual mouse is difficult");
ImGui::Checkbox("io.ConfigNavCaptureKeyboard", &io.ConfigNavCaptureKeyboard);
ImGui::Checkbox("io.ConfigNavEscapeClearFocusWindow", &io.ConfigNavEscapeClearFocusWindow);
ImGui::SameLine(); HelpMarker("Pressing Escape clears focused window.");
ImGui::SeparatorText("Widgets");
ImGui::Checkbox("io.ConfigInputTextCursorBlink", &io.ConfigInputTextCursorBlink);