summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 14:32:27 -0300
committerGabriel Schneider <[email protected]>2026-10-24 20:59:59 -0300
commita87f917559e3712d36e5809d1f457fbf78c8266e (patch)
treef22bcaa16e1b4f384f0def5c46acab814796cd84 /src/gui
parent114757fa94bd38b7620589709965d5f46e317b12 (diff)
downloadpardes-a87f917559e3712d36e5809d1f457fbf78c8266e.tar.gz
pardes-a87f917559e3712d36e5809d1f457fbf78c8266e.zip
anim 4: the thin insert-mode cursor glides as the block does, a small move eases instead of landing, and the cursor rides a scroll's glide with its text
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.zig27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index be92fb18..1a56ecd0 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -10586,18 +10586,34 @@ const max_cursors = 1 + pardes.MAX_PANES + pardes.MAX_TAG_LAYERS;
/// 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| {
- 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) {
+ // 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) {
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))));
+ const y0 = @as(f32, @floatFromInt(cursor.y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(cursor.y, win_h, @intFromFloat(layout.h), @intFromFloat(height)))) + lift.px;
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;
}
@@ -10670,8 +10686,13 @@ 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 };
+ point.* = .{ chrome.cursor_quad[i * 2] * layout.w, chrome.cursor_quad[i * 2 + 1] * layout.h + lift.px };
centre[0] += point[0] / 4;
centre[1] += point[1] / 4;
}