diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 12:56:09 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 15:18:26 -0300 |
| commit | 88ae8456407e0ce9a2dd70ced0c53d8aa5f63fda (patch) | |
| tree | c4c805e0e729f485b8fc1ae6a26c547b2fb7d356 /src/gui/gui.zig | |
| parent | e65ada6bfab3e3851281be253b5e8187b652b66b (diff) | |
| download | pardes-88ae8456407e0ce9a2dd70ced0c53d8aa5f63fda.tar.gz pardes-88ae8456407e0ce9a2dd70ced0c53d8aa5f63fda.zip | |
the jump trail back, the frontends' alone: a jump of the cursor, three cells or more between two frames, leaves three to five cells behind it that fade in 120 ms, as the terminal's did, now seen by each frontend in the cursor of the Surface it shows and timed on its own clock (src/jump_trail.zig, shared by both); the tty tints those cells' ground toward the text again (truecolor terminals, COLORTERM read again for it), and the window draws over them in its overlay, both only on the page's own ground in the cursor's body; JumpTrail is a plain setting again (config.Runtime.jump_trail, off by default, dumped and replicated, in /ctl), which the frontends read; a frontend's trail asks for frames while it fades (shell_continuous, as its glide does)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/gui/gui.zig')
| -rw-r--r-- | src/gui/gui.zig | 77 |
1 files changed, 72 insertions, 5 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index e5ca645d..c2a4cb4e 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -14,6 +14,7 @@ const message = pardes.Messages.Message; const file_watch = @import("../file_watch.zig"); const deck = @import("deck.zig"); const pet = @import("pet.zig"); +const JumpTrail = @import("../jump_trail.zig"); const fonts = @import("../fonts.zig"); // the fallback faces const selection_pipe = @import("../selection_pipe.zig"); const c_heap = @import("c_heap"); @@ -240,9 +241,9 @@ const LoadedFallback = struct { const max_touch_points: usize = 16; const touch_scroll_tick: f32 = 0.02; -// The triangle overlay holds only the pet and the cursor's glide quad: the -// chrome is decor. -const max_overlay_vertices: usize = pet.max_vertices + 6; +// The triangle overlay holds only the pet, a jump's trail and the cursor's +// glide quad: the chrome is decor. +const max_overlay_vertices: usize = pet.max_vertices + 5 * 6 + 6; const font_px_step: f32 = 2.0; const font_px_min: f32 = 8.0; @@ -994,6 +995,8 @@ const Gui = struct { touch: Touch = .{}, /// The workspace tag's pet (Pet), on the window's own clock. pet_state: pet.State = .{}, + /// The cursor's jump trail (JumpTrail), on the window's own clock. + trail: JumpTrail = .{}, live_ctrl: bool = false, live_alt: bool = false, @@ -4553,7 +4556,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { const glide = &g.glide; // The glide runs on the core's continuous path: frames every loop, and // a virtual clock carried on. - defer core.shell_continuous = glide.moving(); + defer core.shell_continuous = glide.moving() or g.trail.active; const notch = g.scroll_notch; g.scroll_notch = 0; var wheeled: ?usize = null; @@ -5421,7 +5424,9 @@ fn renderFrame( if (!pdf_focus) core.frames.scroll = g.glide.follow.offset; core.frames.caret = caretRow(g, surface) orelse 0; const cursors_shown = !quad_mode; - var overlay_count = buildOverlay(g, core.settings.pet, surface, sw, sh); + var overlay_count = buildOverlay(g, core.settings.pet, core.settings.jump_trail and core.settings.motion != .off, surface, sw, sh); + // A trail fading asks for the frames it fades through. + if (g.trail.active) core.shell_continuous = true; if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count)) overlay_count = 0; if (!prepareNativeImages(g, gpa, cmd, surface, &groups, sw, sh)) { @@ -8060,6 +8065,7 @@ fn cursorDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, fn buildOverlay( g: *Gui, which: pardes.config.Runtime.Pet, + trail_on: bool, surface: *const pardes.Surface, sw: u32, sh: u32, @@ -8067,10 +8073,71 @@ fn buildOverlay( if (g.overlay_vertices.len == 0 or sw == 0 or sh == 0) return 0; var builder = OverlayBuilder{ .vertices = g.overlay_vertices, .win_w = @floatFromInt(sw), .win_h = @floatFromInt(sh) }; appendWorkspacePet(g, which, surface, &builder); + appendJumpTrail(g, trail_on, surface, monoNs(), &builder); appendCursorGlide(g, surface, &builder); return @intCast(builder.len); } +/// A jump's trail (jump_trail.zig): the cells behind the cursor in its +/// body, on the page's own ground, drawn over toward the text's colour. +fn appendJumpTrail(g: *Gui, on: bool, surface: *const pardes.Surface, now_ns: u64, builder: *OverlayBuilder) void { + var at: [5]JumpTrail.Cell = undefined; + const lit = g.trail.see(if (surface.cursor) |cu| .{ cu.x, cu.y } else null, on, now_ns, &at); + if (lit.len == 0) return; + const cursor = surface.cursor.?; + const body = for (surface.regionList()) |region| { + if (region.kind == .body and cursor.x >= region.rect.x and cursor.x < @as(u32, region.rect.x) + region.rect.w and + cursor.y >= region.rect.y and cursor.y < @as(u32, region.rect.y) + region.rect.h) break region.rect; + } else return; + const page = surface.chrome.page orelse bg_default; + const w: f32 = @floatFromInt(g.cell_w); + const h: f32 = @floatFromInt(g.cell_h); + for (lit) |cell| { + if (cell.x < body.x or cell.y < body.y or cell.x >= @as(i32, body.x) + body.w or cell.y >= @as(i32, body.y) + body.h) continue; + const under = &surface.cells[@as(usize, @intCast(cell.y)) * surface.cols + @as(usize, @intCast(cell.x))]; + // On the page's own ground alone: never a selection or a match. + const ground: [3]u8 = if (under.default) page else switch (under.style.bg) { + .rgb => |rgb| rgb, + else => page, + }; + if (!std.mem.eql(u8, &ground, &page)) continue; + var color = overlayRgb(surface.chrome.fg orelse fg_default); + color.a = cell.strength; + const x0 = @as(f32, @floatFromInt(cell.x)) * w; + const y0 = @as(f32, @floatFromInt(cell.y)) * h; + builder.addRect(x0, y0, x0 + w, y0 + h, color); + } +} + +test "a jump's trail is drawn behind the cursor in its body, and gone by 120 ms" { + var cells: [80 * 4]pardes.Cell = @splat(.{}); + var surface: pardes.Surface = .{ .cols = 80, .rows = 4, .cells = &cells }; + surface.regions[0] = .{ .kind = .body, .rect = .{ .x = 2, .y = 0, .w = 78, .h = 4 } }; + surface.nregions = 1; + var g = testGui(10, 20, 8, 16); + var vertices: [5 * 6]OverlayVertex = undefined; + var builder: OverlayBuilder = .{ .vertices = &vertices, .win_w = 800, .win_h = 80 }; + const ms = std.time.ns_per_ms; + surface.cursor = .{ .x = 4, .y = 1 }; + appendJumpTrail(&g, true, &surface, 1000 * ms, &builder); + try std.testing.expectEqual(@as(usize, 0), builder.len); + surface.cursor = .{ .x = 14, .y = 1 }; + appendJumpTrail(&g, true, &surface, 1016 * ms, &builder); + try std.testing.expect(builder.len >= 3 * 6 and builder.len <= 5 * 6); + // On the cursor's row, behind it, never its own cell. + for (vertices[0..builder.len]) |v| { + const x = (v.x + 1) * 400; + const y = (1 - v.y) * 40; + try std.testing.expect(y >= 20 - 0.01 and y <= 40 + 0.01); + try std.testing.expect(x >= 50 - 0.01 and x <= 140 + 0.01); + } + try std.testing.expect(g.trail.active); + builder.len = 0; + appendJumpTrail(&g, true, &surface, 1150 * ms, &builder); + try std.testing.expectEqual(@as(usize, 0), builder.len); + try std.testing.expect(!g.trail.active); +} + /// The workspace tag's pet (the Pet setting, gui/pet.zig): in the blank /// end of the grid's first row, past the tag's text, in the tag's colours, /// on the window's own clock. Nothing of it reaches the core. |
