Skip to content

Commit c24b470

Browse files
committed
Set g.HoveredId when item is disabled. Prevents window from being dragged if mouse hovers a disabled item.
1 parent eefae08 commit c24b470

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

imgui.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,15 +3062,16 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id)
30623062
return false;
30633063
if (g.NavDisableMouseHover || !IsWindowContentHoverable(window, ImGuiHoveredFlags_None))
30643064
return false;
3065+
3066+
SetHoveredID(id);
3067+
30653068
if (window->DC.ItemFlags & ImGuiItemFlags_Disabled)
30663069
return false;
30673070

30683071
// We exceptionally allow this function to be called with id==0 to allow using it for easy high-level
30693072
// hover test in widgets code. We could also decide to split this function is two.
30703073
if (id != 0)
30713074
{
3072-
SetHoveredID(id);
3073-
30743075
// [DEBUG] Item Picker tool!
30753076
// We perform the check here because SetHoveredID() is not frequently called (1~ time a frame), making
30763077
// the cost of this tool near-zero. We can get slightly better call-stack and support picking non-hovered

imgui_widgets.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
463463
ImGuiContext& g = *GImGui;
464464
ImGuiWindow* window = GetCurrentWindow();
465465

466+
bool pressed = false;
467+
bool hovered = ItemHoverable(bb, id);
468+
466469
if (flags & ImGuiButtonFlags_Disabled)
467470
{
468471
if (out_hovered) *out_hovered = false;
@@ -489,9 +492,6 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
489492
IMGUI_TEST_ENGINE_ITEM_ADD(bb, id);
490493
#endif
491494

492-
bool pressed = false;
493-
bool hovered = ItemHoverable(bb, id);
494-
495495
// Drag source doesn't report as hovered
496496
if (hovered && g.DragDropActive && g.DragDropPayload.SourceId == id && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoDisableHover))
497497
hovered = false;
@@ -1365,7 +1365,7 @@ bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float
13651365
if (g.ActiveId != id)
13661366
SetItemAllowOverlap();
13671367

1368-
if (held || (g.HoveredId == id && g.HoveredIdPreviousFrame == id && g.HoveredIdTimer >= hover_visibility_delay))
1368+
if (held || (hovered && g.HoveredIdPreviousFrame == id && g.HoveredIdTimer >= hover_visibility_delay))
13691369
SetMouseCursor(axis == ImGuiAxis_Y ? ImGuiMouseCursor_ResizeNS : ImGuiMouseCursor_ResizeEW);
13701370

13711371
ImRect bb_render = bb;
@@ -2189,7 +2189,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data,
21892189
return TempInputScalar(frame_bb, id, label, data_type, p_data, format);// , p_min, p_max);
21902190

21912191
// Draw frame
2192-
const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
2192+
const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
21932193
RenderNavHighlight(frame_bb, id);
21942194
RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, style.FrameRounding);
21952195

@@ -2642,7 +2642,7 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat
26422642
return TempInputScalar(frame_bb, id, label, data_type, p_data, format);// , p_min, p_max);
26432643

26442644
// Draw frame
2645-
const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
2645+
const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
26462646
RenderNavHighlight(frame_bb, id);
26472647
RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, g.Style.FrameRounding);
26482648

@@ -2788,7 +2788,7 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d
27882788
}
27892789

27902790
// Draw frame
2791-
const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
2791+
const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
27922792
RenderNavHighlight(frame_bb, id);
27932793
RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, g.Style.FrameRounding);
27942794

@@ -6347,7 +6347,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
63476347
RenderArrow(window->DrawList, pos + ImVec2(window->DC.MenuColumns.Pos[2] + extra_w + g.FontSize * 0.30f, 0.0f), text_col, ImGuiDir_Right);
63486348
}
63496349

6350-
const bool hovered = enabled && ItemHoverable(window->DC.LastItemRect, id);
6350+
const bool hovered = ItemHoverable(window->DC.LastItemRect, id) && enabled;
63516351
if (menuset_is_open)
63526352
g.NavWindow = backed_nav_window;
63536353

@@ -7216,7 +7216,6 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
72167216
bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags);
72177217
if (pressed)
72187218
tab_bar->NextSelectedTabId = id;
7219-
hovered |= (g.HoveredId == id);
72207219

72217220
// Allow the close button to overlap unless we are dragging (in which case we don't want any overlapping tabs to be hovered)
72227221
if (!held)
@@ -7281,7 +7280,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
72817280

72827281
// Tooltip (FIXME: Won't work over the close button because ItemOverlap systems messes up with HoveredIdTimer)
72837282
// We test IsItemHovered() to discard e.g. when another item is active or drag and drop over the tab bar (which g.HoveredId ignores)
7284-
if (g.HoveredId == id && !held && g.HoveredIdNotActiveTimer > 0.50f && IsItemHovered())
7283+
if (hovered && !held && g.HoveredIdNotActiveTimer > 0.50f && IsItemHovered())
72857284
if (!(tab_bar->Flags & ImGuiTabBarFlags_NoTooltip) && !(tab->Flags & ImGuiTabItemFlags_NoTooltip))
72867285
SetTooltip("%.*s", (int)(FindRenderedTextEnd(label) - label), label);
72877286

0 commit comments

Comments
 (0)