mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-20 01:34:20 +00:00
Add minimize/maximize window flags
TODO: actual work of rendering window
This commit is contained in:
parent
a2366f9022
commit
dd15544751
4 changed files with 143 additions and 0 deletions
|
|
@ -863,6 +863,78 @@ bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)
|
|||
return pressed;
|
||||
}
|
||||
|
||||
// Button to close a window
|
||||
bool ImGui::MinimizeButton(ImGuiID id, const ImVec2& pos, bool minimized)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
|
||||
// Tweak 1: Shrink hit-testing area if button covers an abnormally large proportion of the visible region. That's in order to facilitate moving the window away. (#3825)
|
||||
// This may better be applied as a general hit-rect reduction mechanism for all widgets to ensure the area to move window is always accessible?
|
||||
const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize));
|
||||
ImRect bb_interact = bb;
|
||||
const float area_to_visible_ratio = window->OuterRectClipped.GetArea() / bb.GetArea();
|
||||
if (area_to_visible_ratio < 1.5f)
|
||||
bb_interact.Expand(ImTrunc(bb_interact.GetSize() * -0.25f));
|
||||
|
||||
// Tweak 2: We intentionally allow interaction when clipped so that a mechanical Alt,Right,Activate sequence can always close a window.
|
||||
// (this isn't the common behavior of buttons, but it doesn't affect the user because navigation tends to keep items visible in scrolling layer).
|
||||
bool is_clipped = !ItemAdd(bb_interact, id);
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb_interact, id, &hovered, &held);
|
||||
if (is_clipped)
|
||||
return pressed;
|
||||
|
||||
// Render
|
||||
ImU32 bg_col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered);
|
||||
if (hovered)
|
||||
window->DrawList->AddRectFilled(bb.Min, bb.Max, bg_col);
|
||||
RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_Compact);
|
||||
ImU32 cross_col = GetColorU32(ImGuiCol_Text);
|
||||
ImVec2 cross_center = bb.GetCenter() - ImVec2(0.5f, 0.5f);
|
||||
float cross_extent = g.FontSize * 0.5f * 0.7071f - 1.0f;
|
||||
window->DrawList->AddLine(cross_center + ImVec2(+cross_extent, 0.0f), cross_center + ImVec2(-cross_extent, 0.0f), cross_col, 1.0f);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
// Button to close a window
|
||||
bool ImGui::MaximizeButton(ImGuiID id, const ImVec2& pos, bool maximized)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
|
||||
// Tweak 1: Shrink hit-testing area if button covers an abnormally large proportion of the visible region. That's in order to facilitate moving the window away. (#3825)
|
||||
// This may better be applied as a general hit-rect reduction mechanism for all widgets to ensure the area to move window is always accessible?
|
||||
const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize));
|
||||
ImRect bb_interact = bb;
|
||||
const float area_to_visible_ratio = window->OuterRectClipped.GetArea() / bb.GetArea();
|
||||
if (area_to_visible_ratio < 1.5f)
|
||||
bb_interact.Expand(ImTrunc(bb_interact.GetSize() * -0.25f));
|
||||
|
||||
// Tweak 2: We intentionally allow interaction when clipped so that a mechanical Alt,Right,Activate sequence can always close a window.
|
||||
// (this isn't the common behavior of buttons, but it doesn't affect the user because navigation tends to keep items visible in scrolling layer).
|
||||
bool is_clipped = !ItemAdd(bb_interact, id);
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ButtonBehavior(bb_interact, id, &hovered, &held);
|
||||
if (is_clipped)
|
||||
return pressed;
|
||||
|
||||
// Render
|
||||
ImU32 bg_col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered);
|
||||
if (hovered)
|
||||
window->DrawList->AddRectFilled(bb.Min, bb.Max, bg_col);
|
||||
RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_Compact);
|
||||
ImU32 cross_col = GetColorU32(ImGuiCol_Text);
|
||||
ImVec2 cross_center = bb.GetCenter() - ImVec2(0.5f, 0.5f);
|
||||
float cross_extent = g.FontSize * 0.5f * 0.7071f - 1.0f;
|
||||
window->DrawList->AddRect(cross_center + ImVec2(-cross_extent, -cross_extent), cross_center + ImVec2( + cross_extent, + cross_extent), cross_col, 0.0f, 0, 1.0f);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue