summaryrefslogtreecommitdiff
path: root/core/draw.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/draw.zig')
-rw-r--r--core/draw.zig62
1 files changed, 39 insertions, 23 deletions
diff --git a/core/draw.zig b/core/draw.zig
index 772cbece..bc606f02 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -467,7 +467,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
// its ring. A pixel shell draws the ring (gui.zig gripDecor); a grid,
// which cannot, marks dirty in the grip's second cell with a bold `*`
// on the dirty colour, a cue that survives any palette.
- const band = if (active) chrome.tag_active_bg else chrome.tag_bg;
+ const band = tagGround(p, pane, active);
const dirty = tagline.dirty(pane);
const box_bg = gripBg(p, active);
const box_style: CellStyle = .{
@@ -642,7 +642,7 @@ fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct {
}
return null;
}
- var start: usize = 0;
+ var start: usize = tagline.nameAt(pane);
const name = if (pane.file) |file|
if (pane.prompt == .name) pane.input.own orelse file.path else file.path
else if (pane.addon) |k| blk: {
@@ -800,7 +800,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
layer.cols = columns;
layer.rows = rows;
layer.context_rows = 0;
- layer.bg = if (v.window_pick == id) p.theme().sel_bg else if (active) chrome.tag_active_bg else chrome.tag_bg;
+ layer.bg = if (v.window_pick == id) p.theme().sel_bg else tagGround(p, pane, active);
layer.cursor = if (v.header != null) null else if (temporary.cursor) |cursor|
.{ .x = cursor.x - TAG_TEXT_INSET, .y = cursor.y, .bar = cursor.bar }
else
@@ -830,7 +830,7 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
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 bg = tagGround(p, pane, active);
const fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
const storage = try arena.alloc(Cell, @as(usize, columns) * rows);
@memset(storage, .{});
@@ -886,6 +886,33 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
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 });
}
+/// 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 {
+ const a = modal.positionAt(shown.text, shown.fromReal(lo));
+ const b = modal.positionAt(shown.text, shown.fromReal(hi));
+ var row = @max(a.row, top);
+ while (row <= b.row and row < top + lines.len) : (row += 1) {
+ const line = lines[row - top];
+ const from = if (row == a.row) a.col else 0;
+ const to = if (row == b.row) b.col else line.len;
+ 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 };
+ }
+}
+
+/// 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;
+}
+
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();
@@ -895,7 +922,7 @@ 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 = if (active) chrome.tag_active_bg else chrome.tag_bg;
+ const tag_bg = tagGround(p, pane, active);
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
@@ -927,7 +954,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
else if (pane.prompt == .name) caret: {
// A drafted name is the prefix: its caret is on row 0 of the tag,
// the rows it wrapped onto included.
- const at = modal.positionAt(shown.text, shown.fromReal(@intCast(@max(0, pane.input.cur_col))));
+ const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(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: {
@@ -947,22 +974,11 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
// The name's tint, in the tag's first line, over whichever rows it
// wrapped onto.
const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len];
- if (tagTintRange(pane, first_line, prefix_len)) |name| if (name.lo < name.hi) {
- const name_fg = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg;
- const a = modal.positionAt(shown.text, shown.fromReal(name.lo));
- const b = modal.positionAt(shown.text, shown.fromReal(@min(name.hi, first_line.len)));
- var row = @max(a.row, top);
- while (row <= b.row and row < top + rows) : (row += 1) {
- const line = lines[row - top];
- const from = if (row == a.row) a.col else 0;
- const to = if (row == b.row) b.col else line.len;
- 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 y = tag_y + @as(u16, @intCast(row - top));
- while (col < end and col < tw) : (col += 1)
- s.at(tx + @as(u16, @intCast(col)), y).style.fg = .{ .rgb = name_fg };
- }
- };
+ if (tagTintRange(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).
+ const ahead = tagline.forwardSpan(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);
// 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| {
@@ -1177,7 +1193,7 @@ test "a tag of three rows has its grip on the first, and band under it that stil
const top = p.tagTop(pane, r);
try std.testing.expect(pane.tag_rows >= 3);
const chrome = p.chromeTheme();
- const band = chrome.tag_active_bg;
+ const band = tagGround(p, pane, true);
for (0..config.GUTTER) |dx| {
const x = r.x + @as(u16, @intCast(dx));
try std.testing.expectEqual(Color{ .rgb = chrome.box }, s.at(x, top).style.bg);