Skip to content

Commit

Permalink
Scroll down/up exactly one page with page down/up keys
Browse files Browse the repository at this point in the history
  • Loading branch information
veger committed Jun 18, 2024
1 parent 06f8f10 commit c1ce681
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Yafc.UI/ImGui/ScrollArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Yafc.UI {
public abstract class Scrollable(bool vertical, bool horizontal, bool collapsible) : IKeyboardFocus {
/// <summary>Required size to fit Scrollable (child) contents</summary>
private Vector2 requiredContentSize;
/// <summary>This rectangle contains the available size (and position) of the scrollable content</summary>
private Rect contentRect;
/// <summary>Maximum scroller offset, calculated with the <see cref="requiredContentSize"/> and the available size</summary>
private Vector2 maxScroll;
private Vector2 _scroll;
Expand Down Expand Up @@ -41,8 +43,7 @@ public void Build(ImGui gui, float availableHeight, bool useBottomPadding = fals
float realHeight = collapsible ? MathF.Min(requiredContentSize.Y, availableHeight) : availableHeight;

if (gui.isBuilding) {
/// <summary>This rectangle contains the available size (and position) of the scrollable content</summary>
var contentRect = rect;
contentRect = rect;
contentRect.Width = width;

maxScroll = Vector2.Max(requiredContentSize - new Vector2(contentRect.Width, availableHeight), Vector2.Zero);
Expand Down Expand Up @@ -161,10 +162,10 @@ public bool KeyDown(SDL.SDL_Keysym key) {
scrollX += 3;
return true;
case SDL.SDL_Scancode.SDL_SCANCODE_PAGEDOWN:
// TODO Calculate page height
scrollY += contentRect.Height;
return true;
case SDL.SDL_Scancode.SDL_SCANCODE_PAGEUP:
// TODO Calculate page height
scrollY -= contentRect.Height;
return true;
case SDL.SDL_Scancode.SDL_SCANCODE_HOME:
scrollY = 0;
Expand Down

0 comments on commit c1ce681

Please sign in to comment.