mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
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. (#3414)
# Conflicts: # imgui.cpp
This commit is contained in:
parent
6470681d87
commit
6af92b05bf
52
imgui.cpp
52
imgui.cpp
@ -5048,18 +5048,24 @@ static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size
|
|||||||
return new_size;
|
return new_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 CalcWindowContentSize(ImGuiWindow* window)
|
static void CalcWindowContentSizes(ImGuiWindow* window, ImVec2* content_size_current, ImVec2* content_size_ideal)
|
||||||
{
|
{
|
||||||
if (window->Collapsed)
|
bool preserve_old_content_sizes = false;
|
||||||
if (window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
|
if (window->Collapsed && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
|
||||||
return window->ContentSize;
|
preserve_old_content_sizes = true;
|
||||||
if (window->Hidden && window->HiddenFramesCannotSkipItems == 0 && window->HiddenFramesCanSkipItems > 0)
|
else if (window->Hidden && window->HiddenFramesCannotSkipItems == 0 && window->HiddenFramesCanSkipItems > 0)
|
||||||
return window->ContentSize;
|
preserve_old_content_sizes = true;
|
||||||
|
if (preserve_old_content_sizes)
|
||||||
|
{
|
||||||
|
*content_size_current = window->ContentSize;
|
||||||
|
*content_size_ideal = window->ContentSizeIdeal;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ImVec2 sz;
|
content_size_current->x = (window->ContentSizeExplicit.x != 0.0f) ? window->ContentSizeExplicit.x : IM_FLOOR(window->DC.CursorMaxPos.x - window->DC.CursorStartPos.x);
|
||||||
sz.x = IM_FLOOR((window->ContentSizeExplicit.x != 0.0f) ? window->ContentSizeExplicit.x : window->DC.CursorMaxPos.x - window->DC.CursorStartPos.x);
|
content_size_current->y = (window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : IM_FLOOR(window->DC.CursorMaxPos.y - window->DC.CursorStartPos.y);
|
||||||
sz.y = IM_FLOOR((window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : window->DC.CursorMaxPos.y - window->DC.CursorStartPos.y);
|
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);
|
||||||
return sz;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
|
static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
|
||||||
@ -5097,10 +5103,12 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVec2 ImGui::CalcWindowExpectedSize(ImGuiWindow* window)
|
ImVec2 ImGui::CalcWindowNextAutoFitSize(ImGuiWindow* window)
|
||||||
{
|
{
|
||||||
ImVec2 size_contents = CalcWindowContentSize(window);
|
ImVec2 size_contents_current;
|
||||||
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, size_contents);
|
ImVec2 size_contents_ideal;
|
||||||
|
CalcWindowContentSizes(window, &size_contents_current, &size_contents_ideal);
|
||||||
|
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, size_contents_ideal);
|
||||||
ImVec2 size_final = CalcWindowSizeAfterConstraint(window, size_auto_fit);
|
ImVec2 size_final = CalcWindowSizeAfterConstraint(window, size_auto_fit);
|
||||||
return size_final;
|
return size_final;
|
||||||
}
|
}
|
||||||
@ -5697,7 +5705,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
// UPDATE CONTENTS SIZE, UPDATE HIDDEN STATUS
|
// UPDATE CONTENTS SIZE, UPDATE HIDDEN STATUS
|
||||||
|
|
||||||
// Update contents size from last frame for auto-fitting (or use explicit size)
|
// Update contents size from last frame for auto-fitting (or use explicit size)
|
||||||
window->ContentSize = CalcWindowContentSize(window);
|
CalcWindowContentSizes(window, &window->ContentSize, &window->ContentSizeIdeal);
|
||||||
if (window->HiddenFramesCanSkipItems > 0)
|
if (window->HiddenFramesCanSkipItems > 0)
|
||||||
window->HiddenFramesCanSkipItems--;
|
window->HiddenFramesCanSkipItems--;
|
||||||
if (window->HiddenFramesCannotSkipItems > 0)
|
if (window->HiddenFramesCannotSkipItems > 0)
|
||||||
@ -5720,7 +5728,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
window->Size.x = window->SizeFull.x = 0.f;
|
window->Size.x = window->SizeFull.x = 0.f;
|
||||||
if (!window_size_y_set_by_api)
|
if (!window_size_y_set_by_api)
|
||||||
window->Size.y = window->SizeFull.y = 0.f;
|
window->Size.y = window->SizeFull.y = 0.f;
|
||||||
window->ContentSize = ImVec2(0.f, 0.f);
|
window->ContentSize = window->ContentSizeIdeal = ImVec2(0.f, 0.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5766,7 +5774,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
// SIZE
|
// SIZE
|
||||||
|
|
||||||
// Calculate auto-fit size, handle automatic resize
|
// Calculate auto-fit size, handle automatic resize
|
||||||
const ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSize);
|
const ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSizeIdeal);
|
||||||
bool use_current_size_for_scrollbar_x = window_just_created;
|
bool use_current_size_for_scrollbar_x = window_just_created;
|
||||||
bool use_current_size_for_scrollbar_y = window_just_created;
|
bool use_current_size_for_scrollbar_y = window_just_created;
|
||||||
if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && !window->Collapsed)
|
if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && !window->Collapsed)
|
||||||
@ -6053,6 +6061,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
window->DC.CursorPos = window->DC.CursorStartPos;
|
window->DC.CursorPos = window->DC.CursorStartPos;
|
||||||
window->DC.CursorPosPrevLine = window->DC.CursorPos;
|
window->DC.CursorPosPrevLine = window->DC.CursorPos;
|
||||||
window->DC.CursorMaxPos = window->DC.CursorStartPos;
|
window->DC.CursorMaxPos = window->DC.CursorStartPos;
|
||||||
|
window->DC.IdealMaxPos = window->DC.CursorStartPos;
|
||||||
window->DC.CurrLineSize = window->DC.PrevLineSize = ImVec2(0.0f, 0.0f);
|
window->DC.CurrLineSize = window->DC.PrevLineSize = ImVec2(0.0f, 0.0f);
|
||||||
window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
|
window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
|
||||||
|
|
||||||
@ -6698,7 +6707,7 @@ void ImGui::SetNextWindowContentSize(const ImVec2& size)
|
|||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasContentSize;
|
g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasContentSize;
|
||||||
g.NextWindowData.ContentSizeVal = size;
|
g.NextWindowData.ContentSizeVal = ImFloor(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui::SetNextWindowScroll(const ImVec2& scroll)
|
void ImGui::SetNextWindowScroll(const ImVec2& scroll)
|
||||||
@ -10544,8 +10553,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
Separator();
|
Separator();
|
||||||
|
|
||||||
// Debugging enums
|
// Debugging enums
|
||||||
enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Content, WRT_ContentRegionRect, WRT_Count }; // Windows Rect Type
|
enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Content, WRT_ContentIdeal, WRT_ContentRegionRect, WRT_Count }; // Windows Rect Type
|
||||||
const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Content", "ContentRegionRect" };
|
const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Content", "ContentIdeal", "ContentRegionRect" };
|
||||||
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
|
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
|
||||||
const char* trt_rects_names[TRT_Count] = { "OuterRect", "InnerRect", "WorkRect", "HostClipRect", "InnerClipRect", "BackgroundClipRect", "ColumnsRect", "ColumnsWorkRect", "ColumnsClipRect", "ColumnsContentHeadersUsed", "ColumnsContentHeadersIdeal", "ColumnsContentFrozen", "ColumnsContentUnfrozen" };
|
const char* trt_rects_names[TRT_Count] = { "OuterRect", "InnerRect", "WorkRect", "HostClipRect", "InnerClipRect", "BackgroundClipRect", "ColumnsRect", "ColumnsWorkRect", "ColumnsClipRect", "ColumnsContentHeadersUsed", "ColumnsContentHeadersIdeal", "ColumnsContentFrozen", "ColumnsContentUnfrozen" };
|
||||||
if (cfg->ShowWindowsRectsType < 0)
|
if (cfg->ShowWindowsRectsType < 0)
|
||||||
@ -10581,7 +10590,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
else if (rect_type == WRT_InnerRect) { return window->InnerRect; }
|
else if (rect_type == WRT_InnerRect) { return window->InnerRect; }
|
||||||
else if (rect_type == WRT_InnerClipRect) { return window->InnerClipRect; }
|
else if (rect_type == WRT_InnerClipRect) { return window->InnerClipRect; }
|
||||||
else if (rect_type == WRT_WorkRect) { return window->WorkRect; }
|
else if (rect_type == WRT_WorkRect) { return window->WorkRect; }
|
||||||
else if (rect_type == WRT_Content) { ImVec2 min = window->InnerRect.Min - window->Scroll + window->WindowPadding; return ImRect(min, min + window->ContentSize); }
|
else if (rect_type == WRT_Content) { ImVec2 min = window->InnerRect.Min - window->Scroll + window->WindowPadding; return ImRect(min, min + window->ContentSize); }
|
||||||
|
else if (rect_type == WRT_ContentIdeal) { ImVec2 min = window->InnerRect.Min - window->Scroll + window->WindowPadding; return ImRect(min, min + window->ContentSizeIdeal); }
|
||||||
else if (rect_type == WRT_ContentRegionRect) { return window->ContentRegionRect; }
|
else if (rect_type == WRT_ContentRegionRect) { return window->ContentRegionRect; }
|
||||||
IM_ASSERT(0);
|
IM_ASSERT(0);
|
||||||
return ImRect();
|
return ImRect();
|
||||||
@ -11069,7 +11079,7 @@ void ImGui::DebugNodeWindow(ImGuiWindow* window, const char* label)
|
|||||||
|
|
||||||
ImGuiWindowFlags flags = window->Flags;
|
ImGuiWindowFlags flags = window->Flags;
|
||||||
DebugNodeDrawList(window, window->DrawList, "DrawList");
|
DebugNodeDrawList(window, window->DrawList, "DrawList");
|
||||||
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);
|
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);
|
||||||
BulletText("Flags: 0x%08X (%s%s%s%s%s%s%s%s%s..)", flags,
|
BulletText("Flags: 0x%08X (%s%s%s%s%s%s%s%s%s..)", flags,
|
||||||
(flags & ImGuiWindowFlags_ChildWindow) ? "Child " : "", (flags & ImGuiWindowFlags_Tooltip) ? "Tooltip " : "", (flags & ImGuiWindowFlags_Popup) ? "Popup " : "",
|
(flags & ImGuiWindowFlags_ChildWindow) ? "Child " : "", (flags & ImGuiWindowFlags_Tooltip) ? "Tooltip " : "", (flags & ImGuiWindowFlags_Popup) ? "Popup " : "",
|
||||||
(flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : "",
|
(flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : "",
|
||||||
|
2
imgui.h
2
imgui.h
@ -59,7 +59,7 @@ Index of this file:
|
|||||||
// Version
|
// Version
|
||||||
// (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)
|
// (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)
|
||||||
#define IMGUI_VERSION "1.80 WIP"
|
#define IMGUI_VERSION "1.80 WIP"
|
||||||
#define IMGUI_VERSION_NUM 17911
|
#define IMGUI_VERSION_NUM 17912
|
||||||
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
|
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
|
||||||
#define IMGUI_HAS_TABLE
|
#define IMGUI_HAS_TABLE
|
||||||
|
|
||||||
|
@ -1637,7 +1637,8 @@ struct IMGUI_API ImGuiWindowTempData
|
|||||||
ImVec2 CursorPos; // Current emitting position, in absolute coordinates.
|
ImVec2 CursorPos; // Current emitting position, in absolute coordinates.
|
||||||
ImVec2 CursorPosPrevLine;
|
ImVec2 CursorPosPrevLine;
|
||||||
ImVec2 CursorStartPos; // Initial position after Begin(), generally ~ window position + WindowPadding.
|
ImVec2 CursorStartPos; // Initial position after Begin(), generally ~ window position + WindowPadding.
|
||||||
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
|
ImVec2 CursorMaxPos; // Used to implicitly calculate ContentSize at the beginning of next frame. Always growing during the frame.
|
||||||
|
ImVec2 IdealMaxPos; // Used to implicitly calculate ContentSizeIdeal.
|
||||||
ImVec2 CurrLineSize;
|
ImVec2 CurrLineSize;
|
||||||
ImVec2 PrevLineSize;
|
ImVec2 PrevLineSize;
|
||||||
float CurrLineTextBaseOffset; // Baseline offset (0.0f by default on a new line, generally == style.FramePadding.y when a framed item has been added).
|
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
|
|||||||
ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
|
ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
|
||||||
ImVec2 SizeFull; // Size when non collapsed
|
ImVec2 SizeFull; // Size when non collapsed
|
||||||
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.
|
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.
|
||||||
|
ImVec2 ContentSizeIdeal;
|
||||||
ImVec2 ContentSizeExplicit; // Size of contents/scrollable client area explicitly request by the user via SetNextWindowContentSize().
|
ImVec2 ContentSizeExplicit; // Size of contents/scrollable client area explicitly request by the user via SetNextWindowContentSize().
|
||||||
ImVec2 WindowPadding; // Window padding at the time of Begin().
|
ImVec2 WindowPadding; // Window padding at the time of Begin().
|
||||||
float WindowRounding; // Window rounding at the time of Begin(). May be clamped lower to avoid rendering artifacts with title bar, menu bar etc.
|
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
|
|||||||
IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id);
|
IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id);
|
||||||
IMGUI_API ImGuiWindow* FindWindowByName(const char* name);
|
IMGUI_API ImGuiWindow* FindWindowByName(const char* name);
|
||||||
IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window);
|
IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window);
|
||||||
IMGUI_API ImVec2 CalcWindowExpectedSize(ImGuiWindow* window);
|
IMGUI_API ImVec2 CalcWindowNextAutoFitSize(ImGuiWindow* window);
|
||||||
IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent);
|
IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent);
|
||||||
IMGUI_API bool IsWindowAbove(ImGuiWindow* potential_above, ImGuiWindow* potential_below);
|
IMGUI_API bool IsWindowAbove(ImGuiWindow* potential_above, ImGuiWindow* potential_below);
|
||||||
IMGUI_API bool IsWindowNavFocusable(ImGuiWindow* window);
|
IMGUI_API bool IsWindowNavFocusable(ImGuiWindow* window);
|
||||||
|
@ -1614,7 +1614,7 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF
|
|||||||
if (popup_window->WasActive)
|
if (popup_window->WasActive)
|
||||||
{
|
{
|
||||||
// Always override 'AutoPosLastDirection' to not leave a chance for a past value to affect us.
|
// Always override 'AutoPosLastDirection' to not leave a chance for a past value to affect us.
|
||||||
ImVec2 size_expected = CalcWindowExpectedSize(popup_window);
|
ImVec2 size_expected = CalcWindowNextAutoFitSize(popup_window);
|
||||||
if (flags & ImGuiComboFlags_PopupAlignLeft)
|
if (flags & ImGuiComboFlags_PopupAlignLeft)
|
||||||
popup_window->AutoPosLastDirection = ImGuiDir_Left; // "Below, Toward Left"
|
popup_window->AutoPosLastDirection = ImGuiDir_Left; // "Below, Toward Left"
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user