Skip to content

Commit 134fbe1

Browse files
committed
Windows: Fixed IsItemXXXX() functions not working on append-version of EndChild(). (ocornut#8350)
Also made some of the fields accessible after BeginChild() to match Begin() logic.
1 parent 5a28f18 commit 134fbe1

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Other changes:
6969
but in the meanwhile it works better now. (#2701, #8138, #1018)
7070
- Windows, Style: Fixed small rendering issues with menu bar, resize grip and
7171
scrollbar when using thick border sizes. (#8267, #7887)
72+
- Windows: Fixed IsItemXXXX() functions not working on append-version of EndChild(). (#8350)
73+
Also made some of the fields accessible after BeginChild() to match Begin() logic.
7274
- ColorEdit, ColorPicker: Fixed alpha preview broken in 1.91.7. (#8336, #8241). [@PathogenDavid]
7375
- Tabs, Style: reworked selected overline rendering to better accommodate
7476
for rounded tabs. Reduced default thickness (style.TabBarOverlineSize),

imgui.cpp

+22-6
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@ static void RenderWindowTitleBarContents(ImGuiWindow* window, const
12561256
static void RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32 col);
12571257
static void RenderDimmedBackgrounds();
12581258
static void SetLastItemDataForWindow(ImGuiWindow* window, const ImRect& rect);
1259+
static void SetLastItemDataForChildWindowItem(ImGuiWindow* window, const ImRect& rect);
12591260

12601261
// Viewports
12611262
const ImGuiID IMGUI_VIEWPORT_DEFAULT_ID = 0x11111111; // Using an arbitrary constant instead of e.g. ImHashStr("ViewportDefault", 0); so it's easier to spot in the debugger. The exact value doesn't matter.
@@ -4704,6 +4705,18 @@ void ImGui::SetLastItemData(ImGuiID item_id, ImGuiItemFlags item_flags, ImGuiIte
47044705
g.LastItemData.Rect = g.LastItemData.NavRect = item_rect;
47054706
}
47064707

4708+
static void ImGui::SetLastItemDataForWindow(ImGuiWindow* window, const ImRect& rect)
4709+
{
4710+
ImGuiContext& g = *GImGui;
4711+
SetLastItemData(window->MoveId, g.CurrentItemFlags, window->DC.WindowItemStatusFlags, rect);
4712+
}
4713+
4714+
static void ImGui::SetLastItemDataForChildWindowItem(ImGuiWindow* window, const ImRect& rect)
4715+
{
4716+
ImGuiContext& g = *GImGui;
4717+
SetLastItemData(window->ChildId, g.CurrentItemFlags, window->DC.WindowItemStatusFlags, rect);
4718+
}
4719+
47074720
float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
47084721
{
47094722
if (wrap_pos_x < 0.0f)
@@ -6157,7 +6170,14 @@ void ImGui::EndChild()
61576170
}
61586171
if (g.HoveredWindow == child_window)
61596172
g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredWindow;
6173+
child_window->DC.WindowItemStatusFlags = g.LastItemData.StatusFlags;
6174+
//SetLastItemDataForChildWindowItem(child_window, child_window->Rect()); // Not needed, effectively done by ItemAdd()
61606175
}
6176+
else
6177+
{
6178+
SetLastItemDataForChildWindowItem(child_window, child_window->Rect());
6179+
}
6180+
61616181
g.WithinEndChildID = backup_within_end_child_id;
61626182
g.LogLinePosY = -FLT_MAX; // To enforce a carriage return
61636183
}
@@ -7612,6 +7632,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
76127632

76137633
// We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin().
76147634
// This is useful to allow creating context menus on title bar only, etc.
7635+
window->DC.WindowItemStatusFlags = ImGuiItemStatusFlags_None;
7636+
window->DC.WindowItemStatusFlags |= IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0;
76157637
SetLastItemDataForWindow(window, title_bar_rect);
76167638

76177639
// [DEBUG]
@@ -7717,12 +7739,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
77177739
return !window->SkipItems;
77187740
}
77197741

7720-
static void ImGui::SetLastItemDataForWindow(ImGuiWindow* window, const ImRect& rect)
7721-
{
7722-
ImGuiContext& g = *GImGui;
7723-
SetLastItemData(window->MoveId, g.CurrentItemFlags, IsMouseHoveringRect(rect.Min, rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0, rect);
7724-
}
7725-
77267742
void ImGui::End()
77277743
{
77287744
ImGuiContext& g = *GImGui;

imgui_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,7 @@ struct IMGUI_API ImGuiWindowTempData
24562456
ImGuiLayoutType LayoutType;
24572457
ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin()
24582458
ImU32 ModalDimBgColor;
2459+
ImGuiItemStatusFlags WindowItemStatusFlags;
24592460

24602461
// Local parameters stacks
24612462
// We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings.

0 commit comments

Comments
 (0)