summaryrefslogtreecommitdiff
path: root/core/draw.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/draw.zig')
-rw-r--r--core/draw.zig171
1 files changed, 144 insertions, 27 deletions
diff --git a/core/draw.zig b/core/draw.zig
index 68778667..16dfde5e 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -173,10 +173,15 @@ pub fn place(p: *Pardes, s: *Surface) void {
/// A pane's grip in the grid: `box` focused, else halfway between its ring
/// and `box_dim`, so it shows on its tag without the ring a pixel shell
/// draws (gui.zig draws its button from the region and Chrome instead).
-fn gripBg(p: *const Pardes, active: bool) [3]u8 {
+/// A grip cell's colour: the focused pane's button, else its ring mixed
+/// with the box's dim fill; where that fill is the tag's own ground
+/// (acme's), a reading pane's is its tint, as a window rings a reading
+/// pane's tag ground (gui.zig gripFill).
+fn gripBg(p: *const Pardes, active: bool, reading: bool) [3]u8 {
const chrome = p.chromeTheme();
if (active) return chrome.box;
- return colors.mix(boxBorder(p), chrome.box_dim);
+ const fill = if (reading and std.mem.eql(u8, &chrome.box_dim, &chrome.tag_bg)) chrome.tag_reading_bg else chrome.box_dim;
+ return colors.mix(boxBorder(p), fill);
}
/// An unfocused grip's ring, and a dirty one's fill (colors.Theme).
@@ -471,7 +476,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
// on the dirty colour, a cue that survives any palette.
const band = tagGround(p, pane, active);
const dirty = tagline.dirty(pane);
- const box_bg = gripBg(p, active);
+ const box_bg = gripBg(p, active, pardes.Trail.reading(p, pane));
const box_style: CellStyle = .{
.fg = .{ .rgb = inkOn(box_bg) },
.bg = .{ .rgb = box_bg },
@@ -635,12 +640,21 @@ fn paintNoticeRow(p: *Pardes, s: *Surface) !void {
const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER];
try renderHeaderLayer(p, layer, .notice_row, 0, viewport, row.text, 0, chrome.tagline_bg, chrome.tagline_fg);
if (layer.rows == 0) return;
- const dim: Color = .{ .rgb = colors.mix(chrome.tagline_fg, chrome.tagline_bg) };
+ // The dim ink of the notice row's ground (colors.Roles: 3:1 at least).
+ const dim: Color = .{ .rgb = chrome.roles.notice.dim };
const ink: Color = .{ .rgb = chrome.tagline_fg };
const cells = layer.cells[0..layer.cols];
const tab = p.settings.tab;
const left = @min(cells.len, panes.File.displayWidth(tab, row.text[0..row.left]));
const right = @min(cells.len, panes.File.displayWidth(tab, row.text[0..row.right]));
+ // A picker's sentence: dim, its address in the text's ink.
+ if (row.quiet_left) {
+ const lo = panes.File.displayWidth(tab, row.text[0..@min(row.word[0], row.left)]);
+ const hi = panes.File.displayWidth(tab, row.text[0..@min(row.word[1], row.left)]);
+ for (cells[0..left], 0..) |*cell, x| if ((x < lo or x >= hi) and std.meta.eql(cell.style.fg, ink)) {
+ cell.style.fg = dim;
+ };
+ }
if (row.lead) |lead| {
if (lead.kind == .@"error" or lead.kind == .warn) if (cells.len > 0 and std.meta.eql(cells[0].style.fg, ink)) {
cells[0].style.fg = .{ .rgb = if (lead.kind == .@"error") chrome.diagnostic_error else chrome.diagnostic_warning };
@@ -883,13 +897,17 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
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 th = p.theme();
const chrome = p.chromeTheme();
const tab = p.settings.tab;
const rows = pane.band_rows;
const columns = @max(band.columns, 1);
- const bg = tagGround(p, pane, active);
- const fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
+ // 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);
+ const inks = chrome.roles.on(ground);
+ const selected = chrome.roles.selectedOn(ground);
+ const bg = inks.ground;
+ const fg = inks.text;
const storage = try arena.alloc(Cell, @as(usize, columns) * rows);
@memset(storage, .{});
var t: Surface = .{ .cols = columns, .rows = rows, .cells = storage, .tab = tab };
@@ -898,35 +916,53 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
t.fill(0, row, columns, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
const ln = try band.line(arena, tab, row);
_ = t.print(0, row, columns, ln.text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
- // The spines and the rules between steps: the key ink.
+ // The spines and the rules between steps in the rule ink; a row's
+ // `▶` (the cursor) and `•` (marked) in the key ink.
var col: u16 = 0;
var at: usize = 0;
while (at < ln.text.len and col < columns) : (col += 1) {
const next = modal.nextGrapheme(ln.text, at);
- if (std.mem.eql(u8, ln.text[at..next], "│")) t.at(col, row).style.fg = .{ .rgb = chrome.box };
- if (std.mem.eql(u8, ln.text[at..next], "▶")) t.at(col, row).style.fg = .{ .rgb = chrome.box };
+ const glyph = ln.text[at..next];
+ if (std.mem.eql(u8, glyph, "│")) t.at(col, row).style.fg = .{ .rgb = inks.rule };
+ if (std.mem.eql(u8, glyph, "▶") or std.mem.eql(u8, glyph, "•")) t.at(col, row).style.fg = .{ .rgb = chrome.roles.key };
at = next;
}
for (ln.parts) |part| {
const end = @min(columns, part.col + part.width);
- if (part.row.on and part.col < end) t.tint(part.col, row, end - part.col, th.tag_sel_bg orelse th.sel_bg, th.sel_fg);
+ 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);
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);
const style = &t.at(c, row).style;
if (b < part.row.key) {
- style.fg = .{ .rgb = chrome.box };
+ 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)) style.dim = true;
+ 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 };
+ for (part.row.keys) |k| if (k == b) {
+ style.fg = .{ .rgb = chrome.roles.key };
+ style.bold = true;
+ };
if (part.row.under) style.ul = .single;
+ // 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) {
- style.bg = .{ .rgb = chrome.search_bg };
+ style.fg = .{ .rgb = chrome.roles.match };
+ style.bold = true;
};
b = 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) {
+ const meta: u16 = @intCast(panes.File.displayWidth(tab, part.row.meta));
+ 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;
@@ -967,9 +1003,14 @@ fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const
/// A pane's tag's ground: a reading pane's tint (its focus is its grip's),
/// else the focused tag's or the tag's.
fn tagGround(p: *Pardes, pane: *const Pane, active: bool) [3]u8 {
- const chrome = p.chromeTheme();
- if (pardes.Trail.reading(p, pane)) return chrome.tag_reading_bg;
- return if (active) chrome.tag_active_bg else chrome.tag_bg;
+ return p.chromeTheme().roles.on(groundOf(p, pane, active)).ground;
+}
+
+/// Which of a tag's grounds pane `pane`'s is: its walk UI inks
+/// (colors.Roles) are that ground's.
+fn groundOf(p: *Pardes, pane: *const Pane, active: bool) colors.TagGround {
+ if (pardes.Trail.reading(p, pane)) return if (active) .reading_focused else .reading;
+ return if (active) .focused else .plain;
}
fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void {
@@ -981,7 +1022,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const rows = pane.tag_rows - pane.band_rows;
const page_rgb = th.bg orelse th.tag_bg;
// Focus is visible along the tag without changing its live text grid.
- const tag_bg = tagGround(p, pane, active);
+ const inks = chrome.roles.on(groundOf(p, pane, active));
+ const tag_bg = inks.ground;
const tag_fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
const tag_style: CellStyle = .{ .fg = .{ .rgb = tag_fg }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline };
// Padding belongs to the same font row but keeps its default ink: a
@@ -995,6 +1037,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const head = try TagState.head(p, arena, pane);
const tail = if (head) |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 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;
@@ -1028,7 +1072,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
for (lines[0..rows], 0..) |line, row| {
// The scroll is the caret's line's: a shorter row shows nothing.
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..], tag_style);
+ _ = 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).
@@ -1048,9 +1092,9 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
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).
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), chrome.lineno);
+ 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);
// 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), chrome.lineno);
+ 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);
// 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| {
@@ -1068,13 +1112,14 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const style = &s.at(tx + @as(u16, @intCast(col)), y).style;
switch (span.style) {
.key => {
- style.fg = .{ .rgb = chrome.box };
+ style.fg = .{ .rgb = chrome.roles.key };
style.bold = true;
},
- .dim => style.dim = true,
+ .dim => style.fg = .{ .rgb = inks.dim },
.under => style.ul = .single,
.strike => style.strikethrough = true,
- .err => style.fg = .{ .rgb = chrome.diagnostic_error },
+ .err => style.fg = .{ .rgb = chrome.roles.err },
+ .rule => style.fg = .{ .rgb = inks.rule },
}
}
}
@@ -1148,6 +1193,7 @@ test "an unfocused grip shows on its tag in the grid, in every native theme" {
p.newScratchBelow(0);
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
+ var ok = true;
for (pardes.themes[0..colors.native_count], 0..) |theme, index| {
colors.setThemeIndex(p, index);
p.view().active = 1;
@@ -1155,12 +1201,16 @@ test "an unfocused grip shows on its tag in the grid, in every native theme" {
const s = try p.render(arena.allocator());
const r = p.view().rects[0];
const grip = s.at(r.x, p.tagTop(p.panes[0].?, r)).style.bg.rgb;
- const ratio = colors.contrast(grip, p.chromeTheme().tag_bg);
+ // Its tag's ground: a reading pane's the reading tint.
+ const ratio = colors.contrast(grip, tagGround(p, p.panes[0].?, false));
// ponytail: dark and helix have always had a faint grip (1.2:1); flagged, not changed here.
const floor: f32 = if (std.mem.eql(u8, theme.name, "dark") or std.mem.eql(u8, theme.name, "helix")) 1.2 else 1.5;
- if (ratio < floor) std.debug.print("{s}: grip {d:.2}\n", .{ theme.name, ratio });
- try std.testing.expect(ratio >= floor);
+ // Against a reading tint (UX D4's, lighter on a dark tag) a little
+ // less: forestbones_dark's 1.486, nordbones' 1.488, monokai's 1.4999.
+ if (ratio < floor - 0.02) std.debug.print("{s}: grip {d:.4}\n", .{ theme.name, ratio });
+ ok = ok and ratio >= floor - 0.02;
}
+ try std.testing.expect(ok);
}
test "a grip's four states, focused or not and clean or dirty, are each its own in every native theme" {
@@ -1745,3 +1795,70 @@ test "progress is said at the right end of its tag: a pane's at its tag's, a ser
s = try p.render(frame.allocator());
try std.testing.expect(std.mem.indexOf(u8, Row.of(s, tag_y, &buf), "\u{22ef}") == null);
}
+
+test "a tag out of rest draws its keys bold in the key ink and its hint in the dim ink, never faint (UX D4)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const roles = &p.chromeTheme().roles;
+ const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused);
+ // SPC's level rolled, after its delay: `␣ ▸ … l lsp… … ↓ unroll · ? help`.
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ 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) * (pane.tag_rows - pane.band_rows)];
+ const Row = struct {
+ fn find(cells: []const Cell, word: []const u8) ?usize {
+ var at: usize = 0;
+ while (at + word.len <= cells.len) : (at += 1) {
+ for (word, cells[at..][0..word.len]) |c, cell| {
+ if (cell.len != 1 or cell.text[0] != c) break;
+ } else return at;
+ }
+ return null;
+ }
+ };
+ const hint = Row.find(row, "unroll").?;
+ try std.testing.expectEqual(Color{ .rgb = inks.dim }, row[hint].style.fg);
+ for (row) |cell| try std.testing.expect(!cell.style.dim);
+ var keys: usize = 0;
+ for (row) |cell| if (std.meta.eql(cell.style.fg, Color{ .rgb = roles.key })) {
+ try std.testing.expect(cell.style.bold);
+ keys += 1;
+ };
+ try std.testing.expect(keys > 3);
+}
+
+test "an unfocused reading pane's box in the grid is its ring round the reading tint where the box's fill is the tag's own ground (acme's), as a window draws it; a held pane's, or another theme's, as before" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ const reader = p.view().active;
+ p.newScratchBelow(reader);
+ colors.setThemeIndex(p, colors.themeIndex("acme").?);
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ try std.testing.expect(pardes.Trail.reading(p, pane) and p.view().active != reader);
+ var s = try p.render(frame.allocator());
+ const r = p.view().rects[reader];
+ const want = colors.mix(boxBorder(p), p.chromeTheme().tag_reading_bg);
+ for (0..config.GUTTER) |x| try std.testing.expectEqual(Color{ .rgb = want }, s.at(r.x + @as(u16, @intCast(x)), r.y).style.bg);
+ // Held, the ring round the plain box.
+ pane.trail.held = true;
+ s = try p.render(frame.allocator());
+ try std.testing.expectEqual(Color{ .rgb = colors.mix(boxBorder(p), p.chromeTheme().tag_bg) }, s.at(r.x, r.y).style.bg);
+ // orchard's box has a fill of its own: a reader's keeps it.
+ pane.trail.held = false;
+ colors.setThemeIndex(p, colors.themeIndex("orchard").?);
+ s = try p.render(frame.allocator());
+ try std.testing.expectEqual(Color{ .rgb = colors.mix(boxBorder(p), p.chromeTheme().box_dim) }, s.at(r.x, r.y).style.bg);
+}