From ff284158f3b99a7490e795ba83b12ca3024081cf Mon Sep 17 00:00:00 2001 From: shihan42 Date: Wed, 21 Feb 2024 14:41:11 +0100 Subject: [PATCH 1/3] 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; From 9aa0747977bb6d14f37e01799bd5b308badee4fa Mon Sep 17 00:00:00 2001 From: shihan42 Date: Thu, 22 Feb 2024 13:59:32 +0100 Subject: [PATCH 2/3] Use fixed pixel count for bottom padding On large screens the 50% of height tend to become really high so that the padding is much more than necessary. Padding by a fixed pixel amount makes it usable on screens of different sizes. --- YAFC/Workspace/ProjectPageView.cs | 4 ++-- YAFCui/ImGui/ScrollArea.cs | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/YAFC/Workspace/ProjectPageView.cs b/YAFC/Workspace/ProjectPageView.cs index e04e823b..a617861b 100644 --- a/YAFC/Workspace/ProjectPageView.cs +++ b/YAFC/Workspace/ProjectPageView.cs @@ -58,8 +58,8 @@ public void Build(ImGui gui, Vector2 visibleSize) { else gui.AllocateRect(contentWidth, 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); + // use bottom padding to enable scrolling past the last row + base.Build(gui, visibleSize.Y - headerHeight, true); } protected override Vector2 MeasureContent(Rect rect, ImGui gui) { diff --git a/YAFCui/ImGui/ScrollArea.cs b/YAFCui/ImGui/ScrollArea.cs index 01c72edb..b29fa896 100644 --- a/YAFCui/ImGui/ScrollArea.cs +++ b/YAFCui/ImGui/ScrollArea.cs @@ -13,6 +13,7 @@ public abstract class Scrollable : IKeyboardFocus { private float height; private ImGui gui; public const float ScrollbarSize = 1f; + private const float BottomPaddingInPixels = 100f; protected Scrollable(bool vertical, bool horizontal, bool collapsible) { this.vertical = vertical; @@ -22,7 +23,7 @@ protected Scrollable(bool vertical, bool horizontal, bool collapsible) { protected abstract void PositionContent(ImGui gui, Rect viewport); - public void Build(ImGui gui, float height, float heightPaddingFactor = 0f) { + public void Build(ImGui gui, float height, bool useBottomPadding = false) { this.gui = gui; this.height = height; var rect = gui.statePosition; @@ -33,8 +34,8 @@ public void Build(ImGui gui, float height, float heightPaddingFactor = 0f) { var innerRect = rect; innerRect.Width = width; contentSize = MeasureContent(innerRect, gui); - if (contentSize.Y > height) { - contentSize.Y += height * heightPaddingFactor; + if (contentSize.Y > height && useBottomPadding) { + contentSize.Y += BottomPaddingInPixels / gui.pixelsPerUnit; } maxScroll = Vector2.Max(contentSize - new Vector2(innerRect.Width, height), Vector2.Zero); var realHeight = collapsible ? MathF.Min(contentSize.Y, height) : height; From b4b39bdc55c94d385ee12c89aa381b070dc59fcd Mon Sep 17 00:00:00 2001 From: shihan42 Date: Thu, 22 Feb 2024 15:00:36 +0100 Subject: [PATCH 3/3] Added a comment for documentation --- YAFCui/ImGui/ScrollArea.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/YAFCui/ImGui/ScrollArea.cs b/YAFCui/ImGui/ScrollArea.cs index b29fa896..9b7b18fb 100644 --- a/YAFCui/ImGui/ScrollArea.cs +++ b/YAFCui/ImGui/ScrollArea.cs @@ -13,6 +13,9 @@ public abstract class Scrollable : IKeyboardFocus { private float height; private ImGui gui; public const float ScrollbarSize = 1f; + + // Padding to add at the bottom of the scroll area to be able to scroll past the + // last item; needs useBottomPadding to be set to true in method Build() private const float BottomPaddingInPixels = 100f; protected Scrollable(bool vertical, bool horizontal, bool collapsible) {