MCPcopy Create free account
hub / github.com/Wemino/MarkerPatch / CloseButton

Method CloseButton

include/imgui/imgui_widgets.cpp:903–938  ·  view source on GitHub ↗

Button to close a window

Source from the content-addressed store, hash-verified

901
902// Button to close a window
903bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)
904{
905 ImGuiContext& g = *GImGui;
906 ImGuiWindow* window = g.CurrentWindow;
907
908 // 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)
909 // 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?
910 const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize));
911 ImRect bb_interact = bb;
912 const float area_to_visible_ratio = window->OuterRectClipped.GetArea() / bb.GetArea();
913 if (area_to_visible_ratio < 1.5f)
914 bb_interact.Expand(ImTrunc(bb_interact.GetSize() * -0.25f));
915
916 // Tweak 2: We intentionally allow interaction when clipped so that a mechanical Alt,Right,Activate sequence can always close a window.
917 // (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).
918 bool is_clipped = !ItemAdd(bb_interact, id);
919
920 bool hovered, held;
921 bool pressed = ButtonBehavior(bb_interact, id, &hovered, &held);
922 if (is_clipped)
923 return pressed;
924
925 // Render
926 ImU32 bg_col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered);
927 if (hovered)
928 window->DrawList->AddRectFilled(bb.Min, bb.Max, bg_col);
929 RenderNavCursor(bb, id, ImGuiNavRenderCursorFlags_Compact);
930 const ImU32 cross_col = GetColorU32(ImGuiCol_Text);
931 const ImVec2 cross_center = bb.GetCenter() - ImVec2(0.5f, 0.5f);
932 const float cross_extent = g.FontSize * 0.5f * 0.7071f - 1.0f;
933 const float cross_thickness = 1.0f * (float)(int)g.Style._MainScale; // FIXME-DPI
934 window->DrawList->AddLine(cross_center + ImVec2(+cross_extent, +cross_extent), cross_center + ImVec2(-cross_extent, -cross_extent), cross_col, cross_thickness);
935 window->DrawList->AddLine(cross_center + ImVec2(+cross_extent, -cross_extent), cross_center + ImVec2(-cross_extent, +cross_extent), cross_col, cross_thickness);
936
937 return pressed;
938}
939
940bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos)
941{

Callers

nothing calls this directly

Calls 5

ImVec2Function · 0.85
ImTruncFunction · 0.85
AddRectFilledMethod · 0.80
GetCenterMethod · 0.80
AddLineMethod · 0.80

Tested by

no test coverage detected