From 327cbbc9bd94fb4d3d50af4503e4dfe3751916dc Mon Sep 17 00:00:00 2001 From: shihan42 Date: Wed, 21 Feb 2024 14:41:11 +0100 Subject: [PATCH] Project pages (e.g. production tables, production summaries) get 50% bottom padding to enable scrolling past the last row The base class Scrollable is used in different places (e.g. project pages, item explorer). To ensure that only those subclasses that need vertical bottom padding the padding factor has a default value of 0%. Project pages switch that to 50% to enable scrolling past the last row. Closes #14 --- YAFC/Workspace/ProjectPageView.cs | 3 ++- YAFCui/ImGui/ScrollArea.cs | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/YAFC/Workspace/ProjectPageView.cs b/YAFC/Workspace/ProjectPageView.cs index 1c0fc8ee..e04e823b 100644 --- a/YAFC/Workspace/ProjectPageView.cs +++ b/YAFC/Workspace/ProjectPageView.cs @@ -58,7 +58,8 @@ public void Build(ImGui gui, Vector2 visibleSize) { else gui.AllocateRect(contentWidth, headerHeight); - base.Build(gui, visibleSize.Y - headerHeight); + // 50% visible height gets added to the content height to enable scrolling past the last row + base.Build(gui, visibleSize.Y - headerHeight, 0.5f); } protected override Vector2 MeasureContent(Rect rect, ImGui gui) { diff --git a/YAFCui/ImGui/ScrollArea.cs b/YAFCui/ImGui/ScrollArea.cs index 5e6ef228..01c72edb 100644 --- a/YAFCui/ImGui/ScrollArea.cs +++ b/YAFCui/ImGui/ScrollArea.cs @@ -22,7 +22,7 @@ protected Scrollable(bool vertical, bool horizontal, bool collapsible) { protected abstract void PositionContent(ImGui gui, Rect viewport); - public void Build(ImGui gui, float height) { + public void Build(ImGui gui, float height, float heightPaddingFactor = 0f) { this.gui = gui; this.height = height; var rect = gui.statePosition; @@ -33,6 +33,9 @@ public void Build(ImGui gui, float height) { var innerRect = rect; innerRect.Width = width; contentSize = MeasureContent(innerRect, gui); + if (contentSize.Y > height) { + contentSize.Y += height * heightPaddingFactor; + } maxScroll = Vector2.Max(contentSize - new Vector2(innerRect.Width, height), Vector2.Zero); var realHeight = collapsible ? MathF.Min(contentSize.Y, height) : height; innerRect.Height = rect.Height = realHeight;