Skip to content

Commit

Permalink
Project pages (e.g. production tables, production summaries) get 50% …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
shihan42 committed Feb 21, 2024
1 parent c44f888 commit 1259fd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions YAFC/Workspace/ProjectPageView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Numerics;
using SDL2;
using YAFC.Model;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -116,4 +117,4 @@ public override void SetModel(ProjectPage page) {

protected abstract void BuildPageTooltip(ImGui gui, T contents);
}
}
}
9 changes: 6 additions & 3 deletions YAFCui/ImGui/ScrollArea.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Numerics;
using SDL2;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -278,4 +281,4 @@ protected virtual void BuildElement(ImGui gui, TData element, int index) {
drawer(gui, element, index);
}
}
}
}

0 comments on commit 1259fd9

Please sign in to comment.