Button to close a window
| 750 | |
| 751 | // Button to close a window |
| 752 | bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)//, float size) |
| 753 | { |
| 754 | ImGuiContext& g = *GImGui; |
| 755 | ImGuiWindow* window = g.CurrentWindow; |
| 756 | |
| 757 | // We intentionally allow interaction when clipped so that a mechanical Alt,Right,Validate sequence close a window. |
| 758 | // (this isn't the regular behavior of buttons, but it doesn't affect the user much because navigation tends to keep items visible). |
| 759 | const ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize) + g.Style.FramePadding * 2.0f); |
| 760 | bool is_clipped = !ItemAdd(bb, id); |
| 761 | |
| 762 | bool hovered, held; |
| 763 | bool pressed = ButtonBehavior(bb, id, &hovered, &held); |
| 764 | if (is_clipped) |
| 765 | return pressed; |
| 766 | |
| 767 | // Render |
| 768 | ImU32 col = GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered); |
| 769 | ImVec2 center = bb.GetCenter(); |
| 770 | if (hovered) |
| 771 | window->DrawList->AddCircleFilled(center, ImMax(2.0f, g.FontSize * 0.5f + 1.0f), col, 12); |
| 772 | |
| 773 | float cross_extent = g.FontSize * 0.5f * 0.7071f - 1.0f; |
| 774 | ImU32 cross_col = GetColorU32(ImGuiCol_Text); |
| 775 | center -= ImVec2(0.5f, 0.5f); |
| 776 | window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), cross_col, 1.0f); |
| 777 | window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), cross_col, 1.0f); |
| 778 | |
| 779 | return pressed; |
| 780 | } |
| 781 | |
| 782 | bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos) |
| 783 | { |
nothing calls this directly
no test coverage detected