MCPcopy Create free account
hub / github.com/RenderKit/embree / CloseButton

Method CloseButton

tutorials/common/imgui/imgui_widgets.cpp:808–844  ·  view source on GitHub ↗

Button to close a window

Source from the content-addressed store, hash-verified

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

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