Skip to content

Commit

Permalink
Keep original lastRect to fix some drawing glitches (e.g. in ErrorRow) (
Browse files Browse the repository at this point in the history
ShadowTheAge#34)

ShadowTheAge#31 was missing an additional fix for the scroll area and their
scrollbars.
With this I did not see any glitches anymore, and the ScrollArea size is
set correctly now (showing scrollbars if needed).(hard to see/test, as
it was visible for the Summary tab which will be my next PR)

Adding a lastContentRect which contains the (correct/out-of-window)
size, fixes the contentSize calculation in BuildGui().
  • Loading branch information
shpaass authored Feb 14, 2024
2 parents c940db2 + a457eb2 commit 856c455
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion YAFCui/ImGui/ImGuiBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions YAFCui/ImGui/ImGuiLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions YAFCui/ImGui/ScrollArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TData> : ScrollAreaBase
Expand All @@ -240,7 +240,7 @@ public float spacing
set
{
_spacing = value;
contents.Rebuild();
RebuildContents();
}
}

Expand All @@ -252,7 +252,7 @@ public IReadOnlyList<TData> data
set
{
_data = value ?? Array.Empty<TData>();
contents.Rebuild();
RebuildContents();
}
}

Expand All @@ -275,7 +275,7 @@ public override Vector2 scroll2d
base.scroll2d = value;
var row = CalcFirstBlock();
if (row != firstVisibleBlock)
contents.Rebuild();
RebuildContents();
}
}

Expand Down

0 comments on commit 856c455

Please sign in to comment.