summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-21 21:05:10 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:15 -0300
commitb730ce12667fb75c99b97eafcfc73d7b1f8bdd13 (patch)
treea04da809d8efe12687ed51d395deef258e7a5630 /src/gui/gui.zig
parent2b0d9d607094739133470c10af51fd670cd63ed3 (diff)
downloadpardes-b730ce12667fb75c99b97eafcfc73d7b1f8bdd13.tar.gz
pardes-b730ce12667fb75c99b97eafcfc73d7b1f8bdd13.zip
GUI scrollbar thumb moves by the pixel and follows the glide
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig100
1 files changed, 99 insertions, 1 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index f0dd0682..2abf9166 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -2969,6 +2969,9 @@ test "an attached frontend draws the session's chrome from its frame alone" {
g.tagline_width = 6;
g.tagline_height = 12;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
var groups = makeGroups(&.{}, false);
try buildDecor(&g, gpa, s, &groups, fixedCellLayout(&g), 800, 480, true);
@@ -7165,6 +7168,9 @@ test "every pixel of a grip column is band, button or ring, and the button sits
var g: Gui = undefined;
g.words = .{};
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = m.w;
g.cell_h = m.h;
@@ -7473,6 +7479,9 @@ test "lapis plaques stay in their tag's band, clear of every grip; only the focu
try std.testing.expect(s.chrome.decor_box_border != null and s.chrome.decor_checker != null and s.chrome.decor_dots != null and s.chrome.decor_title != null);
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 16;
g.cell_h = 32;
@@ -7572,6 +7581,9 @@ test "insert cursor overlays without replacing the character beneath it" {
const surface: pardes.Surface = .{ .cols = 5, .rows = 5, .cells = &cells, .cursor = .{ .x = 2, .y = 3, .bar = true } };
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(std.testing.allocator);
g.cell_w = 10;
g.cell_h = 20;
@@ -9032,6 +9044,9 @@ test "a lift never touches a tag, a grip or a header, on a light theme or a dark
g.tagline_width = 6;
g.tagline_height = 12;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
var groups = makeGroups(&.{}, false);
try buildDecor(&g, gpa, settled, &groups, fixedCellLayout(&g), 800, 480, true);
@@ -9317,7 +9332,19 @@ fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, gr
try addChecker(g, gpa, column[0], y0, column[1], y1, chrome.scroll_track, gold, dp(@floatFromInt(@max(1, chrome.decor_checker_px))), track, win_w, win_h)
else
try addDecor(g, gpa, column[0], y0, column[1], y1, chrome.scroll_track, 1, track, win_w, win_h);
- if (rail.thumb_h != 0) {
+ if (rail.thumb_h != 0 and rail.thumb_span > 0) {
+ // In pixels, not rows, and with the picture while it glides
+ // or lags behind the core's rows (both in rows of the body).
+ const lag: f32 = if (g.glide.offset != 0 and g.glide.pane == rail.owner)
+ g.glide.offset
+ else if (g.scroll_pane != null and g.scroll_pane.? == rail.owner) g.scroll_lag else 0;
+ const track_px = body_y1 - y0;
+ const size = @min(track_px, @max(layout.h, rail.thumb_span * track_px));
+ const at = rail.thumb_at + lag * rail.thumb_span / @as(f32, @floatFromInt(rail.rect.h));
+ const thumb_y0 = y0 + std.math.clamp(at * track_px, 0, track_px - size);
+ const thumb_y1 = if (thumb_y0 + size >= body_y1 - 0.5) y1 else thumb_y0 + size;
+ try addDecor(g, gpa, column[0], thumb_y0, column[1] - dp(1), thumb_y1, chrome.scroll_thumb, 1, track, win_w, win_h);
+ } else if (rail.thumb_h != 0) {
const thumb_y0 = @as(f32, @floatFromInt(rail.rect.y + rail.thumb_y)) * layout.h;
const thumb_y1 = if (rail.thumb_y + rail.thumb_h == rail.rect.h) y1 else @as(f32, @floatFromInt(rail.rect.y + rail.thumb_y + rail.thumb_h)) * layout.h;
try addDecor(g, gpa, column[0], thumb_y0, column[1] - dp(1), thumb_y1, chrome.scroll_thumb, 1, track, win_w, win_h);
@@ -9681,6 +9708,9 @@ test "decor less its holes covers each pixel of the rest once and none of the ho
g.cell_w = 1;
g.cell_h = 1;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
const holes = [_][4]f32{ .{ 3, 2, 9, 6 }, .{ 5, 4, 12, 8 }, .{ 30, 30, 40, 40 } };
try addDecorExcept(&g, gpa, .{ 1, 1, 11, 10 }, &holes, .{ 1, 2, 3 }, null, 16, 12);
@@ -9872,6 +9902,9 @@ test "a theme's own rules and scrollbar are drawn at its widths: acme's 2px blac
try std.testing.expectEqual(@as(u8, 18), s.chrome.rail_px);
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 16;
g.cell_h = 20;
@@ -9900,6 +9933,47 @@ test "a theme's own rules and scrollbar are drawn at its widths: acme's 2px blac
try std.testing.expect(tracks >= 2);
}
+test "the scrollbar thumb moves by the pixel and follows a glide" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
+ defer core.deinit();
+ const pane = try core.setTestFile(std.mem.asBytes(&@as([1000][5]u8, @splat("line\n".*))));
+ var g: Gui = undefined;
+ g.decor = .empty;
+ defer g.decor.deinit(gpa);
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
+ g.cell_w = 10;
+ g.cell_h = 20;
+ g.tagline_width = 6;
+ g.tagline_height = 12;
+ const thumb = struct {
+ // The thumb's top, in window pixels.
+ fn top(gui: *Gui, p: *pardes.Pardes) !f32 {
+ gui.decor.clearRetainingCapacity();
+ pardes.test_api.sync(p);
+ const s = try p.render(p.scratch.allocator());
+ var groups = makeGroups(&.{}, false);
+ try buildDecor(gui, std.testing.allocator, s, &groups, fixedCellLayout(gui), 800, 480, true);
+ const ink = s.chrome.scroll_thumb;
+ for (gui.decor.items) |item| if (@abs(item.br - @as(f32, @floatFromInt(ink[0])) / 255) < 1e-3 and
+ @abs(item.bg - @as(f32, @floatFromInt(ink[1])) / 255) < 1e-3 and
+ @abs(item.bb - @as(f32, @floatFromInt(ink[2])) / 255) < 1e-3) return (1 - item.y0) / 2 * 480;
+ return error.TestExpectedThumb;
+ }
+ };
+ pane.file.?.scroll = 10;
+ const at10 = try thumb.top(&g, core);
+ pane.file.?.scroll = 11;
+ const at11 = try thumb.top(&g, core);
+ // A line of a thousand moves it a fraction of a row, not 0 or 20 px.
+ try std.testing.expect(at11 > at10 and at11 - at10 < 1);
+ g.glide.pane = core.active;
+ g.glide.offset = -1;
+ try std.testing.expectApproxEqAbs(at10, try thumb.top(&g, core), 1e-3);
+}
+
test "the rule between stacked panes stays in the tag band's slack, at any tagline size" {
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
@@ -9914,6 +9988,9 @@ test "the rule between stacked panes stays in the tag band's slack, at any tagli
for ([_]u32{ 12, 20 }) |tagline_h| {
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 10;
g.cell_h = 20;
@@ -9949,6 +10026,9 @@ test "an empty column is ruled on both sides, as between two filled ones" {
const s = try core.render(core.scratch.allocator());
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 10;
g.cell_h = 20;
@@ -9985,6 +10065,9 @@ test "at a 2x display every logical pixel is two: rules, the tag rule, the grip'
defer display_scale = 1;
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 16;
g.cell_h = 32;
@@ -10049,6 +10132,9 @@ test "decor is read from the regions, each pane's in its own group" {
const s = try core.render(core.scratch.allocator());
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 10;
g.cell_h = 20;
@@ -10114,6 +10200,9 @@ test "a pane on the move casts a shadow on the other panes' bodies alone, most a
const s = try core.render(core.scratch.allocator());
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 10;
g.cell_h = 20;
@@ -10167,6 +10256,9 @@ test "the selection glows round its block, on the body only, fading in over 100
s.cursor = null;
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 10;
g.cell_h = 20;
@@ -10219,6 +10311,9 @@ test "a hovered word glows along its foot, never over the cursor, fading in over
s.cursor = .{ .x = body.rect.x + 8, .y = row };
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 10;
g.cell_h = 20;
@@ -10262,6 +10357,9 @@ test "occlusion shades each body's edges, inside it, never a tag, a grip or the
s.cursor = .{ .x = body.rect.x, .y = body.rect.y };
var g: Gui = undefined;
g.decor = .empty;
+ g.glide = .{};
+ g.scroll_pane = null;
+ g.scroll_lag = 0;
defer g.decor.deinit(gpa);
g.cell_w = 10;
g.cell_h = 20;