From ca40a4ae68373c78ddf7f2635bb79b4b5212d2a4 Mon Sep 17 00:00:00 2001 From: Dale McCoy <21223975+DaleStan@users.noreply.github.com> Date: Sat, 11 May 2024 12:00:45 -0400 Subject: [PATCH] Add comments and a little bit of cleanup. --- Yafc.UI/ImGui/ScrollArea.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Yafc.UI/ImGui/ScrollArea.cs b/Yafc.UI/ImGui/ScrollArea.cs index 0b607c5c..26604664 100644 --- a/Yafc.UI/ImGui/ScrollArea.cs +++ b/Yafc.UI/ImGui/ScrollArea.cs @@ -202,14 +202,16 @@ public class ScrollArea(float height, GuiBuilder builder, Padding padding = defa public class VirtualScrollList : ScrollAreaBase { private readonly Vector2 elementSize; - protected readonly int bufferRows; - protected int firstVisibleBlock; - protected int elementsPerRow; + // When rendering the scrollable content, render 'blocks' of 4 rows at a time. (As far as I can tell, any positive value works. Shadow picked 4, so I kept that.) + private readonly int bufferRows = 4; + // The first block of bufferRows that was rendered last time BuildContents was called. If it changes while scrolling, we need to re-render the scrollable content. + private int firstVisibleBlock; + private int elementsPerRow; private IReadOnlyList _data = []; private readonly int maxRowsVisible; private readonly Drawer drawer; - public float _spacing; - protected readonly Action reorder; + private float _spacing; + private readonly Action reorder; public float spacing { get => _spacing; @@ -229,10 +231,9 @@ public IReadOnlyList data { } } - public VirtualScrollList(float height, Vector2 elementSize, Drawer drawer, int bufferRows = 4, Padding padding = default, Action reorder = null, bool collapsible = false) : base(height, padding, collapsible) { + public VirtualScrollList(float height, Vector2 elementSize, Drawer drawer, Padding padding = default, Action reorder = null, bool collapsible = false) : base(height, padding, collapsible) { this.elementSize = elementSize; maxRowsVisible = MathUtils.Ceil(height / this.elementSize.Y) + bufferRows + 1; - this.bufferRows = bufferRows; this.drawer = drawer; this.reorder = reorder; }