diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/glide.zig | 51 | ||||
| -rw-r--r-- | src/gui/gui.zig | 32 |
2 files changed, 71 insertions, 12 deletions
diff --git a/src/glide.zig b/src/glide.zig index 6f8fe9a3..1c49d8e8 100644 --- a/src/glide.zig +++ b/src/glide.zig @@ -59,6 +59,11 @@ pub const Glide = struct { /// first line, text and place, so a view that moved since is found /// whatever moved it. seen: [pardes.MAX_PANES]struct { serial: u32 = 0, line: i32 = 0, doc: u64 = 0, rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 } } = @splat(.{}), + /// Each body's rows held at its top while it scrolls (a source's + /// sticky context rows, TreeContext), its frontend's to say: they do + /// not move, so a move is measured, and the rows that left are kept, + /// below them. + held: [pardes.MAX_PANES]u16 = @splat(0), /// The last frame's cells, which a move is measured against. last: []pardes.Cell = &.{}, last_cols: u16 = 0, @@ -189,9 +194,12 @@ pub const Glide = struct { /// the rows of `surface` against `before`; keeps the rows that left. fn measure(glide: *Glide, gpa: std.mem.Allocator, surface: *const pardes.Surface) void { const w = glide.bw(); - const h = glide.body_h; const x0 = glide.rect.x + config.GUTTER; - if (w == 0 or h == 0 or x0 + w > surface.cols or glide.body_y + h > surface.rows or glide.before.len < @as(usize, w) * h) return glide.stop(); + if (w == 0 or glide.body_h == 0 or x0 + w > surface.cols or glide.body_y + glide.body_h > surface.rows or glide.before.len < @as(usize, w) * glide.body_h) return glide.stop(); + // The rows under the held ones (`held`) are what scrolls: `before` + // and the frame are compared, and kept, from there. + const top = @min(glide.held[glide.pane], glide.body_h -| 1); + const h = glide.body_h - top; const now = struct { fn row(s: *const pardes.Surface, x: u16, y: u16, n: u16) []const pardes.Cell { return s.cells[@as(usize, y) * s.cols + x ..][0..n]; @@ -209,8 +217,9 @@ pub const Glide = struct { var misses: usize = 0; for (0..height - kk) |r| { const rr: u16 = @intCast(r); - const old_row = gl.before[@as(usize, if (gl.dir > 0) rr + kk else rr) * width ..][0..width]; - const new_row = now.row(surf, x, gl.body_y + if (gl.dir > 0) rr else rr + kk, width); + const held = @min(gl.held[gl.pane], gl.body_h -| 1); + const old_row = gl.before[@as(usize, held + if (gl.dir > 0) rr + kk else rr) * width ..][0..width]; + const new_row = now.row(surf, x, gl.body_y + held + if (gl.dir > 0) rr else rr + kk, width); if (!sameRow(old_row, new_row)) { misses += 1; if (misses > allowed) return false; @@ -249,7 +258,7 @@ pub const Glide = struct { const kept = @min(count.*, h * reach - shift); std.mem.copyBackwards(pardes.Cell, keep.*[@as(usize, shift) * w ..][0 .. @as(usize, kept) * w], keep.*[0 .. @as(usize, kept) * w]); for (0..shift) |i| { - const src_row: usize = if (glide.dir > 0) shift - 1 - i else h - shift + i; + const src_row: usize = top + if (glide.dir > 0) shift - 1 - i else h - shift + i; @memcpy(keep.*[i * w ..][0..w], glide.before[src_row * w ..][0..w]); } count.* = kept + shift; @@ -423,3 +432,35 @@ test "a follow comes to rest without a snap: past its fastest frame each step is try std.testing.expect(last <= 0.1); } } + +test "a body scrolling under held rows (sticky context) is measured, and keeps the rows that left, below them" { + const gpa = std.testing.allocator; + // A body 10 rows high whose first 3 hold still (a source's context + // rows) while the lines under them scroll one. + var cells: [2][24 * 12]pardes.Cell = undefined; + var frames: [2]pardes.Surface = undefined; + for (&frames, &cells, [_]u16{ 10, 11 }) |*s, *c, first| { + @memset(c, .{}); + s.* = .{ .cols = 24, .rows = 12, .cells = c }; + s.addRegion(.{ .kind = .body, .owner = 0, .serial = 1, .rect = .{ .x = config.GUTTER, .y = 1, .w = 24 - config.GUTTER, .h = 10 }, .active = true, .line = first, .doc = 7 }); + for (0..3) |k| { + var buf: [8]u8 = undefined; + _ = s.print(config.GUTTER, @intCast(1 + k), 20, std.fmt.bufPrint(&buf, "ctx {d}", .{k}) catch unreachable, .{}); + } + for (3..10) |k| { + var buf: [8]u8 = undefined; + _ = s.print(config.GUTTER, @intCast(1 + k), 20, std.fmt.bufPrint(&buf, "L{d}", .{first + k - 3}) catch unreachable, .{}); + } + } + var glide: Glide = .{}; + defer glide.deinit(gpa); + glide.held[0] = 3; + glide.frame(gpa, &frames[0], std.time.ns_per_s, null, null); + glide.frame(gpa, &frames[1], std.time.ns_per_s + 16 * std.time.ns_per_ms, null, null); + // A row down, and the row that left is the first under the held ones, + // L10, not a held row. + try std.testing.expect(glide.follow.offset < -0.9); + try std.testing.expectEqual(@as(u16, 1), glide.nabove); + const w = glide.bw(); + try std.testing.expect(sameRow(glide.above[0..w], frames[0].cells[@as(usize, 1 + 3) * 24 + config.GUTTER ..][0..w])); +} diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 3538481a..80fdb39b 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -4971,7 +4971,8 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { const bw = r.w - config.GUTTER; const bh = g.scroll_body_h; const k: u16 = @intCast(@min(@abs(st.rows), @as(i32, bh))); - const srow = body_y + (if (st.rows > 0) k - 1 else bh - k); + const held = @min(pane.context_rows, bh - k); + const srow = body_y + (if (st.rows > 0) held + k - 1 else bh - k); if (srow < s.rows) { if (g.scroll_edge.len < bw) { gpa.free(g.scroll_edge); @@ -5030,10 +5031,24 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *cons n += 1; } } + // A body layer's held rows are compact, so it has rows past the grid's + // (lifted into the body by what they save): the moving rows go on with + // them, or the band under the grid's last row shows the layer's, still. + if (pane < surface.body_layers.len and surface.body_layers[pane].context_rows != 0) { + const layer = &surface.body_layers[pane]; + if (layer.cols == bw) for (bh..layer.rows) |k| { + const line = layer.cells[k * layer.cols ..][0..layer.cols]; + for (0..bw) |c_i| { + emitInstance(g, instances, base + n, x0 + @as(u16, @intCast(c_i)), y0 + @as(u16, @intCast(k)), shifted, win_w, win_h, cellFontRole(&line[c_i]), line, c_i, null, false, page); + n += 1; + } + }; + } if (!gliding) { - // A touchpad's fraction opens one row, the one that left. + // A touchpad's fraction opens one row, the one that left: under the + // held rows, where the moving rows start. if (g.scroll_edge_len >= bw) { - const erow: u16 = if (lag > 0) y0 + bh else y0 - 1; + const erow: u16 = if (lag > 0) y0 + bh else y0 + kept.rows - 1; var i: u16 = 0; while (i < bw) : (i += 1) { emitInstance(g, instances, base + n, x0 + i, erow, shifted, win_w, win_h, cellFontRole(&g.scroll_edge[i]), g.scroll_edge[0..bw], i, null, false, page); @@ -5049,8 +5064,9 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *cons const rows = if (lag < 0) glide.above else glide.below; 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 (lag < 0) @as(i32, y0) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(i)); + // Row -1 - i above the moving rows (under the held ones), or bh + i + // below the body, in grid rows. + const at_row: i32 = if (lag < 0) @as(i32, y0 + kept.rows) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(i)); var at = shifted; // emitInstance takes an unsigned row: move the layout instead. at.y_off += @as(f32, @floatFromInt(at_row - @as(i32, y0))) * layout.h; @@ -5413,6 +5429,7 @@ fn renderFrame( const chrome = &surface.chrome; // G6: what the scroll just done moved the pane's rows by, measured on // this frame against the last (the glide follows it from there). + for (core.panes, &g.glide.held) |slot, *held| held.* = if (slot) |pane| pane.context_rows else 0; glideFrame(g, gpa, surface); var groups: Groups = .{}; const now = g.now_ns; @@ -5498,8 +5515,9 @@ fn renderFrame( } const decor_len: u32 = @intCast(g.decor.items.len); if (cell_total != 0 or decor_len != 0) { - // The shifted rows of a scroll: its body, and a glide's rows past it. - const capacity = std.math.add(u32, cell_total, 2 * cells + decor_len) catch return error.GpuCapacity; + // The shifted rows of a scroll: its body, a glide's rows past it, and + // a body layer's rows past the grid's. + const capacity = std.math.add(u32, cell_total, 3 * cells + decor_len) catch return error.GpuCapacity; try growInstances(g, &g.vbuf, &g.vxfer, &g.vbuf_cells, capacity, @sizeOf(CellInstance)); const vptr: [*]u8 = @ptrCast(c.SDL_MapGPUTransferBuffer(g.device, g.vxfer.?, false) orelse { |
