summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/next-anim.md25
-rw-r--r--src/FrameStats.zig12
-rw-r--r--src/animation.zig42
-rw-r--r--src/draw.zig73
-rw-r--r--src/gui/gui.zig85
5 files changed, 181 insertions, 56 deletions
diff --git a/docs/next-anim.md b/docs/next-anim.md
index 1acdeacf..a64bfaf4 100644
--- a/docs/next-anim.md
+++ b/docs/next-anim.md
@@ -182,6 +182,31 @@ absorbed by what the system is doing:
| moving | an input the other way | the stream ends; the spring turns it through zero from its speed |
| moving | a jump past what two frames share | its rows are added (the stitched slide); the speed carries on |
+The caret is its own body (anim 10): its state is its own springs
+(`CursorGlide`, screen cells as floats), integrated on the same tick, and
+it is drawn from that state only, never from the text's glide (the ride
+that lifted it with the glide's fractional lag is deleted: every motion
+of the text had leaked into it). Its only coupling to the view is its
+target: its cell in the view as it will be once settled (the core's view
+is that one).
+
+| an input | the caret's target | it does |
+|---|---|---|
+| a page or half page, a scroll that keeps its screen row (Ctrl-f/b/d/u, PageDown/Up, a j or k at the edge row) | unchanged | not a pixel's move while the text slides under it |
+| a move in a still view (h/j/k/l, w, a click, a typed character) | the new cell | the short ease |
+| a stream of such moves (a held key, typing) | each new cell | lands on each, at the keys' rate |
+| a scroll that carries its line (the wheel, Ctrl-o to a far place in view) | where its line will be | moves there whole, at the view's pace, and lands exactly |
+| a jump that moves both (G, a Look) | the final cell | one ease, no trip with the old page |
+| a terminal's output | its cell | lands with the output (which does not glide) |
+| Motion off | the cell | there at once |
+
+While a glide moves the text the caret is drawn as its quad (from its
+springs), not as a cell of the moving rows. Invariants, checked over every
+frame of the scripted scroll and held-key runs (`GlideRun.checkCaret`):
+while its cell stays and it is on it, its drawn row is identical frame to
+frame; it only closes on its cell; it lands within half a second of its
+last change. The blink keys off the last key or click, never a frame.
+
So a held j, a spun wheel and a held Ctrl-d are the same case (a stream),
a single j or notch the same ease as before. Every input, a repeat too,
is still drawn at once: in a stream the picture is on the stream's
diff --git a/src/FrameStats.zig b/src/FrameStats.zig
index 0b252ff9..ee5ee3f2 100644
--- a/src/FrameStats.zig
+++ b/src/FrameStats.zig
@@ -45,8 +45,10 @@ pub const Frame = struct {
/// The shell had no image to draw into (a busy swapchain).
skipped: bool = false,
/// The shell's motion in it: a scroll's picture offset from the text,
- /// rows (0 at rest).
+ /// rows (0 at rest), and where it drew the caret, its top in rows
+ /// (the jitter check: a caret on a fixed row must not wobble).
scroll: f32 = 0,
+ caret: f32 = 0,
/// From the first input this frame answers to its present's end, µs;
/// 0 when it answers none.
latency_us: u32 = 0,
@@ -84,6 +86,7 @@ skipped: u64 = 0,
/// What the shell sets while it draws the frame (Frame.scroll), and the
/// pump (view).
scroll: f32 = 0,
+caret: f32 = 0,
view: i32 = 0,
/// The first input not yet answered by a drawn frame, monotonic ns.
input_ns: u64 = 0,
@@ -146,6 +149,7 @@ pub fn record(stats: *FrameStats, end_ns: u64, moving: bool, skipped: bool) void
.moving = stats.armed,
.skipped = skipped,
.scroll = stats.scroll,
+ .caret = stats.caret,
.latency_us = if (stats.input_ns == 0) 0 else @max(1, us.of(stats.input_ns, end_ns)),
.view = stats.view,
.zones = stats.zone_us,
@@ -263,13 +267,13 @@ pub fn dump(stats: *const FrameStats, path: [:0]const u8) void {
.phase => |name| write.line(fd, &buf, "# phase {s} {d:.1}\n", .{ name, @as(f64, @floatFromInt((stats.demo_ns + @as(u64, step.at_ms) * std.time.ns_per_ms) -| t0)) / std.time.ns_per_ms }),
else => {},
};
- write.line(fd, &buf, "# start_ms\tupdate_us\trender_us\tpresent_us\tgap_us\tmoving\tskipped\tscroll\tlatency_us\tview", .{});
+ write.line(fd, &buf, "# start_ms\tupdate_us\trender_us\tpresent_us\tgap_us\tmoving\tskipped\tscroll\tcaret\tlatency_us\tview", .{});
inline for (comptime std.enums.values(Zone)) |which| write.line(fd, &buf, "\t{t}_us", .{which});
write.line(fd, &buf, "\tshaped\trastered\tbytes\n", .{});
for (all) |part| for (part) |f| {
- write.line(fd, &buf, "{d:.3}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d:.4}\t{d}\t{d}", .{
+ write.line(fd, &buf, "{d:.3}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d}\t{d:.4}\t{d:.4}\t{d}\t{d}", .{
@as(f64, @floatFromInt(f.start_ns -| t0)) / std.time.ns_per_ms, f.update_us, f.render_us, f.present_us, f.gap_us,
- @intFromBool(f.moving), @intFromBool(f.skipped), f.scroll, f.latency_us, f.view,
+ @intFromBool(f.moving), @intFromBool(f.skipped), f.scroll, f.caret, f.latency_us, f.view,
});
for (f.zones) |us| write.line(fd, &buf, "\t{d}", .{us});
write.line(fd, &buf, "\t{d}\t{d}\t{d}\n", .{ f.shaped, f.rastered, f.bytes });
diff --git a/src/animation.zig b/src/animation.zig
index 63a40cbf..ae6f9ca0 100644
--- a/src/animation.zig
+++ b/src/animation.zig
@@ -964,6 +964,8 @@ pub const CursorGlide = struct {
target: Box = .{},
from_centre: [2]f32 = .{ 0, 0 },
placed: bool = false,
+ /// When the last step (a move of a cell or less) came.
+ step_ns: u64 = 0,
/// How much faster than the flavour's own pace a cursor moves: it
/// follows input (§8.1: settles in 90-150 ms on the default).
@@ -972,6 +974,9 @@ pub const CursorGlide = struct {
pub const arc_from: f32 = 8;
/// How much stiffer a step's spring is than a jump's.
pub const step_pace: f32 = 1.5;
+ /// Steps this close are a stream (a held key, typing): each lands, the
+ /// caret at the keys' own rate, as an eased step a key would bounce.
+ pub const stream_ns: u64 = 150 * std.time.ns_per_ms;
fn cornersOf(box: Box) [4][2]f32 {
return .{ .{ box.x, box.y }, .{ box.x + box.w, box.y }, .{ box.x + box.w, box.y + box.h }, .{ box.x, box.y + box.h } };
@@ -982,16 +987,27 @@ pub const CursorGlide = struct {
}
/// Heads for `box` at `now_ns`.
- pub fn aim(glide: *CursorGlide, box: Box, now_ns: u64, motion: Motion, snap: bool) void {
+ /// How a new mark is gone to: eased (a step, or a jump's smear and
+ /// bow), landed at once, or moved whole at a scroll's pace (the text
+ /// moved under it, not the caret).
+ pub const How = enum { ease, land, rigid };
+
+ pub fn aim(glide: *CursorGlide, box: Box, now_ns: u64, motion: Motion, how: How) void {
// The same mark: nothing to do, unless a snap lands a glide under way.
- if (glide.placed and std.meta.eql(box, glide.target) and !(snap and glide.moving())) return;
+ if (glide.placed and std.meta.eql(box, glide.target) and !(how == .land and glide.moving())) return;
const to = cornersOf(box);
const from_c = if (glide.placed) glide.centreAt(now_ns) else centre(box);
const to_c = centre(box);
const dx = to_c[0] - from_c[0];
const dy = to_c[1] - from_c[1];
const jump = @abs(dx) > 1.01 or @abs(dy) > 1.01;
- const land = !glide.placed or snap or motion.instant;
+ // A step is measured mark to mark, not from where an ease under way
+ // has got to (a held key's steps read as jumps from there).
+ const last = centre(glide.target);
+ const one_step = glide.placed and @abs(to_c[0] - last[0]) <= 1.01 and @abs(to_c[1] - last[1]) <= 1.01;
+ const streaming = one_step and glide.step_ns != 0 and now_ns -| glide.step_ns < stream_ns;
+ if (one_step) glide.step_ns = now_ns;
+ const land = !glide.placed or how == .land or motion.instant or streaming;
glide.from_centre = from_c;
glide.target = box;
glide.placed = true;
@@ -999,9 +1015,11 @@ pub const CursorGlide = struct {
// Leading: the corner ahead of the move, on the side it goes.
const ahead = (point[0] - to_c[0]) * dx + (point[1] - to_c[1]) * dy;
var own = motion;
- own.omega *= if (jump) pace * (if (ahead > 0) 1 else motion.follow) else pace * step_pace;
- // A step neither winds up nor overshoots: it is a caret moving.
- if (!jump) {
+ own.omega *= if (how == .rigid) 1.5 else if (jump) pace * (if (ahead > 0) 1 else motion.follow) else pace * step_pace;
+ // A step neither winds up nor overshoots: it is a caret moving;
+ // nor a whole move with the text (rigid: at the view's pace,
+ // Glide's 1.5x, its corners together).
+ if (!jump or how == .rigid) {
own.zeta = 1;
own.anticipate = 0;
}
@@ -1121,10 +1139,10 @@ test "a cursor eases a cell at a time, keeps up with typing, and glides a jump,
const smooth_motion = Motion.of(.smooth);
var glide: CursorGlide = .{};
const cell: Box = .{ .x = 3, .y = 4, .w = 1, .h = 1 };
- glide.aim(cell, 0, smooth_motion, false);
+ glide.aim(cell, 0, smooth_motion, .ease);
try std.testing.expect(!glide.moving());
// One cell over: eases there whole, no wider than a cell, in ~60 ms.
- glide.aim(.{ .x = 4, .y = 4, .w = 1, .h = 1 }, ms, smooth_motion, false);
+ glide.aim(.{ .x = 4, .y = 4, .w = 1, .h = 1 }, ms, smooth_motion, .ease);
try std.testing.expect(glide.moving());
var step_t: u64 = ms;
while (glide.step(step_t)) : (step_t += ms) {
@@ -1132,21 +1150,21 @@ test "a cursor eases a cell at a time, keeps up with typing, and glides a jump,
try std.testing.expect(q[1][0] - q[0][0] <= 1.0 + 1e-3 and q[0][0] >= 3 - 1e-3 and q[0][0] <= 4 + 1e-3);
}
try std.testing.expect(step_t - ms >= 30 * ms and step_t - ms <= 90 * ms);
- // At a keyboard's repeat it keeps up: about half a cell behind.
+ // At a keyboard's repeat the steps are a stream: each lands.
var typed: f32 = 4;
var key_t: u64 = step_t;
for (0..20) |_| {
typed += 1;
- glide.aim(.{ .x = typed, .y = 4, .w = 1, .h = 1 }, key_t, smooth_motion, false);
+ glide.aim(.{ .x = typed, .y = 4, .w = 1, .h = 1 }, key_t, smooth_motion, .ease);
key_t += 33 * ms;
try std.testing.expect(typed - glide.sample(key_t, smooth_motion)[0][0] <= 0.6);
}
while (glide.step(key_t)) key_t += ms;
// A jump of 30 cells: glides, the leading edge ahead of the trailing one.
- glide.aim(cell, key_t, smooth_motion, true);
+ glide.aim(cell, key_t, smooth_motion, .land);
const j0 = key_t;
const far: Box = .{ .x = 34, .y = 4, .w = 1, .h = 1 };
- glide.aim(far, j0 + 2 * ms, smooth_motion, false);
+ glide.aim(far, j0 + 2 * ms, smooth_motion, .ease);
try std.testing.expect(glide.moving());
const mid = glide.sample(j0 + 40 * ms, smooth_motion);
const width = mid[1][0] - mid[0][0];
diff --git a/src/draw.zig b/src/draw.zig
index 265e07c1..e3ab9f2a 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -239,8 +239,8 @@ fn glideCursor(p: *Pardes, s: *Surface) void {
};
const motion = animation.Motion.of(p.settings.motion);
// The thin insert-mode caret glides as the block does (a jump smears
- // and bows, a step eases); only a scroll, below, lands it.
- var snap = false;
+ // and bows, a step eases); a scroll moves it rigidly, below.
+ var how: animation.CursorGlide.How = .ease;
var frame: PaneFrame = .{};
// In a column's or the workspace's tag the cursor is not the pane's,
// and does not move with it.
@@ -259,14 +259,14 @@ fn glideCursor(p: *Pardes, s: *Surface) void {
// The pane moved in the layout: the springs move with it (its
// own cursor's; one in a column's tag stays).
if (inside) p.cursor_glide.shift(origin[0] - view.origin[0], origin[1] - view.origin[1]);
- // Scrolled (a file's view, a terminal's output): the quad moves
- // with the text and lands, never gliding against text that
- // jumped (every Enter at a prompt scrolls one and moves the
- // other).
- if (inside and line != view.line) {
- p.cursor_glide.shift(0, @floatFromInt(view.line - line));
- snap = true;
- }
+ // Scrolled (a file's view, a terminal's output): the caret is its
+ // own body, drawn from its own springs only, never from the text's
+ // glide. Its mark is where it will be once the view settles (its
+ // cell now: the core's view is that one), so a page that keeps its
+ // row leaves it still, and a scroll that carries its line moves
+ // it there whole, at the view's pace, not as a jump's smear. A
+ // terminal's output scrolls it with no glide: it lands with it.
+ if (inside and line != view.line) how = if (pane.isTerminal()) .land else .rigid;
} else if (view.serial != 0 and p.cursor_glide.placed) {
// Focus moved (to another pane, or between a pane and a
// column's or the workspace's tag): the glide starts where the
@@ -290,7 +290,7 @@ fn glideCursor(p: *Pardes, s: *Surface) void {
// A click that took focus places the cursor on its release; aimed at
// the pane's old cursor meanwhile, it would glide there first.
if (p.drag != .select) p.cursor_held = false;
- if (!p.cursor_held) p.cursor_glide.aim(box, p.now_ns, motion, snap);
+ if (!p.cursor_held) p.cursor_glide.aim(box, p.now_ns, motion, how);
_ = p.cursor_glide.step(p.now_ns);
const moving = p.cursor_glide.moving();
if (!moving and !p.cursor_held) p.cursor_crossing = false;
@@ -1971,6 +1971,57 @@ test "each Motion flavour reaches the lift as its own trajectory" {
try std.testing.expect(peaks[2] <= 1.001 and peaks[3] > 1.25 and peaks[4] > peaks[3]);
}
+test "the caret is its own body: a page leaves it still under the moving text, a wheel scroll moves it whole to its line's new row" {
+ if (!builtins.capabilities.lift) return error.SkipZigTest;
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 });
+ defer p.deinit();
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(std.testing.allocator);
+ for (0..400) |i| try text.print(std.testing.allocator, "line {d}\n", .{i});
+ const pane = try p.setTestFile(text.items);
+ p.settings.cursor_blink = false;
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ var now: u64 = std.time.ns_per_s;
+ p.advance(now);
+ // Mid-file, where a half page keeps the caret's row.
+ for ("200G") |ch| p.update(.{ .key = .{ .cp = ch, .text = &.{ch} } });
+ _ = try p.render(arena.allocator());
+ now += std.time.ns_per_s;
+ p.advance(now);
+ _ = arena.reset(.retain_capacity);
+ _ = try p.render(arena.allocator());
+ // Ctrl-d: the caret moves with the view and keeps its screen row: it
+ // does not ride the glide, and it does not move.
+ const row_before = (try p.render(arena.allocator())).cursor.?.y;
+ p.update(.{ .key = .{ .cp = 'd', .ctrl = true } });
+ now += 16 * std.time.ns_per_ms;
+ p.advance(now);
+ _ = arena.reset(.retain_capacity);
+ var s = try p.render(arena.allocator());
+ try std.testing.expect(pane.file.?.scroll > 0);
+ try std.testing.expectEqual(row_before, s.cursor.?.y);
+ try std.testing.expectEqual(@as(u8, 0), s.chrome.cursor_glide & 1);
+ try std.testing.expectEqual(@as(f32, @floatFromInt(row_before)), s.chrome.cursor_quad[1]);
+ // The view scrolled with the caret on its line: it heads for the
+ // line's new row whole (every corner the same way), and lands on it.
+ pane.scrollBy(-3);
+ now += 16 * std.time.ns_per_ms;
+ p.advance(now);
+ _ = arena.reset(.retain_capacity);
+ s = try p.render(arena.allocator());
+ const mark: f32 = @floatFromInt(s.cursor.?.y);
+ try std.testing.expect(s.chrome.cursor_glide & 1 != 0 and s.chrome.cursor_quad[1] < mark);
+ try std.testing.expectApproxEqAbs(s.chrome.cursor_quad[3] - s.chrome.cursor_quad[1], s.chrome.cursor_quad[5] - s.chrome.cursor_quad[7], 1e-4);
+ while (p.continuous()) {
+ now += 7 * std.time.ns_per_ms;
+ p.advance(now);
+ _ = arena.reset(.retain_capacity);
+ s = try p.render(arena.allocator());
+ }
+ try std.testing.expectEqual(mark, s.chrome.cursor_quad[1]);
+}
+
test "the focused cursor glides a jump, eases a step, the thin caret too, and is exact at rest" {
if (!builtins.capabilities.lift) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 });
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 8163581a..3f7dd7ca 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -5428,8 +5428,6 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde
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;
// Only the rows the scissor shows: lagging a body or more, every body
// row is past the edge, and drawing them all was twice the frame's
@@ -5442,8 +5440,9 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde
const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null;
var col = x0;
while (col < x0 + bw) : (col += 1) {
- const sidx: u32 = @as(u32, row) * surface.cols + col;
- emitInstance(g, instances, base + n, col, row, shifted, win_w, win_h, null, cellFontRole(surface.at(col, row)), line, col, row_cursor, false, sidx == cursor_idx and !cursor_bar, page);
+ // No caret among the moving rows: it is drawn from its own
+ // springs (the quad), never carried by the text's glide.
+ emitInstance(g, instances, base + n, col, row, shifted, win_w, win_h, null, cellFontRole(surface.at(col, row)), line, col, row_cursor, false, false, page);
n += 1;
}
}
@@ -5545,6 +5544,8 @@ const GlideRun = struct {
const Step = struct { frame: usize, key: pardes.Key };
offsets: [600]f32 = undefined,
lines: [600]i64 = undefined,
+ carets: [600]f32 = undefined,
+ cells: [600]f32 = undefined,
frames: usize = 0,
fn play(seq: *GlideRun, g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator, arena: *std.heap.ArenaAllocator, script: []const Step, frames: usize) !void {
@@ -5561,10 +5562,27 @@ const GlideRun = struct {
if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion);
seq.offsets[frame] = g.glide.offset;
seq.lines[frame] = @intCast(core.panes[core.active].?.file.?.scroll);
+ seq.carets[frame] = caretRow(g, s) orelse -1;
+ seq.cells[frame] = if (s.cursor) |cu| @floatFromInt(cu.y) else -1;
}
seq.frames = frames;
}
+ /// The caret's invariants over the run: while its cell stays and it is
+ /// on it, it does not move a pixel; it only ever closes on its cell (a
+ /// twentieth of a row of play for a jump's bow); it lands within half a
+ /// second of its last change.
+ fn checkCaret(seq: *const GlideRun) !void {
+ var changed: usize = 0;
+ for (1..seq.frames) |k| {
+ if (seq.cells[k] < 0 or seq.cells[k - 1] < 0) continue;
+ if (seq.cells[k] != seq.cells[k - 1]) changed = k;
+ if (seq.cells[k] == seq.cells[k - 1] and seq.carets[k - 1] == seq.cells[k - 1]) try std.testing.expectEqual(seq.carets[k - 1], seq.carets[k]);
+ try std.testing.expect(@abs(seq.carets[k] - seq.cells[k]) <= @abs(seq.carets[k - 1] - seq.cells[k]) + 0.05);
+ if (k - changed == 30) try std.testing.expectEqual(seq.cells[k], seq.carets[k]);
+ }
+ }
+
/// Frames from `from` until the picture is still: the scroll's glide.
fn settle(seq: *const GlideRun, from: usize) usize {
var k = from;
@@ -5618,6 +5636,7 @@ test "every scroll glides on one law: a half page, a page, the far jumps, a run
};
var seq: GlideRun = .{};
try seq.play(&g, core, gpa, &arena, &script, 240);
+ try seq.checkCaret();
// Every one moves the picture on the frame it is drawn in, and the
// picture lags by what the core moved (a far jump, by one body).
var longest: usize = 0;
@@ -5692,9 +5711,24 @@ test "a held key moves the view at the stream's own rate, never a bounce a line,
most = @max(most, step);
}
try std.testing.expect(seq.lines[89] > 0 and least > 0.4 and most < 0.6);
+ // The caret stays on its row, the text moving under it: not a pixel's
+ // wobble (the glide's fractional lag never reaches it).
+ for (90..110) |k| try std.testing.expectEqual(seq.carets[89], seq.carets[k]);
// It comes to rest once the keys stop, never past its mark.
for (110..200) |k| try std.testing.expect(seq.offsets[k] <= 0);
try std.testing.expectEqual(@as(f32, 0), seq.offsets[199]);
+ // Ctrl-d held, then PageDown held: the caret keeps its row the whole
+ // way, the pages moving under it.
+ var pages: [40]GlideRun.Step = undefined;
+ for (&pages, 0..) |*step, i| step.* = .{ .frame = 10 + 2 * i, .key = if (i < 20) .{ .cp = 'd', .ctrl = true } else .{ .cp = pardes.Key.page_down } };
+ var held: GlideRun = .{};
+ try held.play(&g, core, gpa, &arena, &pages, 100);
+ try held.checkCaret();
+ try seq.checkCaret();
+ // (The first of each may move it, one ease: from the last row to where
+ // a half page keeps it, and from there to a page's.)
+ for (30..50) |k| try std.testing.expectEqual(held.carets[30], held.carets[k]);
+ for (70..90) |k| try std.testing.expectEqual(held.carets[70], held.carets[k]);
}
fn resetScroll(g: *Gui) void {
@@ -6427,12 +6461,15 @@ fn renderFrame(
// while it glides or blinks. One or the other every frame (none only at
// a blink's off half).
const blink_alpha: f32 = if (blinkNow(g, chrome)) |b| b.alpha else 1;
- const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1);
+ // While a glide moves the text, the caret is its quad, drawn from its
+ // own springs, not a cell of the moving rows.
+ const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1 or g.glide.offset != 0);
g.cursor_quad_alpha = if (quad_mode) chrome.cursor_alpha * blink_alpha else 0;
// The probe's view of this frame's motion (FrameStats.Frame).
if (core) |p| {
const probe = &@constCast(p).frames;
probe.scroll = g.glide.offset;
+ probe.caret = caretRow(g, surface) orelse 0;
}
const cursors_shown = groups.tracks == 0 and !quad_mode;
var overlay_count = buildOverlay(g, core, surface, sw, sh, debug_on);
@@ -10713,37 +10750,32 @@ fn postSpare(surface: *const pardes.Surface, layout: CellLayout, out: *[Post.max
const CursorBox = Post.Frame.Cursor;
const max_cursors = 1 + pardes.MAX_PANES + pardes.MAX_TAG_LAYERS;
+/// Where the frame draws the focused caret, its top in grid rows: from its
+/// own springs (the quad's, while it moves or while a glide moves the text)
+/// or its cell; never from the text's glide. The probe records it and the
+/// glide tests hold its invariants.
+fn caretRow(g: *const Gui, surface: *const pardes.Surface) ?f32 {
+ const chrome = &surface.chrome;
+ const cursor = surface.cursor orelse return null;
+ const quad = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or g.glide.offset != 0);
+ return if (quad) chrome.cursor_quad[1] else @floatFromInt(cursor.y);
+}
+
/// Every cursor on the frame where it is drawn, in window pixels: the grid's
/// where no layer has its cell, and each layer's at that layer's pitch. A bar
/// is an eighth of its cell wide, a block the whole cell.
-/// Where a scroll's glide draws grid cell (col, row): its pixels down from
-/// where the grid has it (the picture lags the text), and whether it is
-/// still in the gliding body at all; nothing moved off a glide.
-fn glideLift(g: *const Gui, col: f32, row: f32, layout: CellLayout) struct { px: f32, shown: bool } {
- const glide = &g.glide;
- if (glide.offset == 0) return .{ .px = 0, .shown = true };
- const r = glide.rect;
- const top: f32 = @floatFromInt(glide.body_y);
- const bottom = top + @as(f32, @floatFromInt(glide.body_h));
- if (col < @as(f32, @floatFromInt(r.x + config.GUTTER)) or col >= @as(f32, @floatFromInt(r.x + r.w)) or row < top or row >= bottom) return .{ .px = 0, .shown = true };
- const at = row - glide.offset;
- return .{ .px = -glide.offset * layout.h, .shown = at >= top and at + 1 <= bottom + 0.5 };
-}
-
fn cursorBoxes(g: *const Gui, surface: *const pardes.Surface, layout: CellLayout, win_h: f32, out: *[max_cursors]CursorBox) usize {
const chrome = &surface.chrome;
const page = chrome.page orelse bg_default;
var n: usize = 0;
if (surface.cursor) |cursor| {
- // A scroll's glide carries the cursor with the text it is in.
- const lift = glideLift(g, @floatFromInt(cursor.x), @floatFromInt(cursor.y), layout);
- if (lift.shown and cursor.x < surface.cols and cursor.y < surface.rows and bodyLayerAt(surface, cursor.x, cursor.y) == null and tagLayerIn(surface.tagLayers(), cursor.x, cursor.y) == null) {
+ if (cursor.x < surface.cols and cursor.y < surface.rows and bodyLayerAt(surface, cursor.x, cursor.y) == null and tagLayerIn(surface.tagLayers(), cursor.x, cursor.y) == null) {
const cell = &surface.cells[@as(usize, cursor.y) * surface.cols + cursor.x];
const role = cellFontRole(cell);
const width: f32 = if (role == .tagline) @floatFromInt(g.tagline_width) else layout.w;
const height = std.math.clamp(if (role == .tagline) @as(f32, @floatFromInt(g.tagline_height)) else layout.h, 1.0, layout.h);
const x0 = @as(f32, @floatFromInt(cursor.x)) * layout.w;
- const y0 = @as(f32, @floatFromInt(cursor.y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(cursor.y, win_h, @intFromFloat(layout.h), @intFromFloat(height)))) + lift.px;
+ const y0 = @as(f32, @floatFromInt(cursor.y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(cursor.y, win_h, @intFromFloat(layout.h), @intFromFloat(height))));
out[n] = .{ .x0 = x0, .y0 = y0, .x1 = x0 + if (cursor.bar) @max(dp(1), width / 8.0) else width, .y1 = y0 + height, .rgb = cursorColor(chrome, cell, role), .text = page, .bar = cursor.bar };
n += 1;
}
@@ -10816,13 +10848,8 @@ fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, builder: *OverlayB
const layout = fixedCellLayout(g);
var px: [4][2]f32 = undefined;
var centre: [2]f32 = .{ 0, 0 };
- // A scroll's glide carries the quad with the text, by where its centre is.
- var cell_centre: [2]f32 = .{ 0, 0 };
- for (0..4) |i| cell_centre = .{ cell_centre[0] + chrome.cursor_quad[i * 2] / 4, cell_centre[1] + chrome.cursor_quad[i * 2 + 1] / 4 };
- const lift = glideLift(g, cell_centre[0], cell_centre[1], layout);
- if (!lift.shown) return;
for (&px, 0..) |*point, i| {
- point.* = .{ chrome.cursor_quad[i * 2] * layout.w, chrome.cursor_quad[i * 2 + 1] * layout.h + lift.px };
+ point.* = .{ chrome.cursor_quad[i * 2] * layout.w, chrome.cursor_quad[i * 2 + 1] * layout.h };
centre[0] += point[0] / 4;
centre[1] += point[1] / 4;
}