Skip to content

Commit 634a7ed

Browse files
committed
Nav: added SetNavCursorVisible(). (#1074, #2048, #7237, #8059)
+ Further internal renaming for consistency.
1 parent 0bae2db commit 634a7ed

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Other changes:
6767
state to draw callbacks. (#6969, #5834, #7468, #3590)
6868
- IO: WantCaptureKeyboard is never set when ImGuiConfigFlags_NoKeyboard is enabled. (#4921)
6969
- Error Handling: turned a few more functions into recoverable errors. (#1651)
70+
- Nav: added NavSetCursorVisible(bool visible) to manipulate visibility of keyboard/gamepad
71+
navigation cursor. (#1074, #2048, #7237, #8059)
7072
- Nav: added io.ConfigNavEscapeClearFocusItem and io.ConfigNavEscapeClearFocusWindow to change
7173
how pressing Escape affects navigation. (#8059, #2048, #1074, #3200)
7274
- Set io.ConfigNavEscapeClearFocusItem = true (default) to clear focused item and highlight.

imgui.cpp

+27-20
Original file line numberDiff line numberDiff line change
@@ -8558,7 +8558,7 @@ void ImGui::FocusItem()
85588558
return;
85598559
}
85608560

8561-
ImGuiNavMoveFlags move_flags = ImGuiNavMoveFlags_IsTabbing | ImGuiNavMoveFlags_FocusApi | ImGuiNavMoveFlags_NoSetNavHighlight | ImGuiNavMoveFlags_NoSelect;
8561+
ImGuiNavMoveFlags move_flags = ImGuiNavMoveFlags_IsTabbing | ImGuiNavMoveFlags_FocusApi | ImGuiNavMoveFlags_NoSetNavCursorVisible | ImGuiNavMoveFlags_NoSelect;
85628562
ImGuiScrollFlags scroll_flags = window->Appearing ? ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleEdgeY;
85638563
SetNavWindow(window);
85648564
NavMoveRequestSubmit(ImGuiDir_None, ImGuiDir_Up, move_flags, scroll_flags);
@@ -8593,7 +8593,7 @@ void ImGui::SetKeyboardFocusHere(int offset)
85938593

85948594
SetNavWindow(window);
85958595

8596-
ImGuiNavMoveFlags move_flags = ImGuiNavMoveFlags_IsTabbing | ImGuiNavMoveFlags_Activate | ImGuiNavMoveFlags_FocusApi | ImGuiNavMoveFlags_NoSetNavHighlight;
8596+
ImGuiNavMoveFlags move_flags = ImGuiNavMoveFlags_IsTabbing | ImGuiNavMoveFlags_Activate | ImGuiNavMoveFlags_FocusApi | ImGuiNavMoveFlags_NoSetNavCursorVisible;
85978597
ImGuiScrollFlags scroll_flags = window->Appearing ? ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleEdgeY;
85988598
NavMoveRequestSubmit(ImGuiDir_None, offset < 0 ? ImGuiDir_Up : ImGuiDir_Down, move_flags, scroll_flags); // FIXME-NAV: Once we refactor tabbing, add LegacyApi flag to not activate non-inputable.
85998599
if (offset == -1)
@@ -12209,6 +12209,20 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
1220912209
// In our terminology those should be interchangeable, yet right now this is super confusing.
1221012210
// Those two functions are merely a legacy artifact, so at minimum naming should be clarified.
1221112211

12212+
void ImGui::SetNavCursorVisible(bool visible)
12213+
{
12214+
ImGuiContext& g = *GImGui;
12215+
g.NavCursorVisible = visible;
12216+
}
12217+
12218+
// (was called NavRestoreHighlightAfterMove() before 1.91.4)
12219+
void ImGui::SetNavCursorVisibleAfterMove()
12220+
{
12221+
ImGuiContext& g = *GImGui;
12222+
g.NavCursorVisible = true;
12223+
g.NavHighlightItemUnderNav = g.NavMousePosDirty = true;
12224+
}
12225+
1221212226
void ImGui::SetNavWindow(ImGuiWindow* window)
1221312227
{
1221412228
ImGuiContext& g = *GImGui;
@@ -12735,13 +12749,6 @@ void ImGui::NavRestoreLayer(ImGuiNavLayer layer)
1273512749
}
1273612750
}
1273712751

12738-
void ImGui::NavRestoreHighlightAfterMove()
12739-
{
12740-
ImGuiContext& g = *GImGui;
12741-
g.NavCursorVisible = true;
12742-
g.NavHighlightItemUnderNav = g.NavMousePosDirty = true;
12743-
}
12744-
1274512752
static inline void ImGui::NavUpdateAnyRequestFlag()
1274612753
{
1274712754
ImGuiContext& g = *GImGui;
@@ -13050,7 +13057,7 @@ void ImGui::NavInitRequestApplyResult()
1305013057
if (result->SelectionUserData != ImGuiSelectionUserData_Invalid)
1305113058
g.NavLastValidSelectionUserData = result->SelectionUserData;
1305213059
if (g.NavInitRequestFromMove)
13053-
NavRestoreHighlightAfterMove();
13060+
SetNavCursorVisibleAfterMove();
1305413061
}
1305513062

1305613063
// Bias scoring rect ahead of scoring + update preferred pos (if missing) using source position
@@ -13243,9 +13250,9 @@ void ImGui::NavMoveRequestApplyResult()
1324313250
if (result == NULL)
1324413251
{
1324513252
if (g.NavMoveFlags & ImGuiNavMoveFlags_IsTabbing)
13246-
g.NavMoveFlags |= ImGuiNavMoveFlags_NoSetNavHighlight;
13247-
if (g.NavId != 0 && (g.NavMoveFlags & ImGuiNavMoveFlags_NoSetNavHighlight) == 0)
13248-
NavRestoreHighlightAfterMove();
13253+
g.NavMoveFlags |= ImGuiNavMoveFlags_NoSetNavCursorVisible;
13254+
if (g.NavId != 0 && (g.NavMoveFlags & ImGuiNavMoveFlags_NoSetNavCursorVisible) == 0)
13255+
SetNavCursorVisibleAfterMove();
1324913256
NavClearPreferredPosForAxis(axis); // On a failed move, clear preferred pos for this axis.
1325013257
IMGUI_DEBUG_LOG_NAV("[nav] NavMoveSubmitted but not led to a result!\n");
1325113258
return;
@@ -13330,9 +13337,9 @@ void ImGui::NavMoveRequestApplyResult()
1333013337
g.NavNextActivateFlags |= ImGuiActivateFlags_PreferInput | ImGuiActivateFlags_TryToPreserveState | ImGuiActivateFlags_FromTabbing;
1333113338
}
1333213339

13333-
// Enable nav highlight
13334-
if ((g.NavMoveFlags & ImGuiNavMoveFlags_NoSetNavHighlight) == 0)
13335-
NavRestoreHighlightAfterMove();
13340+
// Make nav cursor visible
13341+
if ((g.NavMoveFlags & ImGuiNavMoveFlags_NoSetNavCursorVisible) == 0)
13342+
SetNavCursorVisibleAfterMove();
1333613343
}
1333713344

1333813345
// Process Escape/NavCancel input (to close a popup, get back to parent, clear focus)
@@ -13356,7 +13363,7 @@ static void ImGui::NavUpdateCancelRequest()
1335613363
{
1335713364
// Leave the "menu" layer
1335813365
NavRestoreLayer(ImGuiNavLayer_Main);
13359-
NavRestoreHighlightAfterMove();
13366+
SetNavCursorVisibleAfterMove();
1336013367
}
1336113368
else if (g.NavWindow && g.NavWindow != g.NavWindow->RootWindow && !(g.NavWindow->RootWindowForNav->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->RootWindowForNav->ParentWindow)
1336213369
{
@@ -13366,7 +13373,7 @@ static void ImGui::NavUpdateCancelRequest()
1336613373
IM_ASSERT(child_window->ChildId != 0);
1336713374
FocusWindow(parent_window);
1336813375
SetNavID(child_window->ChildId, ImGuiNavLayer_Main, 0, WindowRectAbsToRel(parent_window, child_window->Rect()));
13369-
NavRestoreHighlightAfterMove();
13376+
SetNavCursorVisibleAfterMove();
1337013377
}
1337113378
else if (g.OpenPopupStack.Size > 0 && g.OpenPopupStack.back().Window != NULL && !(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal))
1337213379
{
@@ -13732,7 +13739,7 @@ static void ImGui::NavUpdateWindowing()
1373213739
if (apply_focus_window && (g.NavWindow == NULL || apply_focus_window != g.NavWindow->RootWindow))
1373313740
{
1373413741
ClearActiveID();
13735-
NavRestoreHighlightAfterMove();
13742+
SetNavCursorVisibleAfterMove();
1373613743
ClosePopupsOverWindow(apply_focus_window, false);
1373713744
FocusWindow(apply_focus_window, ImGuiFocusRequestFlags_RestoreFocusedChild);
1373813745
apply_focus_window = g.NavWindow;
@@ -13779,7 +13786,7 @@ static void ImGui::NavUpdateWindowing()
1377913786
if (new_nav_layer == ImGuiNavLayer_Menu)
1378013787
g.NavWindow->NavLastIds[new_nav_layer] = 0;
1378113788
NavRestoreLayer(new_nav_layer);
13782-
NavRestoreHighlightAfterMove();
13789+
SetNavCursorVisibleAfterMove();
1378313790
}
1378413791
}
1378513792
}

imgui.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,12 @@ namespace ImGui
900900
IMGUI_API void PopClipRect();
901901

902902
// Focus, Activation
903-
// - Prefer using "SetItemDefaultFocus()" over "if (IsWindowAppearing()) SetScrollHereY()" when applicable to signify "this is the default item"
904-
IMGUI_API void SetItemDefaultFocus(); // make last item the default focused item of a window.
903+
IMGUI_API void SetItemDefaultFocus(); // make last item the default focused item of of a newly appearing window.
905904
IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget. Use -1 to access previous widget.
906905

906+
// Keyboard/Gamepad Navigation
907+
IMGUI_API void SetNavCursorVisible(bool visible); // alter visibility of keyboard/gamepad cursor. by default: show when using an arrow key, hide when clicking with mouse.
908+
907909
// Overlapping mode
908910
IMGUI_API void SetNextItemAllowOverlap(); // allow next item to be overlapped by a subsequent item. Useful with invisible buttons, selectable, treenode covering an area where subsequent items may need to be added. Note that both Selectable() and TreeNode() have dedicated flags doing this.
909911

@@ -996,7 +998,7 @@ namespace ImGui
996998
// - Many related features are still in imgui_internal.h. For instance, most IsKeyXXX()/IsMouseXXX() functions have an owner-id-aware version.
997999
IMGUI_API void SetItemKeyOwner(ImGuiKey key); // Set key owner to last item ID if it is hovered or active. Equivalent to 'if (IsItemHovered() || IsItemActive()) { SetKeyOwner(key, GetItemID());'.
9981000

999-
// Inputs Utilities: Mouse specific
1001+
// Inputs Utilities: Mouse
10001002
// - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right.
10011003
// - You can also use regular integer: it is forever guaranteed that 0=Left, 1=Right, 2=Middle.
10021004
// - Dragging operations are only reported after mouse has moved a certain distance away from the initial clicking position (see 'lock_threshold' and 'io.MouseDraggingThreshold')
@@ -1676,7 +1678,7 @@ enum ImGuiCol_
16761678
ImGuiCol_TextLink, // Hyperlink color
16771679
ImGuiCol_TextSelectedBg,
16781680
ImGuiCol_DragDropTarget, // Rectangle highlighting a drop target
1679-
ImGuiCol_NavHighlight, // Gamepad/keyboard: current highlighted item
1681+
ImGuiCol_NavHighlight, // Color of gamepad/keyboard navigation cursor/rectangle, when visible
16801682
ImGuiCol_NavWindowingHighlight, // Highlight window when using CTRL+TAB
16811683
ImGuiCol_NavWindowingDimBg, // Darken/colorize entire screen behind the CTRL+TAB window list, when active
16821684
ImGuiCol_ModalWindowDimBg, // Darken/colorize entire screen behind a modal window, when one is active

imgui_internal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ enum ImGuiNavMoveFlags_
15781578
ImGuiNavMoveFlags_IsPageMove = 1 << 11, // Identify a PageDown/PageUp request.
15791579
ImGuiNavMoveFlags_Activate = 1 << 12, // Activate/select target item.
15801580
ImGuiNavMoveFlags_NoSelect = 1 << 13, // Don't trigger selection by not setting g.NavJustMovedTo
1581-
ImGuiNavMoveFlags_NoSetNavHighlight = 1 << 14, // Do not alter the visible state of keyboard vs mouse nav highlight
1581+
ImGuiNavMoveFlags_NoSetNavCursorVisible = 1 << 14, // Do not alter the nav cursor visible state
15821582
ImGuiNavMoveFlags_NoClearActiveId = 1 << 15, // (Experimental) Do not clear active id when applying move result
15831583
};
15841584

@@ -3114,7 +3114,7 @@ namespace ImGui
31143114
IMGUI_API void NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags);
31153115
IMGUI_API void NavHighlightActivated(ImGuiID id);
31163116
IMGUI_API void NavClearPreferredPosForAxis(ImGuiAxis axis);
3117-
IMGUI_API void NavRestoreHighlightAfterMove();
3117+
IMGUI_API void SetNavCursorVisibleAfterMove();
31183118
IMGUI_API void NavUpdateCurrentWindowIsScrollPushableX();
31193119
IMGUI_API void SetNavWindow(ImGuiWindow* window);
31203120
IMGUI_API void SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel);

imgui_widgets.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7200,7 +7200,7 @@ int ImGui::TypingSelectFindMatch(ImGuiTypingSelectRequest* req, int items_count,
72007200
else
72017201
idx = TypingSelectFindBestLeadingMatch(req, items_count, get_item_name_func, user_data);
72027202
if (idx != -1)
7203-
NavRestoreHighlightAfterMove();
7203+
SetNavCursorVisibleAfterMove();
72047204
return idx;
72057205
}
72067206

@@ -8883,7 +8883,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled)
88838883
{
88848884
want_open = want_open_nav_init = true;
88858885
NavMoveRequestCancel();
8886-
NavRestoreHighlightAfterMove();
8886+
SetNavCursorVisibleAfterMove();
88878887
}
88888888
}
88898889
else

0 commit comments

Comments
 (0)