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 22, 2024
1 parent 94c01a9 commit 327cbbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion YAFC/Workspace/ProjectPageView.cs
Original file line number Diff line number Diff line change
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
5 changes: 4 additions & 1 deletion YAFCui/ImGui/ScrollArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 327cbbc

Please sign in to comment.