1
0
mirror of https://github.com/ocornut/imgui.git synced 2025-02-02 12:37:20 +01:00

Windows: Fixed IsItemXXXX() functions not working on append-version of EndChild(). (#8350)

Also made some of the fields accessible after BeginChild() to match Begin() logic.
This commit is contained in:
ocornut 2025-01-27 12:39:44 +01:00
parent 5a28f188ff
commit 134fbe1245
3 changed files with 25 additions and 6 deletions

View File

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

View File

@ -1256,6 +1256,7 @@ static void RenderWindowTitleBarContents(ImGuiWindow* window, const
static void RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32 col); static void RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32 col);
static void RenderDimmedBackgrounds(); static void RenderDimmedBackgrounds();
static void SetLastItemDataForWindow(ImGuiWindow* window, const ImRect& rect); static void SetLastItemDataForWindow(ImGuiWindow* window, const ImRect& rect);
static void SetLastItemDataForChildWindowItem(ImGuiWindow* window, const ImRect& rect);
// Viewports // Viewports
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. 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
g.LastItemData.Rect = g.LastItemData.NavRect = item_rect; g.LastItemData.Rect = g.LastItemData.NavRect = item_rect;
} }
static void ImGui::SetLastItemDataForWindow(ImGuiWindow* window, const ImRect& rect)
{
ImGuiContext& g = *GImGui;
SetLastItemData(window->MoveId, g.CurrentItemFlags, window->DC.WindowItemStatusFlags, rect);
}
static void ImGui::SetLastItemDataForChildWindowItem(ImGuiWindow* window, const ImRect& rect)
{
ImGuiContext& g = *GImGui;
SetLastItemData(window->ChildId, g.CurrentItemFlags, window->DC.WindowItemStatusFlags, rect);
}
float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x) float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
{ {
if (wrap_pos_x < 0.0f) if (wrap_pos_x < 0.0f)
@ -6157,7 +6170,14 @@ void ImGui::EndChild()
} }
if (g.HoveredWindow == child_window) if (g.HoveredWindow == child_window)
g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredWindow; g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredWindow;
child_window->DC.WindowItemStatusFlags = g.LastItemData.StatusFlags;
//SetLastItemDataForChildWindowItem(child_window, child_window->Rect()); // Not needed, effectively done by ItemAdd()
} }
else
{
SetLastItemDataForChildWindowItem(child_window, child_window->Rect());
}
g.WithinEndChildID = backup_within_end_child_id; g.WithinEndChildID = backup_within_end_child_id;
g.LogLinePosY = -FLT_MAX; // To enforce a carriage return g.LogLinePosY = -FLT_MAX; // To enforce a carriage return
} }
@ -7612,6 +7632,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin(). // We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin().
// This is useful to allow creating context menus on title bar only, etc. // This is useful to allow creating context menus on title bar only, etc.
window->DC.WindowItemStatusFlags = ImGuiItemStatusFlags_None;
window->DC.WindowItemStatusFlags |= IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0;
SetLastItemDataForWindow(window, title_bar_rect); SetLastItemDataForWindow(window, title_bar_rect);
// [DEBUG] // [DEBUG]
@ -7717,12 +7739,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
return !window->SkipItems; return !window->SkipItems;
} }
static void ImGui::SetLastItemDataForWindow(ImGuiWindow* window, const ImRect& rect)
{
ImGuiContext& g = *GImGui;
SetLastItemData(window->MoveId, g.CurrentItemFlags, IsMouseHoveringRect(rect.Min, rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0, rect);
}
void ImGui::End() void ImGui::End()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;

View File

@ -2456,6 +2456,7 @@ struct IMGUI_API ImGuiWindowTempData
ImGuiLayoutType LayoutType; ImGuiLayoutType LayoutType;
ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin() ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin()
ImU32 ModalDimBgColor; ImU32 ModalDimBgColor;
ImGuiItemStatusFlags WindowItemStatusFlags;
// Local parameters stacks // Local parameters stacks
// 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. // 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.