summaryrefslogtreecommitdiff
path: root/core/draw.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/draw.zig')
-rw-r--r--core/draw.zig65
1 files changed, 33 insertions, 32 deletions
diff --git a/core/draw.zig b/core/draw.zig
index 7091f61e..f4b08635 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -148,8 +148,8 @@ const Printed = struct { left: u16, dropped: usize };
/// band loses its HEAD: the end is the part that says something -- a
/// path's file name, an error's reason -- and `dropped` is how many
/// columns of it went.
-fn printRight(s: *Surface, x: u16, row: u16, w: u16, text: []const u8, style: CellStyle) Printed {
- const width = panes.File.displayWidth(text);
+fn printRight(tab: u16, s: *Surface, x: u16, row: u16, w: u16, text: []const u8, style: CellStyle) Printed {
+ const width = panes.File.displayWidth(tab, text);
if (width <= w) {
const left: u16 = @intCast(x + w - width);
_ = s.print(left, row, @intCast(width), text, style);
@@ -158,10 +158,10 @@ fn printRight(s: *Surface, x: u16, row: u16, w: u16, text: []const u8, style: Ce
// Whole glyphs only: a cut inside a wide one would leave the rest a
// column too wide and clip its LAST glyph instead of the first.
var dropped = width - w;
- var start = panes.File.rawAtDisplay(text, dropped);
- if (panes.File.rawDisplayCol(text, start) < dropped) {
+ var start = panes.File.rawAtDisplay(tab, text, dropped);
+ if (panes.File.rawDisplayCol(tab, text, start) < dropped) {
dropped += 1;
- start = panes.File.rawAtDisplay(text, dropped);
+ start = panes.File.rawAtDisplay(tab, text, dropped);
}
const left: u16 = @intCast(x + w - (width - dropped));
_ = s.print(left, row, @intCast(width - dropped), text[start..], style);
@@ -189,9 +189,9 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
if (text.len == 0 or r.w <= TAG_TEXT_INSET) {
s.fill(region.rect.x, region.rect.y, chip, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
if (text.len == 0) return;
- const printed = printRight(s, region.rect.x, region.rect.y, chip -| 1, text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
+ const printed = printRight(p.settings.tab, s, region.rect.x, region.rect.y, chip -| 1, text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
if (kind != .prompt or id != v.active or pane.prompt == .del_side or pane.prompt == .repl_choice) return;
- const prompt_col = panes.File.displayWidth(text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]);
+ const prompt_col = panes.File.displayWidth(p.settings.tab, text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]);
if (prompt_col < printed.dropped) return;
s.cursor = .{ .x = @intCast(printed.left + (prompt_col - printed.dropped)), .y = region.rect.y, .bar = pane.input.mode == .insert };
return;
@@ -203,14 +203,14 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
// something.
const capacity = layout.tagCapacity(p, chip);
const room = capacity -| 1;
- const shown = panes.File.displayWidth(text);
+ const shown = panes.File.displayWidth(p.settings.tab, text);
var kept = text;
if (shown > room) {
- var start = panes.File.rawAtDisplay(text, shown - room);
- if (panes.File.rawDisplayCol(text, start) < shown - room) start = panes.File.rawAtDisplay(text, shown - room + 1);
+ var start = panes.File.rawAtDisplay(p.settings.tab, text, shown - room);
+ if (panes.File.rawDisplayCol(p.settings.tab, text, start) < shown - room) start = panes.File.rawAtDisplay(p.settings.tab, text, shown - room + 1);
kept = text[start..];
}
- const pad = room -| panes.File.displayWidth(kept);
+ const pad = room -| panes.File.displayWidth(p.settings.tab, kept);
const line = try arena.alloc(u8, pad + kept.len);
@memset(line[0..pad], ' ');
@memcpy(line[pad..], kept);
@@ -218,8 +218,8 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
try renderHeaderLayer(p, layer, .notice, @intCast(id), region.rect, line, 0, bg, fg);
// The caret rides the band, where the prompt's glyphs are.
if (kind == .prompt and id == v.active and pane.prompt != .del_side and pane.prompt != .repl_choice) caret: {
- const typed = panes.File.displayWidth(text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]);
- const dropped = shown - panes.File.displayWidth(kept);
+ const typed = panes.File.displayWidth(p.settings.tab, text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]);
+ const dropped = shown - panes.File.displayWidth(p.settings.tab, kept);
if (typed < dropped) break :caret;
layer.cursor = .{ .x = @intCast(pad + typed - dropped), .y = 0, .bar = pane.input.mode == .insert };
}
@@ -252,6 +252,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
}
s.cols = v.screen_w;
s.rows = v.screen_h;
+ s.tab = p.settings.tab;
s.cursor = null;
s.pointer_shape = .arrow;
// A look-hover preview means the pointed word is a real Look or Exec
@@ -593,7 +594,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
return;
}
var widest: usize = 0;
- for (0..viewport.h) |line| widest = @max(widest, panes.File.displayWidth(modal.lineSlice(text, line + top)));
+ for (0..viewport.h) |line| widest = @max(widest, panes.File.displayWidth(p.settings.tab, modal.lineSlice(text, line + top)));
const columns: u16 = @intCast(@min(std.math.maxInt(u16), @max(layout.tagCapacity(p, viewport.w), widest + 1)));
const count = @as(usize, columns) * viewport.h;
if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count);
@@ -618,10 +619,10 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
for (0..viewport.h) |index| {
const line: u16 = @intCast(index);
const shown = modal.lineSlice(text, index + top);
- var surface: Surface = .{ .cols = columns, .rows = 1, .cells = layer.cells[index * columns ..][0..columns] };
+ var surface: Surface = .{ .cols = columns, .rows = 1, .cells = layer.cells[index * columns ..][0..columns], .tab = p.settings.tab };
surface.fill(0, 0, columns, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
// The scroll is the caret's line's: a shorter line shows nothing.
- _ = surface.print(0, 0, columns, shown[@min(shown.len, panes.File.rawAtDisplay(shown, scroll))..], .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
+ _ = surface.print(0, 0, columns, shown[@min(shown.len, panes.File.rawAtDisplay(p.settings.tab, shown, scroll))..], .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
// The word under the pointer, a Look or Exec target: on a header even
// while it is edited, on a notice, and on the grid's copy of either
// (joined from this); not on a column a carried column's pointer is
@@ -636,9 +637,9 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
v.hover_col - viewport.x
else
null;
- if (col) |hover| if (wordBoundsAtCol(shown, panes.File.rawAtDisplay(shown, hover + scroll))) |bounds| {
- var cell = panes.File.rawDisplayCol(shown, bounds.lo) -| scroll;
- const end = panes.File.rawDisplayCol(shown, bounds.hi) -| scroll;
+ if (col) |hover| if (wordBoundsAtCol(shown, panes.File.rawAtDisplay(p.settings.tab, shown, hover + scroll))) |bounds| {
+ var cell = panes.File.rawDisplayCol(p.settings.tab, shown, bounds.lo) -| scroll;
+ const end = panes.File.rawDisplayCol(p.settings.tab, shown, bounds.hi) -| scroll;
while (cell < end and cell < columns) : (cell += 1) {
surface.at(@intCast(cell), 0).style.bg = .{ .rgb = p.theme().tag_sel_bg orelse p.theme().sel_bg };
surface.at(@intCast(cell), 0).style.fg = .{ .rgb = p.theme().sel_fg };
@@ -647,14 +648,14 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
}
if (editing) |t| {
if (tagline.headerSelection(t, try edit.flatSurface(p.editor(), t), line + v.header_top)) |span| {
- var col = panes.File.rawDisplayCol(shown, span.lo) -| scroll;
- const end = panes.File.rawDisplayCol(shown, span.hi) -| scroll;
+ var col = panes.File.rawDisplayCol(p.settings.tab, shown, span.lo) -| scroll;
+ const end = panes.File.rawDisplayCol(p.settings.tab, shown, span.hi) -| scroll;
while (col < end and col < columns) : (col += 1) {
surface.at(@intCast(col), 0).style.bg = .{ .rgb = p.theme().tag_sel_bg orelse p.theme().sel_bg };
surface.at(@intCast(col), 0).style.fg = .{ .rgb = p.theme().sel_fg };
}
}
- const caret = panes.File.rawDisplayCol(shown, @min(@as(usize, @intCast(@max(0, t.cur_col))), shown.len)) -| scroll;
+ const caret = panes.File.rawDisplayCol(p.settings.tab, shown, @min(@as(usize, @intCast(@max(0, t.cur_col))), shown.len)) -| scroll;
const asking = if (p.panes[v.active]) |active| active.prompt != .none else false;
if (!asking and t.cur_row == line + v.header_top and caret < columns) layer.cursor = .{ .x = @intCast(caret), .y = line, .bar = t.mode == .insert };
}
@@ -671,8 +672,8 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
const end = start + shown.len;
if (mine and swept.lo < swept.hi and swept.hi > start and swept.lo < end) {
const button = @backingInt(sweep.button);
- var col = panes.File.rawDisplayCol(shown, @max(swept.lo, start) - start) -| scroll;
- const stop = panes.File.rawDisplayCol(shown, @min(swept.hi, end) - start) -| scroll;
+ var col = panes.File.rawDisplayCol(p.settings.tab, shown, @max(swept.lo, start) - start) -| scroll;
+ const stop = panes.File.rawDisplayCol(p.settings.tab, shown, @min(swept.hi, end) - start) -| scroll;
while (col < stop and col < columns) : (col += 1) {
surface.at(@intCast(col), 0).style.bg = .{ .rgb = body_layer.buttonTints(p.theme())[button] };
surface.at(@intCast(col), 0).style.fg = .{ .rgb = body_layer.buttonInks(p.theme())[button] };
@@ -698,12 +699,12 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
var widest: usize = 0;
var split = std.mem.splitScalar(u8, tag, '\n');
for (0..pane.tag_top) |_| _ = split.next();
- for (0..rows) |_| widest = @max(widest, panes.File.displayWidth(split.next() orelse ""));
+ for (0..rows) |_| widest = @max(widest, panes.File.displayWidth(p.settings.tab, split.next() orelse ""));
const columns: u16 = @intCast(@min(std.math.maxInt(u16) - TAG_TEXT_INSET, @max(capacity, widest + 1)));
const pitch = @as(usize, columns) + TAG_TEXT_INSET;
const storage = try arena.alloc(Cell, pitch * rows);
@memset(storage, .{});
- var temporary: Surface = .{ .cols = columns + TAG_TEXT_INSET, .rows = rows, .cells = storage };
+ var temporary: Surface = .{ .cols = columns + TAG_TEXT_INSET, .rows = rows, .cells = storage, .tab = p.settings.tab };
try paintPaneTag(p, &temporary, arena, pane, .{ .x = 0, .y = 0, .w = columns + TAG_TEXT_INSET, .h = rows }, id, active);
// Window mode (layout.windowKey): the outlined pane's tag in the
// selection's colours.
@@ -792,7 +793,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
pane.tag_scroll = 0;
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(line, pane.tag_scroll));
+ 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);
}
// The name's tint, in the tag's first line, over whichever rows it
@@ -807,8 +808,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
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(line, @min(from, line.len));
- const end = panes.File.rawDisplayCol(line, @min(to, 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 };
@@ -830,15 +831,15 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const line = lines[row - top];
const from = if (row == first.row) first.col else 0;
const to = @min(line.len, if (row == last.row) last.col else line.len);
- const col = panes.File.rawDisplayCol(line, from) -| pane.tag_scroll;
- const end = @min(panes.File.rawDisplayCol(line, to) -| pane.tag_scroll, tw);
+ const col = panes.File.rawDisplayCol(p.settings.tab, line, from) -| pane.tag_scroll;
+ const end = @min(panes.File.rawDisplayCol(p.settings.tab, line, to) -| pane.tag_scroll, tw);
if (col < end) s.tint(tx + @as(u16, @intCast(col)), tag_y + @as(u16, @intCast(row - top)), @intCast(end - col), th.tag_sel_bg orelse th.sel_bg, th.sel_fg);
}
}
}
// the caret: bar while typing, block in normal mode (same rule as a body)
if (caret) |at| {
- const col = panes.File.rawDisplayCol(lines[at.row], at.at) -| pane.tag_scroll;
+ const col = panes.File.rawDisplayCol(p.settings.tab, lines[at.row], at.at) -| pane.tag_scroll;
const mode = if (pane.prompt == .name) pane.input.mode else pane.tag.mode;
if (col < tw) s.cursor = .{ .x = tx + @as(u16, @intCast(col)), .y = tag_y + @as(u16, @intCast(at.row)), .bar = mode == .insert };
}