Skip to content

Commit 23b655f

Browse files
committed
Internals: (Breaking) changed g.NavDisableHighlight to g.NavCursorVisible : same logic but inverted value. (#1074, #2048, #7237, #8059, #1712, #7370, #787)
1 parent 7a56b41 commit 23b655f

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

imgui.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -3701,7 +3701,7 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl
37013701
ImGuiContext& g = *GImGui;
37023702
if (id != g.NavId)
37033703
return;
3704-
if (g.NavDisableHighlight && !(flags & ImGuiNavHighlightFlags_AlwaysDraw))
3704+
if (!g.NavCursorVisible && !(flags & ImGuiNavHighlightFlags_AlwaysDraw))
37053705
return;
37063706
if (id == g.LastItemData.ID && (g.LastItemData.ItemFlags & ImGuiItemFlags_NoNav))
37073707
return;
@@ -3910,7 +3910,7 @@ ImGuiContext::ImGuiContext(ImFontAtlas* shared_font_atlas)
39103910
NavLastValidSelectionUserData = ImGuiSelectionUserData_Invalid;
39113911
NavIdIsAlive = false;
39123912
NavMousePosDirty = false;
3913-
NavDisableHighlight = true;
3913+
NavCursorVisible = false;
39143914
NavDisableMouseHover = false;
39153915

39163916
NavAnyRequest = false;
@@ -4444,7 +4444,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
44444444
ImGuiWindow* window = g.CurrentWindow;
44454445
IM_ASSERT_USER_ERROR((flags & ~ImGuiHoveredFlags_AllowedMaskForIsItemHovered) == 0, "Invalid flags for IsItemHovered()!");
44464446

4447-
if (g.NavDisableMouseHover && !g.NavDisableHighlight && !(flags & ImGuiHoveredFlags_NoNavOverride))
4447+
if (g.NavDisableMouseHover && g.NavCursorVisible && !(flags & ImGuiHoveredFlags_NoNavOverride))
44484448
{
44494449
if (!IsItemFocused())
44504450
return false;
@@ -4824,7 +4824,7 @@ void ImGui::StartMouseMovingWindow(ImGuiWindow* window)
48244824
ImGuiContext& g = *GImGui;
48254825
FocusWindow(window);
48264826
SetActiveID(window->MoveId, window);
4827-
g.NavDisableHighlight = true;
4827+
g.NavCursorVisible = false;
48284828
g.ActiveIdClickOffset = g.IO.MouseClickedPos[0] - window->RootWindow->Pos;
48294829
g.ActiveIdNoClearOnFocusLoss = true;
48304830
SetActiveIdUsingAllKeyboardKeys();
@@ -5835,7 +5835,7 @@ bool ImGui::IsAnyItemActive()
58355835
bool ImGui::IsAnyItemFocused()
58365836
{
58375837
ImGuiContext& g = *GImGui;
5838-
return g.NavId != 0 && !g.NavDisableHighlight;
5838+
return g.NavId != 0 && g.NavCursorVisible;
58395839
}
58405840

58415841
bool ImGui::IsItemVisible()
@@ -6689,7 +6689,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar
66896689
// Title bar only
66906690
const float backup_border_size = style.FrameBorderSize;
66916691
g.Style.FrameBorderSize = window->WindowBorderSize;
6692-
ImU32 title_bar_col = GetColorU32((title_bar_is_highlight && !g.NavDisableHighlight) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBgCollapsed);
6692+
ImU32 title_bar_col = GetColorU32((title_bar_is_highlight && g.NavCursorVisible) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBgCollapsed);
66936693
RenderFrame(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, true, window_rounding);
66946694
g.Style.FrameBorderSize = backup_border_size;
66956695
}
@@ -12189,7 +12189,7 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
1218912189

1219012190
ImVec2 tooltip_pos = ref_pos + TOOLTIP_DEFAULT_OFFSET_MOUSE * scale;
1219112191
ImRect r_avoid;
12192-
if (!g.NavDisableHighlight && g.NavDisableMouseHover && !g.IO.ConfigNavMoveSetMousePos)
12192+
if (g.NavCursorVisible && g.NavDisableMouseHover && !g.IO.ConfigNavMoveSetMousePos)
1219312193
r_avoid = ImRect(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 16, ref_pos.y + 8);
1219412194
else
1219512195
r_avoid = ImRect(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 24 * scale, ref_pos.y + 24 * scale); // FIXME: Hard-coded based on mouse cursor shape expectation. Exact dimension not very important.
@@ -12272,7 +12272,7 @@ void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window)
1227212272
if (g.ActiveIdSource == ImGuiInputSource_Keyboard || g.ActiveIdSource == ImGuiInputSource_Gamepad)
1227312273
g.NavDisableMouseHover = true;
1227412274
else
12275-
g.NavDisableHighlight = true;
12275+
g.NavCursorVisible = false;
1227612276

1227712277
// Clear preferred scoring position (NavMoveRequestApplyResult() will tend to restore it)
1227812278
NavClearPreferredPosForAxis(ImGuiAxis_X);
@@ -12738,7 +12738,7 @@ void ImGui::NavRestoreLayer(ImGuiNavLayer layer)
1273812738
void ImGui::NavRestoreHighlightAfterMove()
1273912739
{
1274012740
ImGuiContext& g = *GImGui;
12741-
g.NavDisableHighlight = false;
12741+
g.NavCursorVisible = true;
1274212742
g.NavDisableMouseHover = g.NavMousePosDirty = true;
1274312743
}
1274412744

@@ -12789,7 +12789,7 @@ static ImGuiInputSource ImGui::NavCalcPreferredRefPosSource()
1278912789
const bool activated_shortcut = g.ActiveId != 0 && g.ActiveIdFromShortcut && g.ActiveId == g.LastItemData.ID;
1279012790

1279112791
// Testing for !activated_shortcut here could in theory be removed if we decided that activating a remote shortcut altered one of the g.NavDisableXXX flag.
12792-
if ((g.NavDisableHighlight || !g.NavDisableMouseHover || !window) && !activated_shortcut)
12792+
if ((!g.NavCursorVisible || !g.NavDisableMouseHover || !window) && !activated_shortcut)
1279312793
return ImGuiInputSource_Mouse;
1279412794
else
1279512795
return ImGuiInputSource_Keyboard; // or Nav in general
@@ -12897,7 +12897,7 @@ static void ImGui::NavUpdate()
1289712897
// Schedule mouse position update (will be done at the bottom of this function, after 1) processing all move requests and 2) updating scrolling)
1289812898
bool set_mouse_pos = false;
1289912899
if (g.NavMousePosDirty && g.NavIdIsAlive)
12900-
if (!g.NavDisableHighlight && g.NavDisableMouseHover && g.NavWindow)
12900+
if (g.NavCursorVisible && g.NavDisableMouseHover && g.NavWindow)
1290112901
set_mouse_pos = true;
1290212902
g.NavMousePosDirty = false;
1290312903
IM_ASSERT(g.NavLayer == ImGuiNavLayer_Main || g.NavLayer == ImGuiNavLayer_Menu);
@@ -12913,15 +12913,15 @@ static void ImGui::NavUpdate()
1291312913

1291412914
// Set output flags for user application
1291512915
io.NavActive = (nav_keyboard_active || nav_gamepad_active) && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs);
12916-
io.NavVisible = (io.NavActive && g.NavId != 0 && !g.NavDisableHighlight) || (g.NavWindowingTarget != NULL);
12916+
io.NavVisible = (io.NavActive && g.NavId != 0 && g.NavCursorVisible) || (g.NavWindowingTarget != NULL);
1291712917

1291812918
// Process NavCancel input (to close a popup, get back to parent, clear focus)
1291912919
NavUpdateCancelRequest();
1292012920

1292112921
// Process manual activation request
1292212922
g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = 0;
1292312923
g.NavActivateFlags = ImGuiActivateFlags_None;
12924-
if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
12924+
if (g.NavId != 0 && g.NavCursorVisible && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
1292512925
{
1292612926
const bool activate_down = (nav_keyboard_active && IsKeyDown(ImGuiKey_Space, ImGuiKeyOwner_NoOwner)) || (nav_gamepad_active && IsKeyDown(ImGuiKey_NavGamepadActivate, ImGuiKeyOwner_NoOwner));
1292712927
const bool activate_pressed = activate_down && ((nav_keyboard_active && IsKeyPressed(ImGuiKey_Space, 0, ImGuiKeyOwner_NoOwner)) || (nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadActivate, 0, ImGuiKeyOwner_NoOwner)));
@@ -12946,7 +12946,7 @@ static void ImGui::NavUpdate()
1294612946
}
1294712947
}
1294812948
if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
12949-
g.NavDisableHighlight = true;
12949+
g.NavCursorVisible = false;
1295012950
if (g.NavActivateId != 0)
1295112951
IM_ASSERT(g.NavActivateDownId == g.NavActivateId);
1295212952

@@ -13003,7 +13003,7 @@ static void ImGui::NavUpdate()
1300313003
// Always prioritize mouse highlight if navigation is disabled
1300413004
if (!nav_keyboard_active && !nav_gamepad_active)
1300513005
{
13006-
g.NavDisableHighlight = true;
13006+
g.NavCursorVisible = false;
1300713007
g.NavDisableMouseHover = set_mouse_pos = false;
1300813008
}
1300913009

@@ -13147,7 +13147,7 @@ void ImGui::NavUpdateCreateMoveRequest()
1314713147
IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: from move, window \"%s\", layer=%d\n", window ? window->Name : "<NULL>", g.NavLayer);
1314813148
g.NavInitRequest = g.NavInitRequestFromMove = true;
1314913149
g.NavInitResult.ID = 0;
13150-
g.NavDisableHighlight = false;
13150+
g.NavCursorVisible = true;
1315113151
}
1315213152

1315313153
// When using gamepad, we project the reference nav bounding box into window visible area.
@@ -13211,7 +13211,7 @@ void ImGui::NavUpdateCreateTabbingRequest()
1321113211
// See NavProcessItemForTabbingRequest() for a description of the various forward/backward tabbing cases with and without wrapping.
1321213212
const bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
1321313213
if (nav_keyboard_active)
13214-
g.NavTabbingDir = g.IO.KeyShift ? -1 : (g.NavDisableHighlight == true && g.ActiveId == 0) ? 0 : +1;
13214+
g.NavTabbingDir = g.IO.KeyShift ? -1 : (g.NavCursorVisible == false && g.ActiveId == 0) ? 0 : +1;
1321513215
else
1321613216
g.NavTabbingDir = g.IO.KeyShift ? -1 : (g.ActiveId == 0) ? 0 : +1;
1321713217
ImGuiNavMoveFlags move_flags = ImGuiNavMoveFlags_IsTabbing | ImGuiNavMoveFlags_Activate;
@@ -15823,7 +15823,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1582315823
Text("NavActive: %d, NavVisible: %d", g.IO.NavActive, g.IO.NavVisible);
1582415824
Text("NavActivateId/DownId/PressedId: %08X/%08X/%08X", g.NavActivateId, g.NavActivateDownId, g.NavActivatePressedId);
1582515825
Text("NavActivateFlags: %04X", g.NavActivateFlags);
15826-
Text("NavDisableHighlight: %d, NavDisableMouseHover: %d", g.NavDisableHighlight, g.NavDisableMouseHover);
15826+
Text("NavCursorVisible: %d, NavDisableMouseHover: %d", g.NavCursorVisible, g.NavDisableMouseHover);
1582715827
Text("NavFocusScopeId = 0x%08X", g.NavFocusScopeId);
1582815828
Text("NavFocusRoute[] = ");
1582915829
for (int path_n = g.NavFocusRoute.Size - 1; path_n >= 0; path_n--)

imgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Library Version
3030
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
3131
#define IMGUI_VERSION "1.91.4 WIP"
32-
#define IMGUI_VERSION_NUM 19135
32+
#define IMGUI_VERSION_NUM 19136
3333
#define IMGUI_HAS_TABLE
3434

3535
/*

imgui_internal.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,8 @@ struct ImGuiContext
21442144
ImGuiSelectionUserData NavLastValidSelectionUserData; // Last valid data passed to SetNextItemSelectionUser(), or -1. For current window. Not reset when focusing an item that doesn't have selection data.
21452145
bool NavIdIsAlive; // Nav widget has been seen this frame ~~ NavRectRel is valid
21462146
bool NavMousePosDirty; // When set we will update mouse position if io.ConfigNavMoveSetMousePos is set (not enabled by default)
2147-
bool NavDisableHighlight; // When user starts using mouse, we hide gamepad/keyboard highlight (NB: but they are still available, which is why NavDisableHighlight isn't always != NavDisableMouseHover)
2147+
bool NavCursorVisible; // Nav focus rectangle is visible? We hide it after a mouse click. We show it after a nav move.
2148+
//bool NavDisableHighlight; // Before 1.91.4 (2024/10/18) we used g.NavDisableHighlight. g.NavCursorVisible is the new variable name, with opposite value (g.NavDisableHighlight = !g.NavCursorVisible)
21482149
bool NavDisableMouseHover; // When user starts using gamepad/keyboard, we hide mouse hovering highlight until mouse is touched again.
21492150

21502151
// Navigation: Init & Move Requests

imgui_widgets.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,12 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
620620
}
621621

622622
if (pressed)
623-
g.NavDisableHighlight = true;
623+
g.NavCursorVisible = false;
624624
}
625625

626626
// Gamepad/Keyboard handling
627627
// We report navigated and navigation-activated items as hovered but we don't set g.HoveredId to not interfere with mouse.
628-
if (g.NavId == id && !g.NavDisableHighlight && g.NavDisableMouseHover)
628+
if (g.NavId == id && g.NavCursorVisible && g.NavDisableMouseHover)
629629
if (!(flags & ImGuiButtonFlags_NoHoveredOnFocus))
630630
hovered = true;
631631
if (g.NavActivateDownId == id)
@@ -689,7 +689,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
689689
ClearActiveID();
690690
}
691691
if (!(flags & ImGuiButtonFlags_NoNavFocus))
692-
g.NavDisableHighlight = true;
692+
g.NavCursorVisible = false;
693693
}
694694
else if (g.ActiveIdSource == ImGuiInputSource_Keyboard || g.ActiveIdSource == ImGuiInputSource_Gamepad)
695695
{
@@ -7001,7 +7001,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
70017001
if (!g.NavDisableMouseHover && g.NavWindow == window && g.NavLayer == window->DC.NavLayerCurrent)
70027002
{
70037003
SetNavID(id, window->DC.NavLayerCurrent, g.CurrentFocusScopeId, WindowRectAbsToRel(window, bb)); // (bb == NavRect)
7004-
g.NavDisableHighlight = true;
7004+
g.NavCursorVisible = false;
70057005
}
70067006
}
70077007
if (pressed)
@@ -8624,7 +8624,7 @@ void ImGui::EndMenuBar()
86248624
IM_ASSERT(window->DC.NavLayersActiveMaskNext & (1 << layer)); // Sanity check (FIXME: Seems unnecessary)
86258625
FocusWindow(window);
86268626
SetNavID(window->NavLastIds[layer], layer, 0, window->NavRectRel[layer]);
8627-
g.NavDisableHighlight = true; // Hide highlight for the current frame so we don't see the intermediary selection.
8627+
g.NavCursorVisible = false; // Hide nav cursor for the current frame so we don't see the intermediary selection.
86288628
g.NavDisableMouseHover = g.NavMousePosDirty = true;
86298629
NavMoveRequestForward(g.NavMoveDir, g.NavMoveClipDir, g.NavMoveFlags, g.NavMoveScrollFlags); // Repeat
86308630
}

0 commit comments

Comments
 (0)