summaryrefslogtreecommitdiff
path: root/dev/gui
diff options
context:
space:
mode:
Diffstat (limited to 'dev/gui')
-rw-r--r--dev/gui/gui.zig135
1 files changed, 109 insertions, 26 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 6113c9e9..4f574eff 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -455,6 +455,7 @@ const Gui = struct {
scroll_lag: f32 = 0, // picture position - core position, in rows
scroll_edge: []pardes.Cell = &.{}, // the row that just left the pane
scroll_edge_len: u16 = 0,
+ scroll_edge_lanes: pardes.glide.RowLanes = .{}, // and a change's lanes on it
/// Loop steps since the last fractional turn: past `settle_after`, a
/// resting `scroll_lag` eases onto the core's row (stepScroll).
scroll_idle: u8 = 0,
@@ -3562,6 +3563,8 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool {
if (g.scroll_edge.len >= bw) {
@memcpy(g.scroll_edge[0..bw], s.cells[@as(usize, srow) * s.cols + r.x + config.GUTTER ..][0..bw]);
g.scroll_edge_len = bw;
+ g.scroll_edge_lanes = .{};
+ for (s.lanes.items) |lane| if (lane.y == srow and lane.x >= r.x + config.GUTTER and lane.x < r.x + r.w) g.scroll_edge_lanes.add(lane);
}
}
}
@@ -3570,22 +3573,63 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool {
return moved;
}
+/// The body a scroll moves, as its rows are drawn: a glide's at its
+/// offset, else a touchpad's fraction (scroll_lag); its pane's rect (the
+/// rail and the body, Glide.rect's), its body's first row and its rows.
+/// Null when nothing lags, or when it was resized under us.
+const ScrollBody = struct {
+ pane: usize,
+ gliding: bool,
+ lag: f32,
+ rect: pardes.Rect,
+ y0: u16,
+ bh: u16,
+
+ /// The grid row of the `i`th row that left it, nearest first: over its
+ /// moving rows (under the `held` ones) while the picture lags a move
+ /// down, under the body for one up.
+ fn leftRow(sb: ScrollBody, held: u16, i: usize) i32 {
+ return if (sb.lag < 0) @as(i32, sb.y0 + held) - 1 - @as(i32, @intCast(i)) else @as(i32, sb.y0) + sb.bh + @as(i32, @intCast(i));
+ }
+
+ /// A glide's rows that left it drawn: as many as the lag opens.
+ fn glideLeft(sb: ScrollBody, glide: *const Glide) u16 {
+ const gap: u16 = @intFromFloat(@min(@ceil(@abs(sb.lag)), @as(f32, @floatFromInt(@as(u32, sb.bh) * Glide.reach))));
+ return @min(gap, if (sb.lag < 0) glide.nabove else glide.nbelow);
+ }
+};
+
+fn scrollBody(g: *const Gui, surface: *const pardes.Surface) ?ScrollBody {
+ const glide = &g.glide;
+ const gliding = glide.follow.offset != 0;
+ const sb: ScrollBody = .{
+ .pane = if (gliding) glide.pane else g.scroll_pane orelse return null,
+ .gliding = gliding,
+ .lag = if (gliding) glide.follow.offset else g.scroll_lag,
+ .rect = if (gliding) glide.rect else g.scroll_rect,
+ .y0 = if (gliding) glide.body_y else g.scroll_body_y,
+ .bh = if (gliding) glide.body_h else g.scroll_body_h,
+ };
+ const bw = sb.rect.w -| config.GUTTER;
+ if (sb.lag == 0 or bw == 0 or sb.bh == 0 or sb.rect.x + config.GUTTER + bw > surface.cols or sb.y0 + sb.bh > surface.rows) return null;
+ return sb;
+}
+
/// A scrolling body's picture: its rows moved by the lag, a glide's or a
/// touchpad's fraction of a row, and in the gap that opens the rows that
/// left.
fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: [3]u8, held: u16) u32 {
g.scroll_held_px = 0;
const glide = &g.glide;
- const gliding = glide.follow.offset != 0;
- const pane = if (gliding) glide.pane else g.scroll_pane orelse return 0;
- const lag = if (gliding) glide.follow.offset else g.scroll_lag;
- if (lag == 0) return 0;
- const r = if (gliding) glide.rect else g.scroll_rect;
- const bh = if (gliding) glide.body_h else g.scroll_body_h;
- const y0 = if (gliding) glide.body_y else g.scroll_body_y;
- const bw = r.w -| config.GUTTER;
+ const sb = scrollBody(g, surface) orelse return 0;
+ const gliding = sb.gliding;
+ const pane = sb.pane;
+ const lag = sb.lag;
+ const r = sb.rect;
+ const bh = sb.bh;
+ const y0 = sb.y0;
+ const bw = r.w - config.GUTTER;
const x0 = r.x + config.GUTTER;
- if (bw == 0 or bh == 0 or x0 + bw > surface.cols or y0 + bh > surface.rows) return 0; // resized under us
// The scissor the shifted rows are drawn in is the scroll's.
g.scroll_rect = r;
g.scroll_body_y = y0;
@@ -3630,7 +3674,7 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *cons
// 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 + kept.rows - 1;
+ const erow: u16 = @intCast(sb.leftRow(kept.rows, 0));
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);
@@ -3641,14 +3685,10 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *cons
}
// A glide's: rows past the top while the picture lags a move down, past
// the bottom for one up; as many as it opens.
- const gap: u16 = @intFromFloat(@min(@ceil(@abs(lag)), @as(f32, @floatFromInt(@as(u32, bh) * Glide.reach))));
- const nkept = if (lag < 0) glide.nabove else glide.nbelow;
const rows = if (lag < 0) glide.above else glide.below;
- for (0..@min(gap, nkept)) |i| {
+ for (0..sb.glideLeft(glide)) |i| {
const cells = rows[i * bw ..][0..bw];
- // 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));
+ const at_row = sb.leftRow(kept.rows, 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;
@@ -4919,16 +4959,7 @@ fn buildDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, g
} else false;
if (grid_bottom < win_h and tag_last) try addDecor(g, gpa, 0, grid_bottom, win_w, win_h, chrome.tag_bg, 1, win_w, win_h);
try paneDecor(g, gpa, regions, surface.rail_ticks[0..surface.nrail_ticks], surface.heat.items, chrome, layout, surface.cols, surface.rows, win_w, win_h);
- // The changes' lanes (jj.paint): a strip a level in the gutter's
- // lane cells, each a third of a cell wide with half that of air
- // before it, so three take one and a half cells (the ruled
- // sample A); whole pixels, so every row's strip lines up.
- for (surface.lanes.items) |lane| {
- const w = @max(1, @round(layout.w / 3));
- const x0 = @round(@as(f32, @floatFromInt(lane.x)) * layout.w + w / 2 + @as(f32, @floatFromInt(lane.level)) * (w + w / 2));
- const y0 = @as(f32, @floatFromInt(lane.y)) * layout.h;
- try addDecor(g, gpa, x0, y0, x0 + w, y0 + layout.h, lane.rgb, 1, win_w, win_h);
- }
+ try laneDecor(g, gpa, surface, layout, win_w, win_h);
// A single spine runs down each column, through every tag and body.
for (regions) |column| {
if (column.kind != .column) continue;
@@ -4958,6 +4989,58 @@ fn buildDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, g
}
}
+/// The changes' lanes (jj.paint): a strip a level in the gutter's lane
+/// cells, each a third of a cell wide with half that of air before it, so
+/// three take one and a half cells (the ruled sample A); whole pixels, so
+/// every row's strip lines up. A scrolling body's ride its rows as
+/// emitScrollRows draws them: the lag less, cut to the body under its held
+/// rows (its scissor), and the rows that left keep theirs in the gap.
+fn laneDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32) !void {
+ const w = @max(1, @round(layout.w / 3));
+ const b = scrollBody(g, surface) orelse {
+ for (surface.lanes.items) |lane| try laneStrip(g, gpa, lane, lane.y, null, w, layout, win_w, win_h);
+ return;
+ };
+ const kept = holdContext(g, surface, b.pane, if (surface.facts.pane(b.pane)) |pane| pane.context_rows else 0, b.bh, layout);
+ const ride: LaneRide = .{
+ .x0 = b.rect.x + config.GUTTER,
+ .x1 = b.rect.x + b.rect.w,
+ .y0 = b.y0 + kept.rows,
+ .y1 = b.y0 + b.bh,
+ .dy = b.lag * layout.h - kept.lift,
+ .top = @as(f32, @floatFromInt(b.y0 + kept.rows)) * layout.h + kept.lift,
+ .bottom = @as(f32, @floatFromInt(b.y0 + b.bh)) * layout.h,
+ };
+ for (surface.lanes.items) |lane| {
+ const rides = lane.x >= ride.x0 and lane.x < ride.x1 and lane.y >= ride.y0 and lane.y < ride.y1;
+ try laneStrip(g, gpa, lane, lane.y, if (rides) &ride else null, w, layout, win_w, win_h);
+ }
+ if (b.gliding) {
+ const rows = if (b.lag < 0) g.glide.above_lanes else g.glide.below_lanes;
+ for (rows[0..b.glideLeft(&g.glide)], 0..) |*row, i| for (row.items()) |lane| try laneStrip(g, gpa, lane, b.leftRow(kept.rows, i), &ride, w, layout, win_w, win_h);
+ } else if (g.scroll_edge_len >= b.rect.w - config.GUTTER) {
+ for (g.scroll_edge_lanes.items()) |lane| try laneStrip(g, gpa, lane, b.leftRow(kept.rows, 0), &ride, w, layout, win_w, win_h);
+ }
+}
+
+/// A scrolling body's moving rows (laneDecor): their columns and rows, how
+/// far up they are drawn, and the pixels they are cut to.
+const LaneRide = struct { x0: u16, x1: u16, y0: u16, y1: u16, dy: f32, top: f32, bottom: f32 };
+
+/// `lane`'s strip, `w` pixels wide, on grid row `row`, riding a scroll's
+/// rows when given one.
+fn laneStrip(g: *Gui, gpa: std.mem.Allocator, lane: pardes.Lane, row: i32, ride: ?*const LaneRide, w: f32, layout: CellLayout, win_w: f32, win_h: f32) !void {
+ const x0 = @round(@as(f32, @floatFromInt(lane.x)) * layout.w + w / 2 + @as(f32, @floatFromInt(lane.level)) * (w + w / 2));
+ var y0 = @as(f32, @floatFromInt(row)) * layout.h;
+ var y1 = y0 + layout.h;
+ if (ride) |r| {
+ y0 = @max(y0 - r.dy, r.top);
+ y1 = @min(y1 - r.dy, r.bottom);
+ if (y1 <= y0) return;
+ }
+ try addDecor(g, gpa, x0, y0, x0 + w, y1, lane.rgb, 1, win_w, win_h);
+}
+
/// Each pane's rule between its tag and body, and its scroll rail: a page
/// coloured gutter with a thin track and its thumb, running down through the
/// pixels past the last whole row.