Skip to content

Commit d5d7050

Browse files
committed
Various comments
As it turns out, functions like IsItemHovered() won't work on an open BeginMenu() because LastItemData is overriden by BeginPopup(). Probably an easy fix.
1 parent e74a50f commit d5d7050

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

imgui.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3584,6 +3584,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
35843584
return false;
35853585
IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy)) == 0); // Flags not supported by this function
35863586

3587+
// Done with rectangle culling so we can perform heavier checks now
35873588
// Test if we are hovering the right window (our window could be behind another window)
35883589
// [2021/03/02] Reworked / reverted the revert, finally. Note we want e.g. BeginGroup/ItemAdd/EndGroup to work as well. (#3851)
35893590
// [2017/10/16] Reverted commit 344d48be3 and testing RootWindow instead. I believe it is correct to NOT test for RootWindow but this leaves us unable
@@ -3648,6 +3649,8 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id)
36483649
return false;
36493650
if (!IsMouseHoveringRect(bb.Min, bb.Max))
36503651
return false;
3652+
3653+
// Done with rectangle culling so we can perform heavier checks now.
36513654
if (!IsWindowContentHoverable(window, ImGuiHoveredFlags_None))
36523655
{
36533656
g.HoveredIdDisabled = true;

imgui_internal.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // E
149149
typedef int ImGuiActivateFlags; // -> enum ImGuiActivateFlags_ // Flags: for navigation/focus function (will be for ActivateItem() later)
150150
typedef int ImGuiDebugLogFlags; // -> enum ImGuiDebugLogFlags_ // Flags: for ShowDebugLogWindow(), g.DebugLogFlags
151151
typedef int ImGuiInputFlags; // -> enum ImGuiInputFlags_ // Flags: for IsKeyPressedEx()
152-
typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag()
153-
typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for DC.LastItemStatusFlags
152+
typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag(), g.LastItemData.InFlags
153+
typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for g.LastItemData.StatusFlags
154154
typedef int ImGuiOldColumnFlags; // -> enum ImGuiOldColumnFlags_ // Flags: for BeginColumns()
155155
typedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight()
156156
typedef int ImGuiNavMoveFlags; // -> enum ImGuiNavMoveFlags_ // Flags: for navigation requests
@@ -758,7 +758,10 @@ struct ImDrawDataBuilder
758758
// [SECTION] Widgets support: flags, enums, data structures
759759
//-----------------------------------------------------------------------------
760760

761-
// Transient per-window flags, reset at the beginning of the frame. For child window, inherited from parent on first Begin().
761+
// Flags used by upcoming items
762+
// - input: PushItemFlag() manipulates g.CurrentItemFlags, ItemAdd() calls may add extra flags.
763+
// - output: stored in g.LastItemData.InFlags
764+
// Current window shared by all windows.
762765
// This is going to be exposed in imgui.h when stabilized enough.
763766
enum ImGuiItemFlags_
764767
{
@@ -774,10 +777,11 @@ enum ImGuiItemFlags_
774777
ImGuiItemFlags_ReadOnly = 1 << 7, // false // [ALPHA] Allow hovering interactions but underlying value is not changed.
775778

776779
// Controlled by widget code
777-
ImGuiItemFlags_Inputable = 1 << 8, // false // [WIP] Auto-activate input mode when tab focused. Currently only used and supported by a few items before it becomes a generic feature.
780+
ImGuiItemFlags_Inputable = 1 << 10, // false // [WIP] Auto-activate input mode when tab focused. Currently only used and supported by a few items before it becomes a generic feature.
778781
};
779782

780-
// Storage for LastItem data
783+
// Status flags for an already submitted item
784+
// - output: stored in g.LastItemData.StatusFlags
781785
enum ImGuiItemStatusFlags_
782786
{
783787
ImGuiItemStatusFlags_None = 0,
@@ -2650,7 +2654,7 @@ namespace ImGui
26502654
IMGUI_API ImVec2 GetContentRegionMaxAbs();
26512655
IMGUI_API void ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_excess);
26522656

2653-
// Parameter stacks
2657+
// Parameter stacks (shared)
26542658
IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled);
26552659
IMGUI_API void PopItemFlag();
26562660

imgui_widgets.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -7018,6 +7018,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled)
70187018
ImVec2 label_size = CalcTextSize(label, NULL, true);
70197019

70207020
// Odd hack to allow hovering across menus of a same menu-set (otherwise we wouldn't be able to hover parent without always being a Child window)
7021+
// This is only done for items for the menu set and not the full parent window.
70217022
const bool menuset_is_open = IsRootOfOpenMenuSet();
70227023
ImGuiWindow* backed_nav_window = g.NavWindow;
70237024
if (menuset_is_open)
@@ -7156,9 +7157,10 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled)
71567157

71577158
if (menu_is_open)
71587159
{
7159-
SetNextWindowPos(popup_pos, ImGuiCond_Always); // Note: this is super misleading! The value will serve as reference for FindBestWindowPosForPopup(), not actual pos.
7160+
// FIXME: This technically breaks functions relying on LastItemData, somehow nobody complained yet. Should backup/restore LastItemData.
7161+
SetNextWindowPos(popup_pos, ImGuiCond_Always); // Note: misleading: the value will serve as reference for FindBestWindowPosForPopup(), not actual pos.
71607162
PushStyleVar(ImGuiStyleVar_ChildRounding, style.PopupRounding); // First level will use _PopupRounding, subsequent will use _ChildRounding
7161-
menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display)
7163+
menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display)
71627164
PopStyleVar();
71637165
}
71647166
else
@@ -7177,7 +7179,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
71777179
void ImGui::EndMenu()
71787180
{
71797181
// Nav: When a left move request _within our child menu_ failed, close ourselves (the _parent_ menu).
7180-
// A menu doesn't close itself because EndMenuBar() wants the catch the last Left<>Right inputs.
7182+
// A menu doesn't close itself because EndMenuBar() wants to catch the last Left<>Right inputs.
71817183
// However, it means that with the current code, a BeginMenu() from outside another menu or a menu-bar won't be closable with the Left direction.
71827184
// FIXME: This doesn't work if the parent BeginMenu() is not on a menu.
71837185
ImGuiContext& g = *GImGui;
@@ -7203,6 +7205,7 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut
72037205
ImVec2 pos = window->DC.CursorPos;
72047206
ImVec2 label_size = CalcTextSize(label, NULL, true);
72057207

7208+
// See BeginMenuEx() for comments about this.
72067209
const bool menuset_is_open = IsRootOfOpenMenuSet();
72077210
ImGuiWindow* backed_nav_window = g.NavWindow;
72087211
if (menuset_is_open)

0 commit comments

Comments
 (0)