summaryrefslogtreecommitdiff
path: root/core/draw.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/draw.zig')
-rw-r--r--core/draw.zig99
1 files changed, 68 insertions, 31 deletions
diff --git a/core/draw.zig b/core/draw.zig
index 16dfde5e..a459e3e9 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -362,23 +362,16 @@ 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 band over a terminal's or a kind's body (Band.over), drawn after
+ // the body it covers.
+ if (TagState.hostOf(p)) |id| if (p.panes[id]) |pane| if (pane.band_rows == 0) {
+ const rows = pardes.Band.shownRows(p, pane, id);
+ if (rows > 0) try joinBand(p, s, arena, pane, v.rects[id], id, id == v.active, rows);
+ };
// Each notice once, as a tag layer, and the grid's chip a copy of it.
for (s.regionList()) |region| {
if (region.kind == .notice) try joinNotice(p, s, arena, region);
}
- // A tag out of rest: the other panes dim a little so the eye goes to
- // it, but a pane showing a preview (walk UI SPEC §3.6).
- if (TagState.hostOf(p)) |host| for (p.panes, 0..) |slot, id| {
- if (slot == null or id == host or v.tag_state.previewing.isSet(id)) continue;
- const r = v.rects[id];
- for (r.y..r.y + r.h) |y| for (r.x..r.x + r.w) |x| {
- s.at(@intCast(x), @intCast(y)).style.dim = true;
- };
- for ([_]*pardes.Layer{ &s.body_layers[id], &s.tag_layers[id] }) |layer| for (layer.cells[0 .. @as(usize, layer.cols) * layer.rows]) |*cell| {
- cell.style.dim = true;
- };
- };
-
try paintHeaders(p, s);
try paintNoticeRow(p, s);
@@ -513,7 +506,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
try joinPaneTag(p, s, arena, pane, r, id, active);
// The keyboard is in the head's field: its caret, not the body's.
const head_caret = if (typing) s.cursor else null;
- if (pane.band_rows > 0) try joinBand(p, s, arena, pane, r, id, active);
+ if (pane.band_rows > 0) try joinBand(p, s, arena, pane, r, id, active, pane.band_rows);
// Folded panes retain their body state, but neither body pixels nor
// its cursor belong outside the one-row tag rectangle.
@@ -704,6 +697,8 @@ 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");
@@ -841,8 +836,9 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
const chrome = p.chromeTheme();
const region = s.region(.tag, id).?;
const tag = (try tagline.shownTag(p, arena, pane)).text;
- // The tag's text rows; the band's under them are its own layer.
- const rows = pane.tag_rows - pane.band_rows;
+ // The tag's text rows; the band's under them are its own layer. A
+ // tag's own are MAX_TAG_ROWS at most (Pardes.sync).
+ const rows = @min(pane.tag_rows -| pane.band_rows, MAX_TAG_ROWS);
// As wide as the widest row it shows, and never narrower than its
// viewport.
var widest: usize = 0;
@@ -893,13 +889,12 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
/// 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) !void {
+fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, rows: u16) !void {
const layer = &s.tag_layers[pardes.BAND_LAYER];
if (r.w <= TAG_TEXT_INSET) return;
const band = (try pardes.Band.of(p, arena, pane, id)) orelse return;
const chrome = p.chromeTheme();
const tab = p.settings.tab;
- const rows = pane.band_rows;
const columns = @max(band.columns, 1);
// The walk UI's inks on this tag's ground (colors.Roles, UX DESIGN.md
// D4), and on its cursor row's selection.
@@ -930,7 +925,13 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
for (ln.parts) |part| {
const end = @min(columns, part.col + part.width);
const on = if (part.row.on) selected else inks;
- if (part.row.on and part.col < end) t.tint(part.col, row, end - part.col, selected.ground, selected.text);
+ // The cursor's row across its step's width, its lead too (UX
+ // D5), the lead's `▶` keeping the key ink (D4).
+ if (part.row.on and part.col < end) {
+ const lead = part.col -| 2;
+ t.tint(lead, row, part.col - lead, selected.ground, null);
+ 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) {
@@ -968,7 +969,9 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
const count = @as(usize, columns) * rows;
if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count);
@memcpy(layer.cells, storage);
- const y0 = p.tagTop(pane, r) + (pane.tag_rows - rows);
+ // Under the tag's text rows; a terminal's or a kind's over its body's
+ // top rows (Band.over).
+ const y0 = p.tagTop(pane, r) + (pane.tag_rows - pane.band_rows);
layer.kind = .band;
layer.id = @intCast(id);
layer.serial = pane.serial;
@@ -984,7 +987,7 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
/// Bytes `lo` to `hi` of a tag's text in `ink`, over whichever of its
/// shown rows (`lines`, from shown row `top`, drawn at `x`, `y`, `w`
/// wide) they wrapped onto.
-fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const u8, top: usize, x: u16, y: u16, w: u16, lo: usize, hi: usize, ink: [3]u8) void {
+fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const u8, top: usize, x: u16, y: u16, w: u16, lo: usize, hi: usize, ink: [3]u8, under: bool) void {
const a = modal.positionAt(shown.text, shown.fromReal(lo));
const b = modal.positionAt(shown.text, shown.fromReal(hi));
var row = @max(a.row, top);
@@ -995,8 +998,11 @@ fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const
var col = panes.File.rawDisplayCol(p.settings.tab, line, @min(from, line.len));
const end = panes.File.rawDisplayCol(p.settings.tab, line, @min(to, line.len));
const row_y = y + @as(u16, @intCast(row - top));
- while (col < end and col < w) : (col += 1)
- s.at(x + @as(u16, @intCast(col)), row_y).style.fg = .{ .rgb = ink };
+ while (col < end and col < w) : (col += 1) {
+ const style = &s.at(x + @as(u16, @intCast(col)), row_y).style;
+ style.fg = .{ .rgb = ink };
+ if (under) style.ul = .single;
+ }
}
}
@@ -1019,7 +1025,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const tx = r.x + @min(TAG_TEXT_INSET, r.w);
const tw = r.w -| TAG_TEXT_INSET;
const tag_y = p.tagTop(pane, r);
- const rows = pane.tag_rows - pane.band_rows;
+ const rows = @min(pane.tag_rows -| pane.band_rows, MAX_TAG_ROWS);
const page_rgb = th.bg orelse th.tag_bg;
// Focus is visible along the tag without changing its live text grid.
const inks = chrome.roles.on(groundOf(p, pane, active));
@@ -1047,7 +1053,11 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
var lines: [MAX_TAG_ROWS][]const u8 = @splat("");
var split = std.mem.splitScalar(u8, shown.text, '\n');
for (0..top) |_| _ = split.next();
- for (lines[0..rows]) |*line| line.* = split.next() orelse "";
+ var nlines: usize = 0;
+ for (lines[0..rows]) |*line| {
+ line.* = split.next() orelse continue;
+ nlines += 1;
+ }
// The keyboard's caret, as a row and a byte offset in that row's
// line: in the tag's own text when the tag has the keyboard, in the
// path while a name is drafted.
@@ -1074,9 +1084,22 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const start = @min(line.len, panes.File.rawAtDisplay(p.settings.tab, line, pane.tag_scroll));
_ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], text_style);
}
+ // Out of rest the rows the tag keeps from rest under the head's own:
+ // the spines on through them, under the key cells (UX D5).
+ if (head) |h| if (top == 0 and nlines < rows and h.cells > 0) {
+ const first = lines[0];
+ for (h.spans[0..h.cells]) |cell| {
+ const at = prefix_len + cell.lo;
+ if (at > first.len) break;
+ const col = panes.File.rawDisplayCol(p.settings.tab, first, at);
+ if (col >= tw) break;
+ for (nlines..rows) |row| s.set(tx + @as(u16, @intCast(col)), tag_y + @as(u16, @intCast(row)), "│", .{ .fg = .{ .rgb = inks.rule }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline });
+ }
+ };
// The pane's progress at its first row's right end, where the row has
- // room for it (SPEC §10.2).
- if (top == 0 and rows > 0) for (p.messages.live[0..p.messages.live_len]) |*said| {
+ // 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| {
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;
@@ -1089,12 +1112,26 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
// wrapped onto.
const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len];
if (tagTintRange(p, pane, first_line, prefix_len)) |name| if (name.lo < name.hi)
- inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, name.lo, @min(name.hi, first_line.len), if (active) chrome.tag_active_name_fg else chrome.tag_name_fg);
- // A walk's forward steps, after the name, dimmed (Trail.zig).
+ inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, name.lo, @min(name.hi, first_line.len), if (active) chrome.tag_active_name_fg else chrome.tag_name_fg, false);
+ // A walk's forward steps, after the name, dimmed (Trail.zig); its fold
+ // `+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);
+ 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)) {
+ const kept = tagline.folded(p, pane);
+ const t = &pane.trail;
+ const first: usize = @intFromBool(t.steps[0] == .owner);
+ if (t.isFolded(first, kept)) {
+ const fold = t.spanOf(first, kept);
+ inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, fold[0], @min(fold[1], first_line.len), inks.dim, false);
+ }
+ if (t.walked()) |i| if (!t.isFolded(i, kept)) {
+ const word = t.spanOf(i, kept);
+ inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, word[0], @min(word[1], first_line.len), chrome.roles.key, true);
+ };
+ }
// 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);
+ 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| {