diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 00:56:28 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:40:44 -0300 |
| commit | 2715ed7d3ce140bcc39f7596232c874c87df5b3c (patch) | |
| tree | c956dbb4748622ff4894c8c7ad7f44f79ef6ae5f /src/gui | |
| parent | 7ca4524a4cedfeddd6ffa4bcf4eb7465076d2d7d (diff) | |
| download | pardes-2715ed7d3ce140bcc39f7596232c874c87df5b3c.tar.gz pardes-2715ed7d3ce140bcc39f7596232c874c87df5b3c.zip | |
gui: one emitScrollRows draws a scrolling body's shifted rows, a glide's and a touchpad's fraction alike (the rows the scissor shows, the caret a touchpad's block carries, then the gap: the glide's kept rows or the touchpad's one edge row), in place of emitGlideRows and its twin
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/gui.zig | 139 |
1 files changed, 57 insertions, 82 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index edf8347a..bfec8352 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -5206,65 +5206,6 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { glide.step(core, gpa, wheeled, direct); } -/// The glide's picture: the pane's body rows moved by the offset, and in -/// the gap it opens the rows that left, as `emitScrollRows` draws a -/// touchpad's fraction. -fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *const pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: [3]u8, held: u16) u32 { - const glide = &g.glide; - for (surface.panelTracks()) |track| - if (track.active() and track.pane == glide.pane) return 0; - const r = glide.rect; - const bh = glide.body_h; - const bw = glide.bw(); - const x0 = r.x + config.GUTTER; - const y0 = glide.body_y; - if (bw == 0 or bh == 0 or x0 + bw > surface.cols or y0 + bh > surface.rows) return 0; - // The scissor the shifted rows are drawn in is the scroll's. - g.scroll_rect = r; - g.scroll_body_y = y0; - g.scroll_body_h = bh; - var shifted = layout; - shifted.y_off -= glide.follow.offset * layout.h; - const kept = holdContext(g, surface, glide.pane, held, bh, layout); - shifted.y_off += kept.lift; - 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 - // instances for the length of a long glide. - const lag: u16 = @intFromFloat(@min(@floor(@abs(glide.follow.offset)), @as(f32, @floatFromInt(bh)))); - var row = y0 + kept.rows + if (glide.follow.offset > 0) lag else 0; - const row_end = y0 + bh - if (glide.follow.offset < 0) lag else 0; - while (row < row_end) : (row += 1) { - const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols]; - 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) { - // 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(&line[col]), line, col, row_cursor, false, false, page); - n += 1; - } - } - // The gap: 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(glide.follow.offset)), @as(f32, @floatFromInt(@as(u32, bh) * Glide.reach)))); - const nkept = if (glide.follow.offset < 0) glide.nabove else glide.nbelow; - const rows = if (glide.follow.offset < 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 (glide.follow.offset < 0) @as(i32, y0) - 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; - for (0..bw) |c_i| { - emitInstance(g, instances, base + n, x0 + @as(u16, @intCast(c_i)), y0, at, win_w, win_h, null, cellFontRole(&cells[c_i]), cells, c_i, null, false, false, page); - n += 1; - } - } - return n; -} - test "a notch scrolls the core at once and the picture glides after it, a wrapped line's rows at a time" { const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); @@ -5638,43 +5579,77 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { if (g.scroll_lag == 0) resetScroll(g); } +/// 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; - if (g.glide.follow.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held); - const scroll_pane = g.scroll_pane orelse return 0; - if (g.scroll_lag == 0) return 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; for (surface.panelTracks()) |track| - if (track.active() and track.pane == scroll_pane) return 0; - const r = g.scroll_rect; - const bh = g.scroll_body_h; - if (r.w <= config.GUTTER or bh == 0) return 0; + if (track.active() and track.pane == pane) 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 x0 = r.x + config.GUTTER; - const y0 = g.scroll_body_y; - const bw = r.w - config.GUTTER; - if (x0 + bw > surface.cols or y0 + bh > surface.rows) return 0; // resized under us + 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; + g.scroll_body_h = bh; var shifted = layout; - shifted.y_off -= g.scroll_lag * layout.h; - const kept = holdContext(g, surface, scroll_pane, held, bh, layout); + shifted.y_off -= lag * layout.h; + const kept = holdContext(g, surface, 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; + // 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 + // instances for the length of a long glide. + const gone: u16 = @intFromFloat(@min(@floor(@abs(lag)), @as(f32, @floatFromInt(bh)))); + var row = y0 + kept.rows + if (lag > 0) gone else 0; + const row_end = y0 + bh - if (lag < 0) gone else 0; + // A touchpad's block caret moves with its row; a glide's is drawn from + // its own springs (the quad), never carried by the text. + const caret: u32 = if (surface.cursor) |cu| (if (gliding or cu.bar) std.math.maxInt(u32) else @as(u32, cu.y) * surface.cols + cu.x) else std.math.maxInt(u32); var n: u32 = 0; - var row = y0 + kept.rows; - while (row < y0 + bh) : (row += 1) { + while (row < row_end) : (row += 1) { const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols]; 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(&line[col]), line, col, row_cursor, false, sidx == cursor_idx and !cursor_bar, page); + emitInstance(g, instances, base + n, col, row, shifted, win_w, win_h, null, cellFontRole(&line[col]), line, col, row_cursor, false, @as(u32, row) * surface.cols + col == caret, page); n += 1; } } - if (g.scroll_edge_len >= bw) { - const erow: u16 = if (g.scroll_lag > 0) y0 + bh else y0 - 1; - var i: u16 = 0; - while (i < bw) : (i += 1) { - emitInstance(g, instances, base + n, x0 + i, erow, shifted, win_w, win_h, null, cellFontRole(&g.scroll_edge[i]), g.scroll_edge[0..bw], i, null, false, false, page); + if (!gliding) { + // A touchpad's fraction opens one row, the one that left. + if (g.scroll_edge_len >= bw) { + const erow: u16 = if (lag > 0) y0 + bh else y0 - 1; + var i: u16 = 0; + while (i < bw) : (i += 1) { + emitInstance(g, instances, base + n, x0 + i, erow, shifted, win_w, win_h, null, cellFontRole(&g.scroll_edge[i]), g.scroll_edge[0..bw], i, null, false, false, page); + n += 1; + } + } + return n; + } + // 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| { + 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)); + 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; + for (0..bw) |c_i| { + emitInstance(g, instances, base + n, x0 + @as(u16, @intCast(c_i)), y0, at, win_w, win_h, null, cellFontRole(&cells[c_i]), cells, c_i, null, false, false, page); n += 1; } } |
