summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig238
1 files changed, 195 insertions, 43 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 65b3f926..f9921111 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -25,11 +25,7 @@ const ninep_io = @import("../9p_io.zig");
const detached_client = @import("../detached/client.zig");
const tracy = @import("../tracy.zig");
-pub const c = @cImport({
- @cDefine("SDL_DISABLE_OLD_NAMES", "1");
- @cInclude("SDL3/SDL.h");
- @cInclude("font.h");
-});
+pub const c = @import("gui_c"); // SDL3 and font.h, translated by build.zig
const host_io = @import("../host_io.zig");
extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int;
@@ -1873,6 +1869,7 @@ const Gui = struct {
scroll_rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 },
scroll_body_y: u16 = 0, // that rect's first BODY row (Tagbottom moves it)
scroll_body_h: u16 = 0, // and its BODY rows, which a taller tag leaves fewer of
+ scroll_held_px: f32 = 0, // its tree-sitter context band, which never moves
scroll_col: u16 = 0, // where the wheel turned: crossed rows are delivered
scroll_row: u16 = 0, // THERE, not wherever the pointer has drifted to since
scroll_delta: f32 = 0, // finite raw distance waiting for the render batch
@@ -1891,7 +1888,6 @@ const Gui = struct {
sel_glow: SelGlow = .{},
hover_glow: SelGlow = .{},
/// G14: the cells last drawn and when each last changed.
-
/// The cursor's blink (blinkNow): when the frame drawn last arrived,
/// a redraw owed for an edge, and this frame's cursor mode and alpha.
frame_arrival_ns: u64 = 0,
@@ -2294,7 +2290,7 @@ fn setTransitionFields(
instance.present_y0 = presented[1];
instance.present_x1 = presented[2];
instance.present_y1 = presented[3];
- instance.effect = @intFromEnum(active.effect);
+ instance.effect = @backingInt(active.effect);
instance.progress_bits = @bitCast(active.amount());
instance.serial = active.serial;
instance.cell_coord = cell_coord;
@@ -2371,12 +2367,23 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, attach: ?[]const u
defer c.SDL_DestroyWindow(window);
updateDisplayScale(window);
if (native_wayland) log.info("Wayland opacity: background-only transparent surface", .{});
- const arrow_cursor = c.SDL_CreateCursor(&p9_arrow_set, &p9_arrow_mask, 16, 16, 1, 1);
+ // On Linux the desktop's own cursor theme draws them (the compositor's
+ // cursor-shape protocol, else XCURSOR_THEME), at its size and scale:
+ // the arrow is its default, acme's box its move, as the plan9 theme
+ // has them. Elsewhere acme's bitmaps, at 16 pixels.
+ const themed_cursors = builtin.os.tag == .linux;
+ const arrow_cursor = if (themed_cursors)
+ c.SDL_CreateSystemCursor(c.SDL_SYSTEM_CURSOR_DEFAULT)
+ else
+ c.SDL_CreateCursor(&p9_arrow_set, &p9_arrow_mask, 16, 16, 1, 1);
defer if (arrow_cursor) |cursor| c.SDL_DestroyCursor(cursor);
const link_cursor = c.SDL_CreateSystemCursor(c.SDL_SYSTEM_CURSOR_POINTER);
defer if (link_cursor) |cursor| c.SDL_DestroyCursor(cursor);
// Its hot spot the middle, as acme's {-7, -7} offset puts it.
- const box_cursor = c.SDL_CreateCursor(&p9_box_set, &p9_box_mask, 16, 16, 7, 7);
+ const box_cursor = if (themed_cursors)
+ c.SDL_CreateSystemCursor(c.SDL_SYSTEM_CURSOR_MOVE)
+ else
+ c.SDL_CreateCursor(&p9_box_set, &p9_box_mask, 16, 16, 7, 7);
defer if (box_cursor) |cursor| c.SDL_DestroyCursor(cursor);
if (arrow_cursor) |cur| {
_ = c.SDL_SetCursor(cur);
@@ -2973,6 +2980,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);
@@ -3359,8 +3369,8 @@ fn setStdinRaw() !void {
term.lflag.ICANON = false;
term.lflag.IEXTEN = false;
term.lflag.ISIG = false;
- term.cc[@intFromEnum(posix.V.MIN)] = 1;
- term.cc[@intFromEnum(posix.V.TIME)] = 0;
+ term.cc[@backingInt(posix.V.MIN)] = 1;
+ term.cc[@backingInt(posix.V.TIME)] = 0;
try posix.tcsetattr(0, .NOW, term);
}
@@ -4805,7 +4815,7 @@ fn dumpThemes(ctx: ?*anyopaque, pane: u8) void {
}
fn putClipboard(gpa: std.mem.Allocator, text: []const u8) void {
- const z = gpa.dupeZ(u8, text) catch return;
+ const z = gpa.dupeSentinel(u8, text, 0) catch return;
defer gpa.free(z);
_ = c.SDL_SetClipboardText(z.ptr);
}
@@ -4939,7 +4949,7 @@ fn pollCwds(core: *pardes.Pardes, ptys: *[pardes.MAX_PANES]?Pty) void {
for (ptys, 0..) |slot, id| if (slot) |pt| {
if (pt.fd < 0) continue;
var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- if (host_io.shellCwd(pt.pid, &lbuf)) |cwd| core.setCwd(id, cwd);
+ if (host_io.ttyCwd(pt.pid, pt.fd, core.settings.shell.effective.get(), &lbuf)) |cwd| core.setCwd(id, cwd);
};
}
@@ -5130,7 +5140,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
wheelAt(&g, &in, .{ .y = 1, .integer_y = 1 }, mc);
try std.testing.expectEqualStrings("\x1b[<64;6;4M", try Sent.take(core, &sent));
wheelAt(&g, &in, .{ .y = -3, .integer_y = -3 }, mc);
- try std.testing.expectEqualStrings("\x1b[<65;6;4M" ** 3, try Sent.take(core, &sent));
+ try std.testing.expectEqualStrings(std.mem.asBytes(&@as([3][10]u8, @splat("\x1b[<65;6;4M".*))), try Sent.take(core, &sent));
try std.testing.expectEqual(@as(i32, 0), g.scroll_notch);
try std.testing.expect(g.scroll_pane == null);
// A touchpad's fractions add up to a turn.
@@ -5367,7 +5377,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
/// The glide's picture: the pane's body rows moved by the offset, and in
/// the gap it opens the rows that left, as `emitScrollRows` draws a
/// touchpad's fraction.
-fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground) u32 {
+fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 {
const glide = &g.glide;
for (surface.panelTracks()) |track|
if (track.active() and track.pane == glide.pane) return 0;
@@ -5383,10 +5393,12 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde
g.scroll_body_h = bh;
var shifted = layout;
shifted.y_off -= glide.offset * layout.h;
+ const kept = holdContext(g, surface, glide.pane, held, bh, layout);
+ shifted.y_off += kept.lift;
const cursor_idx: u32 = if (surface.cursor) |cu| @as(u32, cu.y) * surface.cols + cu.x else std.math.maxInt(u32);
const cursor_bar = if (surface.cursor) |cu| cu.bar else false;
var n: u32 = 0;
- var row = y0;
+ var row = y0 + kept.rows;
while (row < y0 + bh) : (row += 1) {
const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols];
const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null;
@@ -5400,9 +5412,9 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde
// The gap: rows past the top while the picture lags a move down, past
// the bottom for one up; as many as it opens.
const gap: u16 = @intFromFloat(@min(@ceil(@abs(glide.offset)), @as(f32, @floatFromInt(bh))));
- const kept = if (glide.offset < 0) glide.nabove else glide.nbelow;
+ const nkept = if (glide.offset < 0) glide.nabove else glide.nbelow;
const rows = if (glide.offset < 0) glide.above else glide.below;
- for (0..@min(gap, kept)) |i| {
+ for (0..@min(gap, nkept)) |i| {
const cells = rows[i * bw ..][0..bw];
// Row -1 - i above the body, or bh + i below it, in grid rows.
const at_row: i32 = if (glide.offset < 0) @as(i32, y0) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(i));
@@ -5485,7 +5497,6 @@ test "a notch scrolls the core at once and the picture glides after it, a wrappe
try std.testing.expect(!g.glide.pending and !g.glide.moving());
}
-
fn resetScroll(g: *Gui) void {
g.scroll_pane = null;
g.scroll_delta = 0;
@@ -5520,13 +5531,15 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
const down = left > 0;
left += if (down) -1 else 1;
const was = pane.scroll();
- core.update(.{ .mouse = .{
- .button = if (down) .wheel_down else .wheel_up,
- .kind = .press,
- .col = g.scroll_col,
- .row = g.scroll_row,
- .shift = true, // pardes's own scroll, never a program's wheel
- } });
+ core.update(.{
+ .mouse = .{
+ .button = if (down) .wheel_down else .wheel_up,
+ .kind = .press,
+ .col = g.scroll_col,
+ .row = g.scroll_row,
+ .shift = true, // pardes's own scroll, never a program's wheel
+ },
+ });
if (pane.scroll() == was) {
resetScroll(g);
return;
@@ -5560,8 +5573,9 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
if (g.scroll_lag == 0) resetScroll(g);
}
-fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground) u32 {
- if (g.glide.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page);
+fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 {
+ g.scroll_held_px = 0;
+ if (g.glide.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held);
const scroll_pane = g.scroll_pane orelse return 0;
if (g.scroll_lag == 0) return 0;
for (surface.panelTracks()) |track|
@@ -5575,10 +5589,12 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pard
if (x0 + bw > surface.cols or y0 + bh > surface.rows) return 0; // resized under us
var shifted = layout;
shifted.y_off -= g.scroll_lag * layout.h;
+ const kept = holdContext(g, surface, scroll_pane, held, bh, layout);
+ shifted.y_off += kept.lift;
const cursor_idx: u32 = if (surface.cursor) |cu| @as(u32, cu.y) * surface.cols + cu.x else std.math.maxInt(u32);
const cursor_bar = if (surface.cursor) |cu| cu.bar else false;
var n: u32 = 0;
- var row = y0;
+ var row = y0 + kept.rows;
while (row < y0 + bh) : (row += 1) {
const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols];
const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null;
@@ -5600,12 +5616,52 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pard
return n;
}
+/// A scrolling body's tree-sitter context rows hold still: the shifted
+/// rows start under them and are clipped below their band, and where a
+/// body layer stacks them at the tagline's height (TreeContextTagStyle)
+/// the rows under them are drawn up to meet them, where the layer has them.
+fn holdContext(g: *Gui, surface: *const pardes.Surface, id: usize, held: u16, bh: u16, layout: CellLayout) struct { rows: u16, lift: f32 } {
+ const rows = @min(held, bh);
+ const layered = id < surface.body_layers.len and surface.body_layers[id].rows != 0 and surface.body_layers[id].context_rows != 0;
+ const row_px = if (layered) std.math.clamp(@as(f32, @floatFromInt(g.tagline_height)), 1, @max(1, layout.h)) else layout.h;
+ g.scroll_held_px = @as(f32, @floatFromInt(rows)) * row_px;
+ return .{ .rows = rows, .lift = @as(f32, @floatFromInt(rows)) * (row_px - layout.h) };
+}
+
+test "a scroll's shifted rows start under the context rows, and its scissor below their band" {
+ var surface: pardes.Surface = .{};
+ var g: Gui = undefined;
+ g.tagline_height = 12;
+ g.scroll_rect = .{ .x = 0, .y = 0, .w = 40, .h = 20 };
+ g.scroll_body_y = 1;
+ g.scroll_body_h = 19;
+ const layout: CellLayout = .{ .w = 10, .h = 20, .x_off = 0, .y_off = 0 };
+ // On the grid, three body-high rows are held, and nothing moves up.
+ const grid = holdContext(&g, &surface, 0, 3, 19, layout);
+ try std.testing.expectEqual(@as(u16, 3), grid.rows);
+ try std.testing.expectEqual(@as(f32, 0), grid.lift);
+ const clip = scrollScissor(&g, layout, 400, 400);
+ try std.testing.expectEqual(@as(c_int, 20 + 3 * 20), clip.y);
+ try std.testing.expectEqual(@as(c_int, 16 * 20), clip.h);
+ // In a body layer they are tagline-high: the rows under them move up
+ // by what each is shorter, to where the layer draws them.
+ surface.body_layers[0].rows = 30;
+ surface.body_layers[0].context_rows = 3;
+ const layered = holdContext(&g, &surface, 0, 3, 19, layout);
+ try std.testing.expectEqual(@as(f32, 3 * (12 - 20)), layered.lift);
+ try std.testing.expectEqual(@as(c_int, 20 + 3 * 12), scrollScissor(&g, layout, 400, 400).y);
+ // None held: the whole body moves.
+ surface.body_layers[0].rows = 0;
+ try std.testing.expectEqual(@as(u16, 0), holdContext(&g, &surface, 0, 0, 19, layout).rows);
+ try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout, 400, 400).y);
+}
+
fn scrollScissor(g: *const Gui, layout: CellLayout, sw: u32, sh: u32) c.SDL_Rect {
const r = g.scroll_rect;
const px = layout.x_off + @as(f32, @floatFromInt(r.x + config.GUTTER)) * layout.w;
- const py = layout.y_off + @as(f32, @floatFromInt(g.scroll_body_y)) * layout.h;
+ const py = layout.y_off + @as(f32, @floatFromInt(g.scroll_body_y)) * layout.h + g.scroll_held_px;
const pw = @as(f32, @floatFromInt(r.w - config.GUTTER)) * layout.w;
- const ph = @as(f32, @floatFromInt(g.scroll_body_h)) * layout.h;
+ const ph = @max(0, @as(f32, @floatFromInt(g.scroll_body_h)) * layout.h - g.scroll_held_px);
const x0 = std.math.clamp(@as(i32, @intFromFloat(@floor(px))), 0, @as(i32, @intCast(sw)));
const y0 = std.math.clamp(@as(i32, @intFromFloat(@floor(py))), 0, @as(i32, @intCast(sh)));
const x1 = std.math.clamp(@as(i32, @intFromFloat(@ceil(px + pw))), x0, @as(i32, @intCast(sw)));
@@ -6426,7 +6482,10 @@ fn renderFrame(
}
for (groups.items[0..groups.len], 0..) |group, index|
std.debug.assert(cell_next[index] == group.cell_start + group.cell_count);
- shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page);
+ // The body's context rows, which its scroll leaves where they are.
+ const scrolling: ?usize = if (g.glide.offset != 0) g.glide.pane else g.scroll_pane;
+ const held: u16 = if (core) |p| if (scrolling) |id| if (p.panes[id]) |pane| pane.context_rows else 0 else 0 else 0;
+ shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page, held);
// Over a theme's plaques a see-through cell with no ink blends to
// the plaque under it, so it draws nothing: its quad goes, and the
// cells are drawn unblended (a third of the GPU's frame at 4K)
@@ -7108,7 +7167,7 @@ test "every pixel of a grip column is band, button or ring, and the button sits
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 60, .rows = 20 });
defer core.deinit();
- const pane = try core.setTestFile("text\n" ** 60);
+ const pane = try core.setTestFile(std.mem.asBytes(&@as([60][5]u8, @splat("text\n".*))));
pane.tag.own = try gpa.dupe(u8, "second\nthird");
core.newScratchBelow(0);
for ([_]struct { w: u32, h: u32, tag: u32 }{ .{ .w = 10, .h = 20, .tag = 12 }, .{ .w = 17, .h = 35, .tag = 30 }, .{ .w = 9, .h = 19, .tag = 15 }, .{ .w = 12, .h = 24, .tag = 24 } }) |m| for ([_]bool{ false, true }) |bottom| for ([_]usize{ 0, 1 }) |focus| for ([_]bool{ false, true }) |dirty| {
@@ -7120,6 +7179,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;
@@ -7206,7 +7268,7 @@ test "a rising pane past its mark stays inside its box" {
var g: Gui = undefined;
g.cell_w = 10;
g.cell_h = 20;
- var track: pardes.animation.Track = .{ .serial = 3, .phase = .opening, .effect = .vertical, .motion = @intFromEnum(pardes.animation.Motion.Flavour.bouncy) + 1, .frame_count = 20, .from = .{ .x = 0, .y = 10, .w = 40, .h = 10 }, .to = .{ .x = 0, .y = 0, .w = 40, .h = 10 } };
+ var track: pardes.animation.Track = .{ .serial = 3, .phase = .opening, .effect = .vertical, .motion = @backingInt(pardes.animation.Motion.Flavour.bouncy) + 1, .frame_count = 20, .from = .{ .x = 0, .y = 10, .w = 40, .h = 10 }, .to = .{ .x = 0, .y = 0, .w = 40, .h = 10 } };
var peak: u16 = 0;
var highest: f32 = 1e9;
while (track.frame < track.frames()) : (track.frame += 1) {
@@ -7428,6 +7490,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;
@@ -7527,6 +7592,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;
@@ -8743,7 +8811,6 @@ fn addPattern(g: *Gui, gpa: std.mem.Allocator, x0: f32, y0: f32, x1: f32, y1: f3
instance.effect |= checker_bit;
}
-
/// How a lift of 0 to 1 stands off the page: the shadow's blur and offset
/// in cell heights, and its darkest, where it leaves the caster's edge.
/// Within ยง8.2's budget: sigma 0.4-0.8 cell, at most 30% darker at the edge.
@@ -8881,7 +8948,6 @@ fn clipToBodies(g: *Gui, gpa: std.mem.Allocator, first: usize, bodies: []const [
};
}
-
/// Like shadowCeiling for a light colour laid over at `a` (sRGB blend, as
/// the decor pipeline blends a colour that is not black): the largest `a`
/// that keeps text and page apart by min(their contrast, 4.5).
@@ -8989,6 +9055,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);
@@ -9274,7 +9343,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);
@@ -9638,6 +9719,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);
@@ -9829,6 +9913,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;
@@ -9857,6 +9944,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 });
@@ -9871,6 +9999,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;
@@ -9906,6 +10037,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;
@@ -9942,6 +10076,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;
@@ -10006,6 +10143,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;
@@ -10054,7 +10194,7 @@ test "decor is read from the regions, each pane's in its own group" {
try std.testing.expect(tracked.decor_count >= 4);
try std.testing.expectEqual(still, groups.items[0].decor_count + tracked.decor_count);
for (g.decor.items[tracked.decor_start..][0..tracked.decor_count]) |item|
- try std.testing.expectEqual(@as(u32, @intFromEnum(pardes.animation.Transition.slide)), item.effect);
+ try std.testing.expectEqual(@as(u32, @backingInt(pardes.animation.Transition.slide)), item.effect);
// Cursors stand still while panes move.
try std.testing.expectEqual(@as(u32, 0), groups.items[groups.ink].decor_count);
}
@@ -10071,6 +10211,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;
@@ -10107,7 +10250,7 @@ test "the selection glows round its block, on the body only, fading in over 100
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
defer core.deinit();
- _ = try core.setTestFile("some text on a line\n" ** 30);
+ _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*))));
core.settings.selection_glow = true;
pardes.test_api.sync(core);
const s = try core.render(core.scratch.allocator());
@@ -10124,6 +10267,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;
@@ -10157,7 +10303,7 @@ test "a hovered word glows along its foot, never over the cursor, fading in over
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
defer core.deinit();
- _ = try core.setTestFile("some text on a line\n" ** 30);
+ _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*))));
core.settings.hover_glow = true;
pardes.test_api.sync(core);
const s = try core.render(core.scratch.allocator());
@@ -10176,6 +10322,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;
@@ -10207,7 +10356,7 @@ test "occlusion shades each body's edges, inside it, never a tag, a grip or the
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
defer core.deinit();
- _ = try core.setTestFile("some text on a line\n" ** 30);
+ _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*))));
core.settings.occlusion = true;
pardes.test_api.sync(core);
const s = try core.render(core.scratch.allocator());
@@ -10219,6 +10368,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;
@@ -10246,7 +10398,7 @@ test "a body tells its first line, and lapis's dots under it move a quarter as f
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
defer core.deinit();
- const pane = try core.setTestFile("line\n" ** 80);
+ const pane = try core.setTestFile(std.mem.asBytes(&@as([80][5]u8, @splat("line\n".*))));
pane.scrollBy(8);
try std.testing.expect(core.executeBuiltinLine(0, "Theme lapis"));
core.settings.parallax = true;
@@ -10423,7 +10575,7 @@ fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, builder: *OverlayB
fn appendWorkspacePet(g: *Gui, core: ?*const pardes.Pardes, surface: *const pardes.Surface, builder: *OverlayBuilder) void {
const p = core orelse return;
- const kind: pet.Kind = @enumFromInt(@intFromEnum(p.settings.pet));
+ const kind: pet.Kind = @fromBackingInt(@intCast(@backingInt(p.settings.pet)));
if (kind == .off or surface.rows == 0 or surface.cols == 0) {
g.pet_state = .{};
return;