summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CHANGELOG.md6
-rw-r--r--src/draw.zig2
-rw-r--r--src/gui/gui.zig100
-rw-r--r--src/pdf_view.zig2
-rw-r--r--src/surface.zig5
5 files changed, 114 insertions, 1 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index c6c2eadd..1d6a1e71 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -16,6 +16,12 @@
- Workspace, column and pane tags share a tighter text inset.
- A diff paged into a session (`git show | pardes -`) opens its `+Diff`
alone; the `+Pager` no longer stays folded under it.
+- The workspace Pet wanders to a random spot, rests there a few seconds,
+ then sets off for another; the frog is drawn side-on and hops.
+- A drag started on a file's line numbers copies only the text; the
+ numbers no longer come along with the first line.
+- The GUI's scrollbar thumb moves by the pixel and follows a smooth
+ scroll as it glides, instead of jumping a row of the track at a time.
- Built with Zig 0.17. A bare `zig build` still puts the binaries in
`~/.local/bin`, now as a copy beside the prefix, which `--prefix` no
diff --git a/src/draw.zig b/src/draw.zig
index 22a8dc2a..84575873 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -87,6 +87,8 @@ pub fn place(p: *Pardes, s: *Surface) void {
const pos = (track_h * sb.offset) / total;
rail.thumb_y = @intCast(@min(pos, track_h));
rail.thumb_h = @intCast(@min(len, track_h - rail.thumb_y));
+ rail.thumb_at = @as(f32, @floatFromInt(sb.offset)) / @as(f32, @floatFromInt(total));
+ rail.thumb_span = @as(f32, @floatFromInt(@max(1, sb.len))) / @as(f32, @floatFromInt(total));
}
s.addRegion(rail);
// Each notice a chip at the right edge, one to a row in the order
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;
diff --git a/src/pdf_view.zig b/src/pdf_view.zig
index 500f05f3..2a89ef01 100644
--- a/src/pdf_view.zig
+++ b/src/pdf_view.zig
@@ -2814,6 +2814,8 @@ pub fn draw(
));
rail.thumb_y = @intCast(pos);
rail.thumb_h = @intCast(@min(len, track_h -| pos));
+ rail.thumb_at = @floatCast(state.document_scroll_y / @as(f64, @floatFromInt(total)));
+ rail.thumb_span = @as(f32, @floatFromInt(view.pixel_h)) / @as(f32, @floatFromInt(total));
s.fill(rail.rect.x, rail.rect.y, 1, rail.rect.h, .{ .bg = .{ .rgb = chrome.scroll_track } });
s.fill(rail.rect.x + 1, rail.rect.y, 1, rail.rect.h, .{ .bg = pane_bg });
s.fill(rail.rect.x, rail.rect.y + rail.thumb_y, 1, rail.thumb_h, .{ .bg = .{ .rgb = chrome.scroll_thumb } });
diff --git a/src/surface.zig b/src/surface.zig
index f7cc6010..e67cf21c 100644
--- a/src/surface.zig
+++ b/src/surface.zig
@@ -368,6 +368,11 @@ pub const Region = struct {
/// regions once render has returned.
thumb_y: u16 = 0,
thumb_h: u16 = 0,
+ /// The same thumb unrounded, for a pixel shell: its top and its length
+ /// as fractions of the track (the length before any minimum, so one
+ /// row of the content is `thumb_span / rect.h`). Zero when unmeasured.
+ thumb_at: f32 = 0,
+ thumb_span: f32 = 0,
/// A notice's index in its pane's `notices`.
notice: u8 = 0,
/// How far it stands off the page, 0 to 1: a pane's while it has the