diff options
Diffstat (limited to 'core/draw.zig')
| -rw-r--r-- | core/draw.zig | 91 |
1 files changed, 87 insertions, 4 deletions
diff --git a/core/draw.zig b/core/draw.zig index de08ef4f..37fdee1e 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -360,6 +360,18 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { 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); @@ -483,6 +495,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: }, box_style); try joinPaneTag(p, s, arena, pane, r, id, active); + if (pane.band_rows > 0) try joinBand(p, s, arena, pane, r, id, active); // Folded panes retain their body state, but neither body pixels nor // its cursor belong outside the one-row tag rectangle. @@ -667,7 +680,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v const editing: ?*Text = if (v.header != null and switch (kind) { .workspace => p.headerColumn() == null, .column => p.headerColumn() == id, - .pane, .notice, .body => false, + .pane, .notice, .body, .band => false, }) tagline.focusedHeader(p) else null; const scroll = if (editing != null) v.header_scroll else 0; for (0..viewport.h) |index| { @@ -719,7 +732,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v const mine = switch (kind) { .workspace => column == null, .column => column == id, - .pane, .notice, .body => false, + .pane, .notice, .body, .band => false, }; const swept = sweep.span(text.len); const start = modal.lineStartOffset(text, index + top); @@ -747,7 +760,8 @@ 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; - const rows = pane.tag_rows; + // The tag's text rows; the band's under them are its own layer. + const rows = pane.tag_rows - pane.band_rows; // As wide as the widest row it shows, and never narrower than its // viewport. var widest: usize = 0; @@ -794,13 +808,82 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r } } +/// The band under pane `id`'s tag text (Band.zig), 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. +fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void { + const layer = &s.tag_layers[pardes.BAND_LAYER_BASE + id]; + 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 = if (active) chrome.tag_active_bg else chrome.tag_bg; + const fg = if (active) chrome.tag_active_fg else chrome.tag_fg; + 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.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. + 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 }; + 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); + 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.bold = true; + } + if (part.row.dim) style.dim = true; + if (part.row.under) style.ul = .single; + for (part.row.marks) |m| if (m == b) { + style.bg = .{ .rgb = chrome.search_bg }; + }; + b = next; + } + } + } + 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); + layer.kind = .band; + layer.id = @intCast(id); + layer.serial = pane.serial; + layer.viewport = .{ .x = r.x + TAG_TEXT_INSET, .y = y0, .w = r.w - TAG_TEXT_INSET, .h = rows }; + layer.cols = columns; + layer.rows = rows; + layer.context_rows = 0; + 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 }); +} + fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void { const th = p.theme(); const chrome = p.chromeTheme(); 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; + 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 = if (active) chrome.tag_active_bg else chrome.tag_bg; |
