MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / CloseButton

Method CloseButton

KBotExt/imgui/imgui_widgets.cpp:798–834  ·  view source on GitHub ↗

Button to close a window

Source from the content-addressed store, hash-verified

796
797// Button to close a window
798bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)
799{
800 ImGuiContext& g = *GImGui;
801 ImGuiWindow* window = g.CurrentWindow;
802
803 // 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)
804 // 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?
805 const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize));
806 ImRect bb_interact = bb;
807 const float area_to_visible_ratio = window->OuterRectClipped.GetArea() / bb.GetArea();
808 if (area_to_visible_ratio < 1.5f)
809 bb_interact.Expand(ImFloor(bb_interact.GetSize() * -0.25f));
810
811 // Tweak 2: We intentionally allow interaction when clipped so that a mechanical Alt,Right,Activate sequence can always close a window.
812 // (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).
813 bool is_clipped = !ItemAdd(bb_interact, id);
814
815 bool hovered, held;
816 bool pressed = ButtonBehavior(bb_interact, id, &hovered, &held);
817 if (is_clipped)
818 return pressed;
819
820 // Render
821 // FIXME: Clarify this mess
822 ImU32 col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered);
823 ImVec2 center = bb.GetCenter();
824 if (hovered)
825 window->DrawList->AddCircleFilled(center, ImMax(2.0f, g.FontSize * 0.5f + 1.0f), col);
826
827 float cross_extent = g.FontSize * 0.5f * 0.7071f - 1.0f;
828 ImU32 cross_col = GetColorU32(ImGuiCol_Text);
829 center -= ImVec2(0.5f, 0.5f);
830 window->DrawList->AddLine(center + ImVec2(+cross_extent, +cross_extent), center + ImVec2(-cross_extent, -cross_extent), cross_col, 1.0f);
831 window->DrawList->AddLine(center + ImVec2(+cross_extent, -cross_extent), center + ImVec2(-cross_extent, +cross_extent), cross_col, 1.0f);
832
833 return pressed;
834}
835
836bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos)
837{

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