summaryrefslogtreecommitdiff
path: root/src/glide.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/glide.zig')
-rw-r--r--src/glide.zig121
1 files changed, 1 insertions, 120 deletions
diff --git a/src/glide.zig b/src/glide.zig
index 1605b2d3..ced0ca85 100644
--- a/src/glide.zig
+++ b/src/glide.zig
@@ -1,6 +1,6 @@
//! The view's glide (G6, anim 3, 9, 12): the text's picture following
//! its core's rows, one system on every shell. The GUI draws it at the
-//! pixel; the tty at whole rows (`shifted`).
+//! pixel; the tty at whole rows (panel_compositor.glideRows).
const std = @import("std");
const pardes = @import("pardes.zig");
@@ -282,44 +282,6 @@ pub const Glide = struct {
}
};
-/// The tty's picture of the glide (anim 12): the body's rows moved by the
-/// offset rounded to whole rows (the position rounded, never the step, so
-/// a slowing glide's steps come further apart), the rows that left in the
-/// gap it opens, and a caret whose line rode the scroll carried with it.
-/// `surface` itself while nothing is shifted.
-pub fn shifted(glide: *const Glide, arena: std.mem.Allocator, surface: *pardes.Surface) !*pardes.Surface {
- for (surface.panelTracks()) |track|
- if (track.active() and track.pane == glide.pane) return surface;
- const k: i32 = @intFromFloat(@round(glide.follow.offset));
- const w = glide.bw();
- const h = glide.body_h;
- const x0 = glide.rect.x + config.GUTTER;
- const y0 = glide.body_y;
- if (k == 0 or w == 0 or h == 0 or x0 + w > surface.cols or y0 + h > surface.rows) return surface;
- const out = try arena.create(pardes.Surface);
- out.* = surface.*;
- out.cells = try arena.dupe(pardes.Cell, surface.cells);
- const cols: usize = surface.cols;
- for (0..h) |r| {
- const from = @as(i32, @intCast(r)) + k;
- const to = out.cells[(y0 + r) * cols + x0 ..][0..w];
- const kept: ?[]const pardes.Cell = if (from >= 0 and from < h)
- surface.cells[(y0 + @as(usize, @intCast(from))) * cols + x0 ..][0..w]
- else if (from < 0 and -from - 1 < glide.nabove)
- glide.above[@as(usize, @intCast(-from - 1)) * w ..][0..w]
- else if (from >= h and from - h < glide.nbelow)
- glide.below[@as(usize, @intCast(from - h)) * w ..][0..w]
- else
- null;
- if (kept) |cells| @memcpy(to, cells) else @memset(to, .{});
- }
- if (out.cursor) |*c| if (glide.caret_rides and c.x >= x0 and c.x < x0 + w and c.y >= y0 and c.y < y0 + h) {
- const y = @as(i32, c.y) - k;
- if (y >= y0 and y < y0 + h) c.y = @intCast(y) else out.cursor = null;
- };
- return out;
-}
-
pub fn sameRow(a: []const pardes.Cell, b: []const pardes.Cell) bool {
for (a, b) |x, y| {
if (x.default != y.default) return false;
@@ -328,84 +290,3 @@ pub fn sameRow(a: []const pardes.Cell, b: []const pardes.Cell) bool {
}
return true;
}
-
-
-test "the tty draws a glide at whole rows: once a flick or a spin slows, its steps a tick never grow and its one-row steps come further apart, to where the core is" {
- const gpa = std.testing.allocator;
- const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 30, .tty_only = true });
- defer core.deinit();
- var text: std.ArrayList(u8) = .empty;
- defer text.deinit(gpa);
- for (0..3000) |i| try text.print(gpa, "{d:0>5} line\n", .{i});
- _ = try core.setTestFile(text.items);
- core.settings.motion = .smooth;
- var arena: std.heap.ArenaAllocator = .init(gpa);
- defer arena.deinit();
- var glide: Glide = .{};
- defer glide.deinit(gpa);
- var now: u64 = std.time.ns_per_s;
- // One tick of the tty: its loop step, the frame, the picture.
- const tick = struct {
- fn f(c: *pardes.Pardes, g: *Glide, a: *std.heap.ArenaAllocator, t: u64) !i32 {
- c.advance(t);
- g.step(c, std.testing.allocator, null, null);
- _ = a.reset(.retain_capacity);
- const s = try c.render(a.allocator());
- if (g.pending) g.measure(std.testing.allocator, s);
- if (g.moving()) g.advance(t, g.motion);
- _ = try shifted(g, a.allocator(), s);
- return @intFromFloat(@round(g.follow.offset));
- }
- }.f;
- _ = try tick(core, &glide, &arena, now);
- for ([_]usize{ 4, 24 }) |notches| {
- for (0..notches) |i| {
- core.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = 20, .row = 10 } });
- if (i % 2 == 1) {
- now += pardes.animation.frame_ns;
- _ = try tick(core, &glide, &arena, now);
- }
- }
- var drawn = try tick(core, &glide, &arena, now + pardes.animation.frame_ns);
- now += pardes.animation.frame_ns;
- var last_step: i32 = std.math.maxInt(i32);
- var last_gap: usize = 0;
- var since: usize = 0;
- var ticks: usize = 0;
- while (glide.moving()) : (ticks += 1) {
- try std.testing.expect(ticks < 200);
- now += pardes.animation.frame_ns;
- const k = try tick(core, &glide, &arena, now);
- const step = k - drawn;
- drawn = k;
- since += 1;
- if (step == 0) continue;
- // Toward the core, never past it, each step no longer than the last.
- try std.testing.expect(step > 0 and k <= 0);
- try std.testing.expect(step <= last_step);
- if (step == 1 and last_step == 1) try std.testing.expect(since >= last_gap);
- if (step == 1) last_gap = since;
- last_step = step;
- since = 0;
- }
- try std.testing.expectEqual(@as(i32, 0), drawn);
- }
- // j held on the bottom row: the text glides a row a key under a caret
- // that stays on its cell (it does not ride: its row is kept).
- const keys = struct {
- fn j(c: *pardes.Pardes) void {
- c.update(.{ .key = .{ .cp = 'j', .text = "j" } });
- }
- };
- for (0..40) |_| keys.j(core);
- now += std.time.ns_per_s;
- _ = try tick(core, &glide, &arena, now);
- const row = (core.surface.cursor orelse return error.NoCursor).y;
- for (0..20) |i| {
- if (i % 2 == 0) keys.j(core);
- now += pardes.animation.frame_ns;
- _ = try tick(core, &glide, &arena, now);
- const out = try shifted(&glide, arena.allocator(), &core.surface);
- try std.testing.expectEqual(row, (out.cursor orelse return error.NoCursor).y);
- }
-}