Skip to content

Commit 6af92b0

Browse files
committed
Internals: Layout: maintain two content sizes, optionally writing to IdealMaxPos to distinguish used from ideal size, later is used for auto-fit. Unused in this commit, should be no-op. (ocornut#3414)
# Conflicts: # imgui.cpp
1 parent 6470681 commit 6af92b0

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

imgui.cpp

+31-21
Original file line numberDiff line numberDiff line change
@@ -5048,18 +5048,24 @@ static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size
50485048
return new_size;
50495049
}
50505050

5051-
static ImVec2 CalcWindowContentSize(ImGuiWindow* window)
5051+
static void CalcWindowContentSizes(ImGuiWindow* window, ImVec2* content_size_current, ImVec2* content_size_ideal)
50525052
{
5053-
if (window->Collapsed)
5054-
if (window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
5055-
return window->ContentSize;
5056-
if (window->Hidden && window->HiddenFramesCannotSkipItems == 0 && window->HiddenFramesCanSkipItems > 0)
5057-
return window->ContentSize;
5053+
bool preserve_old_content_sizes = false;
5054+
if (window->Collapsed && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
5055+
preserve_old_content_sizes = true;
5056+
else if (window->Hidden && window->HiddenFramesCannotSkipItems == 0 && window->HiddenFramesCanSkipItems > 0)
5057+
preserve_old_content_sizes = true;
5058+
if (preserve_old_content_sizes)
5059+
{
5060+
*content_size_current = window->ContentSize;
5061+
*content_size_ideal = window->ContentSizeIdeal;
5062+
return;
5063+
}
50585064

5059-
ImVec2 sz;
5060-
sz.x = IM_FLOOR((window->ContentSizeExplicit.x != 0.0f) ? window->ContentSizeExplicit.x : window->DC.CursorMaxPos.x - window->DC.CursorStartPos.x);
5061-
sz.y = IM_FLOOR((window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : window->DC.CursorMaxPos.y - window->DC.CursorStartPos.y);
5062-
return sz;
5065+
content_size_current->x = (window->ContentSizeExplicit.x != 0.0f) ? window->ContentSizeExplicit.x : IM_FLOOR(window->DC.CursorMaxPos.x - window->DC.CursorStartPos.x);
5066+
content_size_current->y = (window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : IM_FLOOR(window->DC.CursorMaxPos.y - window->DC.CursorStartPos.y);
5067+
content_size_ideal->x = (window->ContentSizeExplicit.x != 0.0f) ? window->ContentSizeExplicit.x : IM_FLOOR(ImMax(window->DC.CursorMaxPos.x, window->DC.IdealMaxPos.x) - window->DC.CursorStartPos.x);
5068+
content_size_ideal->y = (window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : IM_FLOOR(ImMax(window->DC.CursorMaxPos.y, window->DC.IdealMaxPos.y) - window->DC.CursorStartPos.y);
50635069
}
50645070

50655071
static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
@@ -5097,10 +5103,12 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont
50975103
}
50985104
}
50995105

5100-
ImVec2 ImGui::CalcWindowExpectedSize(ImGuiWindow* window)
5106+
ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window)
51015107
{
5102-
ImVec2 size_contents = CalcWindowContentSize(window);
5103-
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, size_contents);
5108+
ImVec2 size_contents_current;
5109+
ImVec2 size_contents_ideal;
5110+
CalcWindowContentSizes(window, &size_contents_current, &size_contents_ideal);
5111+
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, size_contents_ideal);
51045112
ImVec2 size_final = CalcWindowSizeAfterConstraint(window, size_auto_fit);
51055113
return size_final;
51065114
}
@@ -5697,7 +5705,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
56975705
// UPDATE CONTENTS SIZE, UPDATE HIDDEN STATUS
56985706

56995707
// Update contents size from last frame for auto-fitting (or use explicit size)
5700-
window->ContentSize = CalcWindowContentSize(window);
5708+
CalcWindowContentSizes(window, &window->ContentSize, &window->ContentSizeIdeal);
57015709
if (window->HiddenFramesCanSkipItems > 0)
57025710
window->HiddenFramesCanSkipItems--;
57035711
if (window->HiddenFramesCannotSkipItems > 0)
@@ -5720,7 +5728,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
57205728
window->Size.x = window->SizeFull.x = 0.f;
57215729
if (!window_size_y_set_by_api)
57225730
window->Size.y = window->SizeFull.y = 0.f;
5723-
window->ContentSize = ImVec2(0.f, 0.f);
5731+
window->ContentSize = window->ContentSizeIdeal = ImVec2(0.f, 0.f);
57245732
}
57255733
}
57265734

@@ -5766,7 +5774,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
57665774
// SIZE
57675775

57685776
// Calculate auto-fit size, handle automatic resize
5769-
const ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSize);
5777+
const ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSizeIdeal);
57705778
bool use_current_size_for_scrollbar_x = window_just_created;
57715779
bool use_current_size_for_scrollbar_y = window_just_created;
57725780
if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && !window->Collapsed)
@@ -6053,6 +6061,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
60536061
window->DC.CursorPos = window->DC.CursorStartPos;
60546062
window->DC.CursorPosPrevLine = window->DC.CursorPos;
60556063
window->DC.CursorMaxPos = window->DC.CursorStartPos;
6064+
window->DC.IdealMaxPos = window->DC.CursorStartPos;
60566065
window->DC.CurrLineSize = window->DC.PrevLineSize = ImVec2(0.0f, 0.0f);
60576066
window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
60586067

@@ -6698,7 +6707,7 @@ void ImGui::SetNextWindowContentSize(const ImVec2& size)
66986707
{
66996708
ImGuiContext& g = *GImGui;
67006709
g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasContentSize;
6701-
g.NextWindowData.ContentSizeVal = size;
6710+
g.NextWindowData.ContentSizeVal = ImFloor(size);
67026711
}
67036712

67046713
void ImGui::SetNextWindowScroll(const ImVec2& scroll)
@@ -10544,8 +10553,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1054410553
Separator();
1054510554

1054610555
// Debugging enums
10547-
enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Content, WRT_ContentRegionRect, WRT_Count }; // Windows Rect Type
10548-
const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Content", "ContentRegionRect" };
10556+
enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Content, WRT_ContentIdeal, WRT_ContentRegionRect, WRT_Count }; // Windows Rect Type
10557+
const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Content", "ContentIdeal", "ContentRegionRect" };
1054910558
enum { TRT_OuterRect, TRT_InnerRect, TRT_WorkRect, TRT_HostClipRect, TRT_InnerClipRect, TRT_BackgroundClipRect, TRT_ColumnsRect, TRT_ColumnsWorkRect, TRT_ColumnsClipRect, TRT_ColumnsContentHeadersUsed, TRT_ColumnsContentHeadersIdeal, TRT_ColumnsContentFrozen, TRT_ColumnsContentUnfrozen, TRT_Count }; // Tables Rect Type
1055010559
const char* trt_rects_names[TRT_Count] = { "OuterRect", "InnerRect", "WorkRect", "HostClipRect", "InnerClipRect", "BackgroundClipRect", "ColumnsRect", "ColumnsWorkRect", "ColumnsClipRect", "ColumnsContentHeadersUsed", "ColumnsContentHeadersIdeal", "ColumnsContentFrozen", "ColumnsContentUnfrozen" };
1055110560
if (cfg->ShowWindowsRectsType < 0)
@@ -10581,7 +10590,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1058110590
else if (rect_type == WRT_InnerRect) { return window->InnerRect; }
1058210591
else if (rect_type == WRT_InnerClipRect) { return window->InnerClipRect; }
1058310592
else if (rect_type == WRT_WorkRect) { return window->WorkRect; }
10584-
else if (rect_type == WRT_Content) { ImVec2 min = window->InnerRect.Min - window->Scroll + window->WindowPadding; return ImRect(min, min + window->ContentSize); }
10593+
else if (rect_type == WRT_Content) { ImVec2 min = window->InnerRect.Min - window->Scroll + window->WindowPadding; return ImRect(min, min + window->ContentSize); }
10594+
else if (rect_type == WRT_ContentIdeal) { ImVec2 min = window->InnerRect.Min - window->Scroll + window->WindowPadding; return ImRect(min, min + window->ContentSizeIdeal); }
1058510595
else if (rect_type == WRT_ContentRegionRect) { return window->ContentRegionRect; }
1058610596
IM_ASSERT(0);
1058710597
return ImRect();
@@ -11069,7 +11079,7 @@ void ImGui::DebugNodeWindow(ImGuiWindow* window, const char* label)
1106911079

1107011080
ImGuiWindowFlags flags = window->Flags;
1107111081
DebugNodeDrawList(window, window->DrawList, "DrawList");
11072-
BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), ContentSize (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->ContentSize.x, window->ContentSize.y);
11082+
BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), ContentSize (%.1f,%.1f) Ideal (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->ContentSize.x, window->ContentSize.y, window->ContentSizeIdeal.x, window->ContentSizeIdeal.y);
1107311083
BulletText("Flags: 0x%08X (%s%s%s%s%s%s%s%s%s..)", flags,
1107411084
(flags & ImGuiWindowFlags_ChildWindow) ? "Child " : "", (flags & ImGuiWindowFlags_Tooltip) ? "Tooltip " : "", (flags & ImGuiWindowFlags_Popup) ? "Popup " : "",
1107511085
(flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : "",

imgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Index of this file:
5959
// Version
6060
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
6161
#define IMGUI_VERSION "1.80 WIP"
62-
#define IMGUI_VERSION_NUM 17911
62+
#define IMGUI_VERSION_NUM 17912
6363
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
6464
#define IMGUI_HAS_TABLE
6565

imgui_internal.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,8 @@ struct IMGUI_API ImGuiWindowTempData
16371637
ImVec2 CursorPos; // Current emitting position, in absolute coordinates.
16381638
ImVec2 CursorPosPrevLine;
16391639
ImVec2 CursorStartPos; // Initial position after Begin(), generally ~ window position + WindowPadding.
1640-
ImVec2 CursorMaxPos; // Used to implicitly calculate the size of our contents, always growing during the frame. Used to calculate window->ContentSize at the beginning of next frame
1640+
ImVec2 CursorMaxPos; // Used to implicitly calculate ContentSize at the beginning of next frame. Always growing during the frame.
1641+
ImVec2 IdealMaxPos; // Used to implicitly calculate ContentSizeIdeal.
16411642
ImVec2 CurrLineSize;
16421643
ImVec2 PrevLineSize;
16431644
float CurrLineTextBaseOffset; // Baseline offset (0.0f by default on a new line, generally == style.FramePadding.y when a framed item has been added).
@@ -1695,6 +1696,7 @@ struct IMGUI_API ImGuiWindow
16951696
ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
16961697
ImVec2 SizeFull; // Size when non collapsed
16971698
ImVec2 ContentSize; // Size of contents/scrollable client area (calculated from the extents reach of the cursor) from previous frame. Does not include window decoration or window padding.
1699+
ImVec2 ContentSizeIdeal;
16981700
ImVec2 ContentSizeExplicit; // Size of contents/scrollable client area explicitly request by the user via SetNextWindowContentSize().
16991701
ImVec2 WindowPadding; // Window padding at the time of Begin().
17001702
float WindowRounding; // Window rounding at the time of Begin(). May be clamped lower to avoid rendering artifacts with title bar, menu bar etc.
@@ -2146,7 +2148,7 @@ namespace ImGui
21462148
IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id);
21472149
IMGUI_API ImGuiWindow* FindWindowByName(const char* name);
21482150
IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window);
2149-
IMGUI_API ImVec2 CalcWindowExpectedSize(ImGuiWindow* window);
2151+
IMGUI_API ImVec2 CalcWindowNextAutoFitSize(ImGuiWindow* window);
21502152
IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent);
21512153
IMGUI_API bool IsWindowAbove(ImGuiWindow* potential_above, ImGuiWindow* potential_below);
21522154
IMGUI_API bool IsWindowNavFocusable(ImGuiWindow* window);

imgui_widgets.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF
16141614
if (popup_window->WasActive)
16151615
{
16161616
// Always override 'AutoPosLastDirection' to not leave a chance for a past value to affect us.
1617-
ImVec2 size_expected = CalcWindowExpectedSize(popup_window);
1617+
ImVec2 size_expected = CalcWindowNextAutoFitSize(popup_window);
16181618
if (flags & ImGuiComboFlags_PopupAlignLeft)
16191619
popup_window->AutoPosLastDirection = ImGuiDir_Left; // "Below, Toward Left"
16201620
else

0 commit comments

Comments
 (0)