Skip to content

Commit

Permalink
Collapsed windows run initial auto-fit to resize the title bar #175
Browse files Browse the repository at this point in the history
Maybe have side-effects on window contents? Unsure at this point.
  • Loading branch information
ocornut committed Mar 22, 2015
1 parent ed94edf commit 7e8f1f1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions imgui.cpp
Expand Up @@ -3081,9 +3081,29 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg
window->Collapsed = false;
}

// Calculate auto-fit size
ImVec2 size_auto_fit;
if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
{
// Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose.
size_auto_fit = window->SizeContents + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
}
else
{
size_auto_fit = ImClamp(window->SizeContents + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
}

const float window_rounding = (window->Flags & ImGuiWindowFlags_ChildWindow) ? style.ChildWindowRounding : style.WindowRounding;
if (window->Collapsed)
{
// We still process initial auto-fit on collapsed windows to get a window width
// But otherwise we don't honor ImGuiWindowFlags_AlwaysAutoResize when collapsed.
if (window->AutoFitFrames > 0)
{
window->SizeFull = window->AutoFitOnlyGrows ? ImMax(window->SizeFull, size_auto_fit) : size_auto_fit;
title_bar_rect = window->TitleBarRect();
}

// Draw title bar only
window->Size = title_bar_rect.GetSize();
window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), window_rounding);
Expand All @@ -3098,13 +3118,10 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg
ImU32 resize_col = 0;
if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
{
// Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose.
const ImVec2 size_auto_fit = window->SizeContents + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
window->Size = window->SizeFull = size_auto_fit;
}
else
{
const ImVec2 size_auto_fit = ImClamp(window->SizeContents + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
{
// Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
Expand All @@ -3113,10 +3130,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg
else if (window->AutoFitFrames > 0)
{
// Auto-fit only grows during the first few frames
if (window->AutoFitOnlyGrows)
window->SizeFull = ImMax(window->SizeFull, size_auto_fit);
else
window->SizeFull = size_auto_fit;
window->SizeFull = window->AutoFitOnlyGrows ? ImMax(window->SizeFull, size_auto_fit) : size_auto_fit;
if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
MarkSettingsDirty();
}
Expand Down Expand Up @@ -3299,7 +3313,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg
window->Visible = false;

// Return false if we don't intend to display anything to allow user to perform an early out optimization
window->SkipItems = window->Collapsed || (!window->Visible && window->AutoFitFrames == 0);
window->SkipItems = (window->Collapsed || !window->Visible) && window->AutoFitFrames == 0;
return !window->SkipItems;
}

Expand Down

0 comments on commit 7e8f1f1

Please sign in to comment.