diff options
Diffstat (limited to 'core/draw.zig')
| -rw-r--r-- | core/draw.zig | 165 |
1 files changed, 101 insertions, 64 deletions
diff --git a/core/draw.zig b/core/draw.zig index 42396aa1..3caf27ca 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -373,15 +373,15 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { s.body_layers[id].rows = 0; try renderPane(p, s, arena, pane, v.rects[id], id, id == v.active); } - // A tag out of rest after every body (UX DESIGN I1): its head and its - // band past its own rows are drawn over the top rows of its body, - // which stay where they were; beside them the grip's column on the - // tag's ground, and a caret under them hidden until rest. + // A tag out of rest after every body (UX DESIGN I1, M2): drawn as at + // rest, its head and band hanging under it over the top rows of its + // body, which stay where they were; beside them the grip's column on + // the tag's ground, and a caret under them hidden until rest. if (TagState.hostOf(p)) |id| if (p.panes[id]) |pane| if (v.rects[id].w > config.GUTTER and v.rects[id].h > 0) { const r = v.rects[id]; const at = pardes.Band.covered(p, pane, id); - const y = p.tagTop(pane, r) + pane.tag_rows; - const rows = @min(at.over, r.h -| pane.tag_rows); + const y = p.tagTop(pane, r) + at.tag; + const rows = @min(at.over, r.h -| at.tag); if (rows > 0) { s.fill(r.x, y, config.GUTTER, rows, .{ .bg = .{ .rgb = tagGround(p, pane, id == v.active) }, .font_role = .tagline }); if (s.cursor) |c| if (c.x >= r.x and c.x < r.x + r.w and c.y >= y and c.y < y + rows) { @@ -391,8 +391,8 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { s.body_layers[id].cursor = null; }; } - try joinPaneTag(p, s, arena, pane, r, id, id == v.active, at.text); - if (at.band > 0) try joinBand(p, s, arena, pane, r, id, id == v.active, at); + try joinPaneTag(p, s, arena, pane, r, id, id == v.active, at.tag); + if (at.over > 0) try joinBand(p, s, arena, pane, r, id, id == v.active, at); }; // Each notice once, as a tag layer, and the grid's chip a copy of it. for (s.regionList()) |region| { @@ -736,8 +736,6 @@ fn joinCells(s: *Surface, x: u16, y: u16, cells: []const Cell, from: usize, w: u } fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } { - // Out of rest no name is shown (UX D1). - if (pardes.Trail.outOfRest(p, pane)) return null; if (pane.isTerminal()) { // `tag` is the first row; a prefix longer than it ran to a second. var words = std.mem.tokenizeAny(u8, tag[@min(prefix_len, tag.len)..], " \t\r\n"); @@ -749,7 +747,7 @@ fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len return null; } var start: usize = tagline.nameAt(p, pane); - const name = if (pane.file) |file| + const name = if (tagline.named(p, pane)) |file| if (pane.prompt == .name) pane.input.own orelse file.path else file.path else if (pane.addon) |k| blk: { // A kind's tag may put its words before the path (an image's @@ -870,9 +868,8 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v } /// A pane's tag's `rows` text rows (MAX_TAG_ROWS at most; out of rest its -/// head's, Band.covered, past its own rows over its body), painted once -/// into their layer, a row to a line, and copied into the grid; the grid's -/// caret where the layer has it. +/// rows at rest, Band.covered), painted once into their layer, a row to a +/// line, and copied into the grid; the grid's caret where the layer has it. fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, rows: u16) !void { const v = p.view(); const capacity = layout.tagCapacity(p, r.w -| TAG_TEXT_INSET); @@ -927,19 +924,21 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r } } -/// The band under pane `id`'s tag text (Band.zig), its `drawn.band` rows -/// under the head's `drawn.text`, painted once into its layer at the -/// tagline's pitch, a row to a line, and copied into the grid: the spines -/// and steps in the tag's tint, the keys in the key ink, the cursor's row -/// tinted as a selection. +/// The head and the band under pane `id`'s tag (UX DESIGN M2): the head's +/// `drawn.head` rows (TagState.head: its keys, the level or the field and +/// its caret, the count, the hints), then the band's `drawn.band` +/// (Band.zig), painted once into their layer at the tagline's pitch, a row +/// to a line, and copied into the grid: the spines and steps in the tag's +/// tint, the keys in the key ink, the cursor's row tinted as a selection. fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, drawn: pardes.Band.Covered) !void { const layer = &s.tag_layers[pardes.BAND_LAYER]; - const rows = drawn.band; + const rows = drawn.over; if (r.w <= TAG_TEXT_INSET) return; - const band = (try pardes.Band.of(p, arena, pane, id)) orelse return; + const head = (try TagState.head(p, arena, pane)) orelse return; + const band = try pardes.Band.of(p, arena, pane, id); const chrome = p.chromeTheme(); const tab = p.settings.tab; - const columns = @max(band.columns, 1); + const columns = @max(layout.tagCapacity(p, r.w -| TAG_TEXT_INSET), 1); // The walk UI's inks on this tag's ground (colors.Roles, UX DESIGN.md // D4), and on its cursor row's selection. const ground = groundOf(p, pane, active); @@ -953,10 +952,45 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R const storage = try arena.alloc(Cell, @as(usize, columns) * rows); @memset(storage, .{}); var t: Surface = .{ .cols = columns, .rows = rows, .cells = storage, .tab = tab }; - for (0..rows) |y| { - const row: u16 = @intCast(y); - t.fill(0, row, columns, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline }); - const ln = try band.line(arena, tab, row); + t.fill(0, 0, columns, rows, .{ .bg = .{ .rgb = bg }, .font_role = .tagline }); + // The head's rows, as it laid itself out at the tag's width (UX D2, D3). + const shown = try tagline.wrapTag(tab, arena, head.text, columns); + var lines: [MAX_TAG_ROWS][]const u8 = @splat(""); + var split = std.mem.splitScalar(u8, shown.text, '\n'); + for (lines[0..drawn.head], 0..) |*line, y| { + line.* = split.next() orelse break; + _ = t.print(0, @intCast(y), columns, line.*, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline }); + } + // Its keys in the key ink, its dimmed, underlined and struck words + // (TagState.Span), over whichever rows they wrapped onto. + for (head.spans) |span| { + const a = modal.positionAt(shown.text, shown.fromReal(span.lo)); + const b = modal.positionAt(shown.text, shown.fromReal(span.hi)); + var row = a.row; + while (row <= b.row and row < drawn.head) : (row += 1) { + const line = lines[row]; + var col = panes.File.rawDisplayCol(tab, line, @min(if (row == a.row) a.col else 0, line.len)); + const end = panes.File.rawDisplayCol(tab, line, @min(if (row == b.row) b.col else line.len, line.len)); + while (col < end and col < columns) : (col += 1) { + const style = &t.at(@intCast(col), @intCast(row)).style; + switch (span.style) { + .key => { + style.fg = .{ .rgb = chrome.roles.key }; + style.bold = true; + }, + .dim => style.fg = .{ .rgb = inks.dim }, + .under => style.ul = .single, + .strike => style.strikethrough = true, + .err => style.fg = .{ .rgb = chrome.roles.err }, + .rule => style.fg = .{ .rgb = inks.rule }, + } + } + } + } + // The band's rows under the head's. + if (band) |b| for (0..drawn.band) |y| { + const row: u16 = @intCast(drawn.head + y); + const ln = try b.line(arena, tab, @intCast(y)); _ = t.print(0, row, columns, ln.text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline }); // The spines and the rules between steps in the rule ink; a row's // `▶` (the cursor) and `•` (marked) in the key ink. @@ -980,20 +1014,20 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R t.tint(part.col, row, end - part.col, selected.ground, selected.text); } var c = part.col; - var b: usize = 0; - while (b < part.row.text.len and c < end) : (c += 1) { - const next = modal.nextGrapheme(part.row.text, b); + var i: usize = 0; + while (i < part.row.text.len and c < end) : (c += 1) { + const next = modal.nextGrapheme(part.row.text, i); const style = &t.at(c, row).style; - if (b < part.row.key) { + if (i < part.row.key) { style.fg = .{ .rgb = chrome.roles.key }; style.bold = true; } // A chord (Help's `SPC h t`): keys, at the text's weight. - if (b < part.row.chord) style.fg = .{ .rgb = chrome.roles.key }; - if (b < part.row.pre) style.fg = .{ .rgb = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg }; - if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint) or (b >= part.row.quiet[0] and b < part.row.quiet[1])) style.fg = .{ .rgb = on.dim }; - if (b < part.row.kind) style.fg = .{ .rgb = kind }; - for (part.row.keys) |k| if (k == b) { + if (i < part.row.chord) style.fg = .{ .rgb = chrome.roles.key }; + if (i < part.row.pre) style.fg = .{ .rgb = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg }; + if (part.row.dim or (i >= part.row.pre and i < part.row.pre + part.row.faint) or (i >= part.row.quiet[0] and i < part.row.quiet[1])) style.fg = .{ .rgb = on.dim }; + if (i < part.row.kind) style.fg = .{ .rgb = kind }; + for (part.row.keys) |k| if (k == i) { style.fg = .{ .rgb = chrome.roles.key }; style.bold = true; }; @@ -1001,11 +1035,11 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R // A matched letter: the match ink, bold, on the row's own // ground (never a ground of its own: on the cursor row's // selection one vanished). - for (part.row.marks) |m| if (m == b) { + for (part.row.marks) |m| if (m == i) { style.fg = .{ .rgb = chrome.roles.match }; style.bold = true; }; - b = next; + i = next; } // Its meta, right-aligned in the part (Band.line), dim. if (pardes.Band.metaShown(tab, part.row, part.width) and part.col + part.width <= columns) { @@ -1013,12 +1047,12 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R for (part.col + part.width - meta..part.col + part.width) |x| t.at(@intCast(x), row).style.fg = .{ .rgb = on.dim }; } } - } + }; const count = @as(usize, columns) * rows; if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count); @memcpy(layer.cells, storage); - // Under the head's rows, over the body's top ones (Band.covered). - const y0 = p.tagTop(pane, r) + drawn.text; + // Under the tag's rows, over the body's top ones (Band.covered). + const y0 = p.tagTop(pane, r) + drawn.tag; layer.kind = .band; layer.id = @intCast(id); layer.serial = pane.serial; @@ -1029,6 +1063,18 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R layer.bg = bg; layer.cursor = null; for (0..rows) |y| joinCells(s, r.x + TAG_TEXT_INSET, y0 + @as(u16, @intCast(y)), storage[y * columns ..][0..columns], 0, r.w - TAG_TEXT_INSET, .{ .rgb = fg }); + // A head typed in: its caret a bar at the field's, the keyboard's + // where the pane has it. + if (head.caret) |c| if (active) { + const at = modal.positionAt(shown.text, shown.fromReal(c)); + if (at.row < drawn.head) { + const col = panes.File.rawDisplayCol(tab, lines[at.row], @min(at.col, lines[at.row].len)); + if (col < columns) { + layer.cursor = .{ .x = @intCast(col), .y = @intCast(at.row), .bar = true }; + if (col < r.w - TAG_TEXT_INSET) s.cursor = .{ .x = r.x + TAG_TEXT_INSET + @as(u16, @intCast(col)), .y = y0 + @as(u16, @intCast(at.row)), .bar = true }; + } + } + }; } /// Bytes `lo` to `hi` of a tag's text in `ink`, over whichever of its @@ -1085,12 +1131,12 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, .font_role = .tagline, }); const whole = try tagline.tagText(p, arena, pane); - // Out of rest, the head in place of the tag's own text (TagState). - const head = try TagState.head(p, arena, pane); - const tail = if (head) |h| h.text else tagline.curTail(pane); + // A question in place of the tag's own text (TagState.asking). + const question = try TagState.asking(p, arena, pane); + const tail = if (question) |h| h.text else tagline.curTail(pane); const prefix_len = whole.len - tail.len; - // Out of rest, the walk UI's text ink (at rest the tag's own, unchanged). - const text_style: CellStyle = if (head == null) tag_style else .{ .fg = .{ .rgb = inks.text }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }; + // A question in the walk UI's text ink (the tag's own text its own). + const text_style: CellStyle = if (question == null) tag_style else .{ .fg = .{ .rgb = inks.text }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }; // A row per line shown, from `tag_top`: the tag's first line carries // the prefix, the rest are the tag's own text alone. const top = pane.tag_top; @@ -1112,7 +1158,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(p, pane) + @as(usize, @intCast(@max(0, pane.input.cur_col))))); if (at.row < top or at.row >= top + rows) break :caret null; break :caret .{ .row = at.row - top, .at = @min(lines[at.row - top].len, at.col) }; - } else if (pane.focus == .tag and pane.prompt == .none and head == null) caret: { + } else if (pane.focus == .tag and pane.prompt == .none and question == null) caret: { const real = modal.offsetAt(whole, .{ .row = @intCast(@max(0, pane.tag.cur_row)), .col = @intCast(@max(0, pane.tag.cur_col)) }); const at = modal.positionAt(shown.text, shown.fromReal(real)); if (at.row < top or at.row >= top + rows) break :caret null; @@ -1127,9 +1173,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], text_style); } // The pane's progress at its first row's right end, where the row has - // room for it (SPEC §10.2); out of rest the head's right block is - // there (UX D1). - if (top == 0 and rows > 0 and !pardes.Trail.outOfRest(p, pane)) for (p.messages.live[0..p.messages.live_len]) |*said| { + // room for it (SPEC §10.2). + if (top == 0 and rows > 0) for (p.messages.live[0..p.messages.live_len]) |*said| { if (said.kind != .progress or said.pane != pane.serial) continue; var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined; const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break; @@ -1147,7 +1192,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, // `+N` too; the word n walks underlined in the key ink (UX D8). const ahead = tagline.forwardSpan(p, pane); if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), inks.dim, false); - if (pane.file != null and pane.trail.n > 0 and !pardes.Trail.outOfRest(p, pane)) { + if (pane.file != null and pane.trail.n > 0) { const kept = tagline.folded(p, pane).whole; const t = &pane.trail; // Each run of folded places' `+N` (UX L'1: words never fold). @@ -1162,9 +1207,9 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, } // A search word its places no longer light, dimmed (Prompt.zig). if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), inks.dim, false); - // The head's keys in the key ink, its dimmed, underlined and struck - // words (TagState.Span), over whichever rows they wrapped onto. - if (head) |h| for (h.spans) |span| { + // A question's keys in the key ink, its dimmed words (TagState.Span), + // over whichever rows they wrapped onto. + if (question) |h| for (h.spans) |span| { const a = modal.positionAt(shown.text, shown.fromReal(prefix_len + span.lo)); const b = modal.positionAt(shown.text, shown.fromReal(prefix_len + span.hi)); var row = @max(a.row, top); @@ -1193,7 +1238,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, }; // The tag's own selections, while it has the keyboard, a line at a // time. A range of one grapheme is the block cursor, not a selection. - if (pane.focus == .tag and head == null) { + if (pane.focus == .tag and question == null) { var ranges: [Text.max_selections]modal.Selection = undefined; const got = pane.tag.ranges(whole, 0, &ranges); for (ranges[0..got.n]) |range| { @@ -1213,15 +1258,6 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, } } } - // A head typed in: its caret a bar at the field's. - if (head) |h| if (h.caret) |c| if (active) { - const at = modal.positionAt(shown.text, shown.fromReal(prefix_len + c)); - if (at.row >= top and at.row < top + rows) { - const line = lines[at.row - top]; - const col = panes.File.rawDisplayCol(p.settings.tab, line, @min(at.col, line.len)); - if (col < tw) s.cursor = .{ .x = tx + @as(u16, @intCast(col)), .y = tag_y + @as(u16, @intCast(at.row - top)), .bar = true }; - } - }; // the caret: bar while typing, block in normal mode (same rule as a body) if (caret) |at| { const col = panes.File.rawDisplayCol(p.settings.tab, lines[at.row], at.at) -| pane.tag_scroll; @@ -1880,7 +1916,8 @@ test "a tag out of rest draws its keys bold in the key ink and its hint in the d p.sync(); const s = try p.render(a); const r = p.view().rects[p.view().active]; - const row = s.cells[@as(usize, r.y) * s.cols ..][0 .. @as(usize, s.cols) * pardes.Band.covered(p, pane, p.view().active).text]; + const drawn = pardes.Band.covered(p, pane, p.view().active); + const row = s.cells[@as(usize, r.y + drawn.tag) * s.cols ..][0 .. @as(usize, s.cols) * drawn.head]; const Row = struct { fn find(cells: []const Cell, word: []const u8) ?usize { var at: usize = 0; |
