Skip to content

Commit

Permalink
CollapseButton: handle clipping better + align circle like in docking…
Browse files Browse the repository at this point in the history
… branch.

Amend 6c3697f
  • Loading branch information
ocornut committed Aug 25, 2023
1 parent 040e818 commit b41811a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)
bb_interact.Expand(ImFloor(bb_interact.GetSize() * -0.25f));

// Tweak 2: We intentionally allow interaction when clipped so that a mechanical Alt,Right,Activate sequence can always close a window.
// (this isn't the regular behavior of buttons, but it doesn't affect the user much because navigation tends to keep items visible).
// (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).
bool is_clipped = !ItemAdd(bb_interact, id);

bool hovered, held;
Expand Down Expand Up @@ -839,15 +839,17 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos)
ImGuiWindow* window = g.CurrentWindow;

ImRect bb(pos, pos + ImVec2(g.FontSize, g.FontSize) + g.Style.FramePadding * 2.0f);
ItemAdd(bb, id);
bool is_clipped = !ItemAdd(bb, id);
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, ImGuiButtonFlags_None);
if (is_clipped)
return pressed;

// Render
ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
ImU32 text_col = GetColorU32(ImGuiCol_Text);
if (hovered || held)
window->DrawList->AddCircleFilled(bb.GetCenter()/*+ ImVec2(0.0f, -0.5f)*/, g.FontSize * 0.5f + 1.0f, bg_col);
window->DrawList->AddCircleFilled(bb.GetCenter() + ImVec2(0.0f, -0.5f), g.FontSize * 0.5f + 1.0f, bg_col);
RenderArrow(window->DrawList, bb.Min + g.Style.FramePadding, text_col, window->Collapsed ? ImGuiDir_Right : ImGuiDir_Down, 1.0f);

// Switch to moving the window after mouse is moved beyond the initial drag threshold
Expand Down

0 comments on commit b41811a

Please sign in to comment.