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 e1cd68e commit 4a8c135
Show file tree
Hide file tree
Showing 2 changed files with 6 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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Date: soon
- Fix that some pages couldn't be deleted.
- Fix that returning to the Welcome Screen could break the panels in the main window.
- Make horizontal scrollbar clickable/draggable.
- Scroll down/up exactly one page with page down/up keys
----------------------------------------------------------------------------------------------------------------------
Version: 0.7.1
Date: June 12th 2024
Expand Down

0 comments on commit 4a8c135

Please sign in to comment.