diff options
Diffstat (limited to 'core/Band.zig')
| -rw-r--r-- | core/Band.zig | 95 |
1 files changed, 49 insertions, 46 deletions
diff --git a/core/Band.zig b/core/Band.zig index d60e9831..6e8f9589 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -1,10 +1,11 @@ //! The band (walk UI, pick-ui SPEC.md §3.6): rows hanging under a pane's -//! tag while it is out of rest, in the tag's tint, drawn over the top rows -//! of its body, which stay where they were (UX DESIGN I1): the tag -//! unrolled. Its steps stand side by side, each a column of rows -//! (a level, Help's rows, a doc; later a picker's acts and sources, a -//! prompt's history, the registers), a one-cell rule between them, right -//! of a spine under each of the head's key cells. +//! head (TagState.head, the row under its tag) while it is out of rest, in +//! the tag's tint, drawn over the top rows of its body, which stay where +//! they were (UX DESIGN I1, M2): the tag unrolled. Its steps stand side by +//! side, each a column of rows (a level, Help's rows, a doc; later a +//! picker's acts and sources, a prompt's history, the registers), a +//! one-cell rule between them, right of a spine under each of the head's +//! key cells. //! //! Derived from the live view's state each time it is asked (`of`), never //! stored (the coordinator's R2): the layout reads its height (`takes`, @@ -136,24 +137,25 @@ pub fn takes(p: *Pardes, id: usize) u16 { return @max(doc_rows, levelRows(n)); } -/// Where pane `id`'s tag out of rest is drawn, in rows from its top (UX -/// DESIGN I1): its head's text (`text`, the rows its own text keeps from -/// rest at least where no band hangs under it) and the band under that -/// (`band`), as many as the pane has; `over` of them past the tag's own -/// rows (`tag_rows`, its rows at rest), drawn over the top rows of its -/// body, which never move for them. A picker's band keeps a body of -/// `body_rows` under it (UX D6), any other state only the pane's rows. -/// Asked of the state alone, as `takes` is: the layout, the frame and a -/// click ask it of the same step. -pub const Covered = struct { text: u16, band: u16, over: u16 }; +/// Where pane `id`'s head and band hang out of rest, in rows from its top +/// (UX DESIGN I1, M2): under its tag's rows (`tag`, its rows at rest, which +/// no state changes), its head's (`head`), then the band's (`band`), as +/// many as the pane has under its tag; `over` the two, drawn over the top +/// rows of its body, which never move for them. A picker's band keeps a +/// body of `body_rows` under it (UX D6), any other state only the pane's +/// rows. Asked of the state alone, as `takes` is: the layout, the frame and +/// a click ask it of the same step. +pub const Covered = struct { tag: u16, head: u16, band: u16, over: u16 }; pub fn covered(p: *Pardes, pane: *const Pane, id: usize) Covered { - if (pane.collapsed or TagState.hostOf(p) != id) return .{ .text = pane.tag_rows, .band = 0, .over = 0 }; + if (pane.collapsed or TagState.hostOf(p) != id) return .{ .tag = pane.tag_rows, .head = 0, .band = 0, .over = 0 }; const h = p.view().rects[id].h; - const text = @min(layout.headRows(p, id), h); + // As Pardes.sync sets `tag_rows` (a picker's preview adds the rows + // over it to them). + const tag = @min(layout.wantedTagRows(p, id), pardes.MAX_TAG_ROWS, @max(pardes.BOX_H, h -| 1)); + const head = @min(layout.headRows(p, id), h -| tag); const keep: u16 = if (p.view().tag_state.kind == .pick) body_rows else 0; - const band = @min(takes(p, id), h -| text -| keep); - const shown = if (band > 0) text else @min(@max(text, pane.tag_rows), pardes.MAX_TAG_ROWS); - return .{ .text = shown, .band = band, .over = (shown + band) -| pane.tag_rows }; + const band = @min(takes(p, id), h -| tag -| head -| keep); + return .{ .tag = tag, .head = head, .band = band, .over = head + band }; } fn levelRows(n: u16) u16 { @@ -494,14 +496,12 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi } /// The display columns of the head's key cells: a spine hangs under each, -/// through the tag's rows under them and the band's (UX D5). +/// through the head's rows under them and the band's (UX D5). fn findSpines(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !void { const h = (try TagState.head(p, arena, pane)) orelse return; - const whole = try tagline.tagText(p, arena, pane); - const shown = try tagline.wrapTag(p.settings.tab, arena, whole, tagline.tagWidth(p, id)); - const lead = whole.len - h.text.len; + const shown = try tagline.wrapTag(p.settings.tab, arena, h.text, tagline.tagWidth(p, id)); for (h.spans[0..h.cells]) |span| { - const at = modal.positionAt(shown.text, shown.fromReal(lead + span.lo)); + const at = modal.positionAt(shown.text, shown.fromReal(span.lo)); if (band.nspines == max_spines) return; band.spines[band.nspines] = @intCast(File.rawDisplayCol(p.settings.tab, modal.lineSlice(shown.text, at.row), at.col)); band.nspines += 1; @@ -680,7 +680,7 @@ fn layerRow(arena: std.mem.Allocator, layer: *const pardes.Layer, row: usize) ![ return out.items; } -test "a narrow band gives way and keeps its spines: the doc goes, the steps start two cells right of the last spine, no row past the band's edge; the band starts on the row under the head, in the rows the tag keeps from rest" { +test "a narrow band gives way and keeps its spines: the doc goes, the steps start two cells right of the last spine, no row past the band's edge; the band starts on the row under the head, which hangs under the tag's rows at rest (UX DESIGN M2)" { const Key = pardes.Key; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 44, .rows = 30 }); defer p.deinit(); @@ -702,23 +702,24 @@ test "a narrow band gives way and keeps its spines: the doc goes, the steps star try std.testing.expectEqual(@as(u8, 1), band.nsteps); try std.testing.expectEqual(band.spines[1] + 2, band.steps[0].x); for (0..band.height) |y| try std.testing.expect(File.displayWidth(p.settings.tab, (try band.line(a, p.settings.tab, @intCast(y))).text) <= band.columns); - // The band on the row under the head's one, in the row the tag keeps - // from rest (UX E3): never a blank row between the head and its rows, - // the body under whichever is lower. + // The head on the row under the tag's rows, the band on the row under + // it: never a blank row between them, the body under them. const s = try p.render(a); const r = p.view().rects[id]; const tag_y = p.tagTop(pane, r); const at = covered(p, pane, id); - try std.testing.expectEqual(@as(u16, 1), at.text); + try std.testing.expectEqual(@as(u16, 1), at.head); + try std.testing.expectEqual(rest, at.tag); try std.testing.expectEqual(rest, pane.tag_rows); - try std.testing.expectEqual((1 + band.height) -| rest, at.over); - try std.testing.expectEqual(tag_y + 1, bandLayer(p, id).?.viewport.y); - for (band.spines[0..band.nspines]) |col| try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + col, tag_y + 1).grapheme()); - try std.testing.expect(std.mem.indexOf(u8, try layerRow(a, bandLayer(p, id).?, 0), "▶") != null); + try std.testing.expectEqual(1 + band.height, at.over); + try std.testing.expectEqual(tag_y + rest, bandLayer(p, id).?.viewport.y); + for (band.spines[0..band.nspines]) |col| try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + col, tag_y + rest + 1).grapheme()); + try std.testing.expect(std.mem.startsWith(u8, try layerRow(a, bandLayer(p, id).?, 0), "Help ␣ l ")); + try std.testing.expect(std.mem.indexOf(u8, try layerRow(a, bandLayer(p, id).?, 1), "▶") != null); p.update(.{ .key = .{ .cp = Key.escape } }); } -test "out of rest with no band, the rows a tag keeps from rest stay blank: a spine hangs only where a band row is" { +test "out of rest with no band, the tag's rows are its rows at rest: no spine hangs in them (UX DESIGN M1)" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 44, .rows = 30 }); defer p.deinit(); const pane = try p.setTestFile("one\n"); @@ -874,25 +875,27 @@ test "SPC Down unrolls the level into a band under the tag's text, drawn over th _ = frame.reset(.retain_capacity); const s = try p.render(frame.allocator()); const layer = bandLayer(p, id).?; - try std.testing.expectEqual(p.tagTop(pane, r) + at.text, layer.viewport.y); - try std.testing.expectEqual(at.band, layer.viewport.h); + try std.testing.expectEqual(p.tagTop(pane, r) + at.tag, layer.viewport.y); + try std.testing.expectEqual(at.over, layer.viewport.h); // The body region starts where it did at rest: the band is over it. const body = s.region(.body, id).?; try std.testing.expectEqual(body_top, body.rect.y); try std.testing.expect(layer.viewport.y + layer.viewport.h > body.rect.y); - const first = try layerRow(frame.allocator(), layer, 0); + const first = try layerRow(frame.allocator(), layer, at.head); try std.testing.expect(std.mem.indexOf(u8, first, "│") != null); try std.testing.expect(std.mem.indexOf(u8, first, "▶ b buffer…") != null); // The grid has the same rows, where the layer is, the body's under // them drawn first: its last covered row is the band's. var grid: std.ArrayList(u8) = .empty; - for (s.cells[@as(usize, layer.viewport.y) * s.cols ..][layer.viewport.x..][0..layer.viewport.w]) |cell| try grid.appendSlice(frame.allocator(), cell.grapheme()); + for (s.cells[@as(usize, layer.viewport.y + at.head) * s.cols ..][layer.viewport.x..][0..layer.viewport.w]) |cell| try grid.appendSlice(frame.allocator(), cell.grapheme()); try std.testing.expect(std.mem.indexOf(u8, grid.items, "▶ b buffer…") != null); const spine = (try of(p, frame.allocator(), pane, id)).?.spines[0]; try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + spine, layer.viewport.y + layer.viewport.h - 1).grapheme()); - // The head names the level and says how to roll it up. - const head = try tagline.tagText(p, frame.allocator(), pane); + // The head, the layer's first row, names the level and says how to roll + // it up. + const head = (try TagState.head(p, frame.allocator(), pane)).?.text; try std.testing.expect(std.mem.startsWith(u8, head, "␣ SPC ") and std.mem.endsWith(u8, head, " ↑ roll up · ? field · esc")); + try std.testing.expect(std.mem.startsWith(u8, try layerRow(frame.allocator(), layer, 0), "␣ SPC ")); // Down moves the cursor; Up back to the first row, then rolls up. p.update(.{ .key = .{ .cp = Key.down } }); try std.testing.expectEqual(@as(u8, 'c'), p.view().tag_state.hi); @@ -931,7 +934,7 @@ test "a level's band covers what it needs: its pane keeps its rows where its hea p.update(.{ .key = .{ .cp = Key.down } }); const pane = p.panes[low].?; const at = covered(p, pane, low); - const need = at.text + at.band; + const need = at.tag + at.over; try std.testing.expect(at.band == takes(p, low) and need <= before[low].h); try std.testing.expectEqualDeep(before, p.view().rects); p.update(.{ .key = .{ .cp = Key.escape } }); @@ -1215,7 +1218,7 @@ test "a covered row belongs to the band: a click on a band row over the body mov const band = (try of(p, frame.allocator(), pane, id)).?; // The band's last row, over the body: its first step's row there. const row: u16 = at.band - 1; - const y = p.tagTop(pane, r) + at.text + row; + const y = p.tagTop(pane, r) + at.tag + at.head + row; try std.testing.expect(y >= body_top); const ln = try band.line(frame.allocator(), p.settings.tab, row); const part = ln.parts[0]; @@ -1238,8 +1241,8 @@ test "a covered row belongs to the band: a click on a band row over the body mov p.clock.now_ns = p.view().tag_state.due_ns; p.sync(); const rolled = covered(p, pane, id); - try std.testing.expect(rolled.band == 0 and rolled.text > pane.tag_rows); - const hy = p.tagTop(pane, r) + rolled.text - 1; + try std.testing.expect(rolled.band == 0 and rolled.head > 1); + const hy = p.tagTop(pane, r) + rolled.tag + rolled.head - 1; try std.testing.expect(hy >= body_top); const hx = r.x + pardes.TAG_TEXT_INSET + 6; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = hx, .row = hy } }); |
