MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / CloseButton

Method CloseButton

extern/imgui/imgui_widgets.cpp:807–843  ·  view source on GitHub ↗

Button to close a window

Source from the content-addressed store, hash-verified

805
806// Button to close a window
807bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)
808{
809 ImGuiContext& g = *GImGui;
810 ImGuiWindow* window = g.CurrentWindow;
811
812 // 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)
813 // 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?
814 const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize) + g.Style.FramePadding * 2.0f);
815 ImRect bb_interact = bb;
816 const float area_to_visible_ratio = window->OuterRectClipped.GetArea() / bb.GetArea();
817 if (area_to_visible_ratio < 1.5f)
818 bb_interact.Expand(ImFloor(bb_interact.GetSize() * -0.25f));
819
820 // Tweak 2: We intentionally allow interaction when clipped so that a mechanical Alt,Right,Activate sequence can always close a window.
821 // (this isn't the regular behavior of buttons, but it doesn't affect the user much because navigation tends to keep items visible).
822 bool is_clipped = !ItemAdd(bb_interact, id);
823
824 bool hovered, held;
825 bool pressed = ButtonBehavior(bb_interact, id, &hovered, &held);
826 if (is_clipped)
827 return pressed;
828
829 // Render
830 // FIXME: Clarify this mess
831 ImU32 col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered);
832 ImVec2 center = bb.GetCenter();
833 if (hovered)
834 window->DrawList->AddCircleFilled(center, ImMax(2.0f, g.FontSize * 0.5f + 1.0f), col, 12);
835
836 float cross_extent = g.FontSize * 0.5f * 0.7071f - 1.0f;
837 ImU32 cross_col = GetColorU32(ImGuiCol_Text);
838 center -= ImVec2(0.5f, 0.5f);
839 window->DrawList->AddLine(center + ImVec2(+cross_extent, +cross_extent), center + ImVec2(-cross_extent, -cross_extent), cross_col, 1.0f);
840 window->DrawList->AddLine(center + ImVec2(+cross_extent, -cross_extent), center + ImVec2(-cross_extent, +cross_extent), cross_col, 1.0f);
841
842 return pressed;
843}
844
845// The Collapse button also functions as a Dock Menu button.
846bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos, ImGuiDockNode* dock_node)

Callers

nothing calls this directly

Calls 7

ImVec2Function · 0.85
ImFloorFunction · 0.85
ImMaxFunction · 0.85
GetSizeMethod · 0.80
GetCenterMethod · 0.80
AddCircleFilledMethod · 0.80
AddLineMethod · 0.80

Tested by

no test coverage detected