mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-26 05:27:01 +00:00
CollapsingHeader(bool*) variant: fixed for IsItemHovered() to work properly in the nav branch.Basically the close button now has to use ItemAdd() to be navable into, which overwrite the IsItemHovered data. (#600, #787)
This commit is contained in:
parent
a126c702d9
commit
29a652adee
@ -7346,8 +7346,11 @@ bool ImGui::CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags
|
|||||||
// Create a small overlapping close button // FIXME: We can evolve this into user accessible helpers to add extra buttons on title bars, headers, etc.
|
// Create a small overlapping close button // FIXME: We can evolve this into user accessible helpers to add extra buttons on title bars, headers, etc.
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
float button_sz = g.FontSize * 0.5f;
|
float button_sz = g.FontSize * 0.5f;
|
||||||
|
ImGuiItemHoveredDataBackup last_item_backup;
|
||||||
|
last_item_backup.Backup();
|
||||||
if (CloseButton(window->GetID((void*)(intptr_t)(id+1)), ImVec2(ImMin(window->DC.LastItemRect.Max.x, window->ClipRect.Max.x) - g.Style.FramePadding.x - button_sz, window->DC.LastItemRect.Min.y + g.Style.FramePadding.y + button_sz), button_sz))
|
if (CloseButton(window->GetID((void*)(intptr_t)(id+1)), ImVec2(ImMin(window->DC.LastItemRect.Max.x, window->ClipRect.Max.x) - g.Style.FramePadding.x - button_sz, window->DC.LastItemRect.Min.y + g.Style.FramePadding.y + button_sz), button_sz))
|
||||||
*p_open = false;
|
*p_open = false;
|
||||||
|
last_item_backup.Restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_open;
|
return is_open;
|
||||||
|
@ -460,11 +460,13 @@ void ImGui::ShowTestWindow(bool* p_open)
|
|||||||
ImGui::Checkbox("Enable extra group", &closable_group);
|
ImGui::Checkbox("Enable extra group", &closable_group);
|
||||||
if (ImGui::CollapsingHeader("Header"))
|
if (ImGui::CollapsingHeader("Header"))
|
||||||
{
|
{
|
||||||
|
ImGui::Text("IsItemHovered: %d", IsItemHovered());
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
ImGui::Text("Some content %d", i);
|
ImGui::Text("Some content %d", i);
|
||||||
}
|
}
|
||||||
if (ImGui::CollapsingHeader("Header with a close button", &closable_group))
|
if (ImGui::CollapsingHeader("Header with a close button", &closable_group))
|
||||||
{
|
{
|
||||||
|
ImGui::Text("IsItemHovered: %d", IsItemHovered());
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
ImGui::Text("More content %d", i);
|
ImGui::Text("More content %d", i);
|
||||||
}
|
}
|
||||||
|
@ -848,6 +848,17 @@ public:
|
|||||||
ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); }
|
ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Backup and restore just enough data to be able to use IsItemHovered() on item A after another B in the same window has overwritten the data.
|
||||||
|
struct ImGuiItemHoveredDataBackup
|
||||||
|
{
|
||||||
|
ImGuiID LastItemId;
|
||||||
|
ImRect LastItemRect;
|
||||||
|
bool LastItemRectHoveredRect;
|
||||||
|
|
||||||
|
void Backup() { ImGuiWindow* window = GImGui->CurrentWindow; LastItemId = window->DC.LastItemId; LastItemRect = window->DC.LastItemRect; LastItemRectHoveredRect = window->DC.LastItemRectHoveredRect; }
|
||||||
|
void Restore() { ImGuiWindow* window = GImGui->CurrentWindow; window->DC.LastItemId = LastItemId; window->DC.LastItemRect = LastItemRect; window->DC.LastItemRectHoveredRect = LastItemRectHoveredRect; }
|
||||||
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Internal API
|
// Internal API
|
||||||
// No guarantee of forward compatibility here.
|
// No guarantee of forward compatibility here.
|
||||||
|
Loading…
Reference in New Issue
Block a user