Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project pages get 50% bottom padding #50

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
// 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) {
Expand Down
9 changes: 8 additions & 1 deletion YAFCui/ImGui/ScrollArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public abstract class Scrollable : IKeyboardFocus {
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;
veger marked this conversation as resolved.
Show resolved Hide resolved

protected Scrollable(bool vertical, bool horizontal, bool collapsible) {
this.vertical = vertical;
this.horizontal = horizontal;
Expand All @@ -22,7 +26,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, bool useBottomPadding = false) {
this.gui = gui;
this.height = height;
var rect = gui.statePosition;
Expand All @@ -33,6 +37,9 @@ public void Build(ImGui gui, float height) {
var innerRect = rect;
innerRect.Width = width;
contentSize = MeasureContent(innerRect, gui);
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;
innerRect.Height = rect.Height = realHeight;
Expand Down