diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/gui/gui.zig | 97 |
1 files changed, 96 insertions, 1 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 9f6e4876..1d3fd926 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -3655,6 +3655,14 @@ fn scrollBody(g: *const Gui, surface: *const pardes.Surface) ?ScrollBody { }; 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; + // Its body layer, when the frame has one, under the whole body and a + // row of cells for each of its rows: a shorter one is a pane shrunk + // under the scroll (a glide keeps the rect it began on), and the frame + // is drawn as it is. + if (sb.pane < surface.body_layers.len) { + const layer = &surface.body_layers[sb.pane]; + if (layer.rows != 0 and (layer.rows < sb.bh or layer.cells.len < @as(usize, layer.rows) * layer.cols)) return null; + } return sb; } @@ -3703,7 +3711,10 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *cons // 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) { + // A layer this frame has: one whose context rows went (scrolled out + // of, TreeContext off) is none (`rows == 0`), its slot keeping their + // count and its width. + if (pane < surface.body_layers.len and surface.body_layers[pane].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]; @@ -7074,6 +7085,90 @@ test "a scroll's shifted rows start under the context rows, and its scissor belo try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout).y); } +test "a touchpad's fraction over a body whose context rows went (scrolled out of, TreeContext off) draws the rows the frame has: its body layer went with them" { + const gpa = std.testing.allocator; + const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); + defer core.deinit(); + const pane = try core.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (std.mem.asBytes(&@as([30][16]u8, @splat(" // body\n".*)))) ++ " }\n};\n"); + gpa.free(pane.file.?.path); + pane.file.?.path = try gpa.dupe(u8, "/test.zig"); + if (!pardes.panes.File.supportsContext(pane)) return error.SkipZigTest; + core.update(.{ .resize = .{ .cols = 80, .rows = 24, .row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 } } }); + pane.file.?.tree_context = true; + core.sync(); + var wr = try WheelRun.init(gpa, core); + defer wr.deinit(gpa); + const id = core.view().active; + // The test's gui has no font: each frame is drawn with its cells, its + // layers' and the row that left blank. + const blank = try gpa.alloc(pardes.Cell, 2 * 80 * 24); + defer gpa.free(blank); + @memset(blank, .{}); + const instances = try gpa.alloc(CellInstance, 3 * 80 * 24); + defer gpa.free(instances); + // From line 5, under its two context rows, quarter notches up, a frame + // each, to the file's top: a row crossed leaves the picture three + // quarters of a row behind the core's. The frame that crosses onto + // `pub const Box` has no context rows; and with TreeContext turned off + // none has: no body layer, its last context rows and width still in + // its slot. + for ([_]bool{ false, true }) |off| { + pane.file.?.scroll = 4; + core.sync(); + core.needs_frame = true; + // The jump there glided to rest. + for (0..120) |_| try wr.frame(gpa, &.{}); + try std.testing.expect(!frontendMoving(&wr.g)); + try std.testing.expectEqual(@as(u16, 2), wr.g.frame.?.body_layers[id].context_rows); + try std.testing.expect(wr.g.frame.?.body_layers[id].rows != 0); + if (off) core.update(.{ .command = "TreeContext" }); + var gone: usize = 0; + for (0..20) |_| { + try wr.frame(gpa, &.{0.25}); + if (wr.g.scroll_lag == 0) continue; + var s = wr.g.frame.?.*; + s.cells = blank[0..s.cells.len]; + for (&s.body_layers) |*layer| layer.cells = blank[0..layer.cells.len]; + @memset(wr.g.scroll_edge, .{}); + const held = if (s.facts.pane(id)) |shown| shown.context_rows else 0; + const n = emitScrollRows(&wr.g, instances.ptr, 0, &s, fixedCellLayout(&wr.g), 800, 480, bg_default, held); + // The body's moving rows under the held ones, the layer's + // rows past the grid's while there is a layer, and the row + // that left. + const layer = &s.body_layers[id]; + const bw = wr.g.scroll_rect.w - config.GUTTER; + const past = if (layer.rows != 0) layer.rows - wr.g.scroll_body_h else 0; + try std.testing.expectEqual(@as(u32, wr.g.scroll_body_h - held + past + 1) * bw, n); + if (layer.rows == 0 and layer.context_rows != 0) gone += 1; + } + try std.testing.expect(gone > 0); + } +} + +test "a scroll's body taller than its body layer (the pane shrunk under a glide) is drawn still, and nothing past a layer's cells is read" { + var g = testGui(10, 20, 6, 12); + var grid: [40 * 20]pardes.Cell = @splat(.{}); + var short: [38 * 12]pardes.Cell = @splat(.{}); + var surface: pardes.Surface = .{ .cols = 40, .rows = 20, .cells = &grid }; + surface.body_layers[0] = .{ .viewport = .{ .x = 2, .y = 1, .w = 38, .h = 10 }, .cols = 38, .rows = 12, .context_rows = 2, .cells = &short }; + g.scroll_pane = 0; + g.scroll_lag = 0.5; + g.scroll_rect = .{ .x = 0, .y = 0, .w = 40, .h = 20 }; + g.scroll_body_y = 1; + g.scroll_body_h = 19; + var instances: [3 * 40 * 20]CellInstance = undefined; + const layout = fixedCellLayout(&g); + try std.testing.expectEqual(@as(u32, 0), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, bg_default, 2)); + // As tall as the body, its cells short of its rows: the same. + surface.body_layers[0].rows = 21; + try std.testing.expectEqual(@as(u32, 0), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, bg_default, 2)); + // Its cells all there: the body's moving rows under the two held, and + // the layer's two past the grid's. + var whole: [38 * 21]pardes.Cell = @splat(.{}); + surface.body_layers[0].cells = &whole; + try std.testing.expectEqual(@as(u32, (19 - 2 + 2) * 38), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, bg_default, 2)); +} + test "concealed terminal text emits no ink on its ground" { var g = testGui(10, 20, 6, 12); var cell: pardes.Cell = .{ .default = false, .style = .{ .invisible = true, .ul = .single } }; |
