From a457eb2c5ab916f73ca3d565620f2f3438d1ca74 Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Mon, 3 Jan 2022 21:47:28 +0100 Subject: [PATCH] Keep original lastRect to fix some drawing glitches (e.g. in ErrorRow) Adding a lastContentRect which contains the (correct/out-of-window) size, fixes the contentSize calculation in BuildGui(). I did not see any glich(es) anymore, and the ScrollArea size is set correctly now (showing scrollbars if needed) --- YAFCui/ImGui/ImGuiBuilding.cs | 2 +- YAFCui/ImGui/ImGuiLayout.cs | 5 +++-- YAFCui/ImGui/ScrollArea.cs | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/YAFCui/ImGui/ImGuiBuilding.cs b/YAFCui/ImGui/ImGuiBuilding.cs index cc918a60..412823e5 100644 --- a/YAFCui/ImGui/ImGuiBuilding.cs +++ b/YAFCui/ImGui/ImGuiBuilding.cs @@ -191,7 +191,7 @@ private void BuildGui(float width) rebuildRequested = false; ClearDrawCommandList(); DoGui(ImGuiAction.Build); - contentSize = new Vector2(lastRect.Right, lastRect.Bottom); + contentSize = new Vector2(lastContentRect.Width, lastContentRect.Height); if (boxColor != SchemeColor.None) { var rect = new Rect(default, contentSize); diff --git a/YAFCui/ImGui/ImGuiLayout.cs b/YAFCui/ImGui/ImGuiLayout.cs index f00e3723..5029d259 100644 --- a/YAFCui/ImGui/ImGuiLayout.cs +++ b/YAFCui/ImGui/ImGuiLayout.cs @@ -8,6 +8,7 @@ public partial class ImGui { private CopyableState state; public Rect lastRect { get; set; } + public Rect lastContentRect { get; set; } public float width => state.right - state.left; public Rect statePosition => new Rect(state.left, state.top, width, 0f); public ref RectAllocator allocator => ref state.allocator; @@ -242,8 +243,8 @@ public void Dispose() rect.Height += padding.top + padding.bottom; if (hasContent) { - gui.state.EncapsulateRect(rect); - gui.lastRect = rect; + gui.lastRect = gui.state.EncapsulateRect(rect); + gui.lastContentRect = rect; } else gui.lastRect = default; } diff --git a/YAFCui/ImGui/ScrollArea.cs b/YAFCui/ImGui/ScrollArea.cs index f8659de0..9ed0759e 100644 --- a/YAFCui/ImGui/ScrollArea.cs +++ b/YAFCui/ImGui/ScrollArea.cs @@ -219,7 +219,7 @@ public ScrollArea(float height, GuiBuilder builder, Padding padding = default, b } protected override void BuildContents(ImGui gui) => builder(gui); - public void Rebuild() => contents.Rebuild(); + public void Rebuild() => RebuildContents(); } public class VirtualScrollList : ScrollAreaBase @@ -240,7 +240,7 @@ public float spacing set { _spacing = value; - contents.Rebuild(); + RebuildContents(); } } @@ -252,7 +252,7 @@ public IReadOnlyList data set { _data = value ?? Array.Empty(); - contents.Rebuild(); + RebuildContents(); } } @@ -275,7 +275,7 @@ public override Vector2 scroll2d base.scroll2d = value; var row = CalcFirstBlock(); if (row != firstVisibleBlock) - contents.Rebuild(); + RebuildContents(); } }