summaryrefslogtreecommitdiff
path: root/src/draw.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/draw.zig')
-rw-r--r--src/draw.zig192
1 files changed, 99 insertions, 93 deletions
diff --git a/src/draw.zig b/src/draw.zig
index 4c476914..c97e2a6c 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -42,16 +42,17 @@ const NOTICE_LAYER_BASE = pardes.NOTICE_LAYER_BASE;
/// and notice chips; each column's grip and tag; the workspace tag. The
/// painters below and every shell read these rectangles.
pub fn place(p: *Pardes, s: *Surface) void {
+ const v = p.view();
s.nregions = 0;
s.nrail_ticks = 0;
s.addRegion(.{ .kind = .page, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = s.rows } });
for (&p.panes, 0..) |*slot, id| {
const pane = slot.* orelse continue;
- Messages.collectNotices(p, pane, p.rects[id], id);
- const r = p.rects[id];
+ Messages.collectNotices(p, pane, v.rects[id], id);
+ const r = v.rects[id];
if (r.w <= config.GUTTER or r.h == 0) continue;
const owner: u8 = @intCast(id);
- const active = id == p.active;
+ const active = id == v.active;
const tag_y = p.tagTop(pane, r);
const body_y = p.bodyTop(pane, r);
s.addRegion(.{ .kind = .grip, .owner = owner, .serial = pane.serial, .active = active, .dirty = tagline.dirty(pane), .rect = .{ .x = r.x, .y = tag_y, .w = config.GUTTER, .h = pane.tag_rows } });
@@ -106,28 +107,28 @@ pub fn place(p: *Pardes, s: *Surface) void {
}
}
const column_rows = layout.columnBarHeight(p);
- if (column_rows > 0) for (0..p.ncol) |c| {
- if (p.col_w[c] == 0) continue;
- const active = if (layout.findPane(p, p.active)) |found| found.col == c else false;
- const inset = @min(TAG_TEXT_INSET, p.col_w[c]);
- s.addRegion(.{ .kind = .column_grip, .owner = @intCast(c), .serial = p.cols[c].serial, .active = active, .rect = .{ .x = p.col_x[c], .y = p.topBarHeight(), .w = @min(config.GUTTER, p.col_w[c]), .h = column_rows } });
- s.addRegion(.{ .kind = .column_tag, .owner = @intCast(c), .serial = p.cols[c].serial, .active = active, .rect = .{ .x = p.col_x[c] + inset, .y = p.topBarHeight(), .w = p.col_w[c] - inset, .h = column_rows } });
+ if (column_rows > 0) for (0..p.view().ncol) |c| {
+ if (v.col_w[c] == 0) continue;
+ const active = if (layout.findPane(p, v.active)) |found| found.col == c else false;
+ const inset = @min(TAG_TEXT_INSET, v.col_w[c]);
+ s.addRegion(.{ .kind = .column_grip, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active, .rect = .{ .x = v.col_x[c], .y = p.topBarHeight(), .w = @min(config.GUTTER, v.col_w[c]), .h = column_rows } });
+ s.addRegion(.{ .kind = .column_tag, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active, .rect = .{ .x = v.col_x[c] + inset, .y = p.topBarHeight(), .w = v.col_w[c] - inset, .h = column_rows } });
};
- const active_col = if (layout.findPane(p, p.active)) |found| found.col else null;
- for (0..p.ncol) |c| {
- if (p.col_w[c] == 0) continue;
- s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = p.cols[c].serial, .active = active_col == c, .rect = .{ .x = p.col_x[c], .y = p.topBarHeight(), .w = p.col_w[c], .h = s.rows -| p.topBarHeight() } });
+ const active_col = if (layout.findPane(p, v.active)) |found| found.col else null;
+ for (0..p.view().ncol) |c| {
+ if (v.col_w[c] == 0) continue;
+ s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active_col == c, .rect = .{ .x = v.col_x[c], .y = p.topBarHeight(), .w = v.col_w[c], .h = s.rows -| p.topBarHeight() } });
}
if (p.settings.workspace_tag)
s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } });
// A column carried to the window's right edge shows where it lands as a
// rail in the last cell: the layers under it stop a cell short.
- if (p.drag == .column_move) rail: {
- const d = p.drag.column_move;
+ if (v.drag == .column_move) rail: {
+ const d = v.drag.column_move;
const source = layout.columnBySerial(p, d.serial) orelse break :rail;
const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) {
.stay => break :rail,
- .reorder => |target| if (target < source) p.col_x[target] else p.col_x[target] + p.col_w[target],
+ .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target],
.edge => |x| x,
};
if (edge != s.cols) break :rail;
@@ -164,20 +165,21 @@ fn inkOn(bg: [3]u8) [3]u8 {
}
pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
+ const v = p.view();
const taped = pardes.tape.enter(p, .render);
defer pardes.tape.leave(p, taped);
panes.terminal.drawing = true;
defer panes.terminal.drawing = false;
panes.File.refreshHighlights(p);
const s = &p.surface;
- const ncells = @as(usize, p.screen_w) * p.screen_h;
+ const ncells = @as(usize, v.screen_w) * v.screen_h;
if (s.cells.len != ncells) {
const cells = try p.gpa.alloc(Cell, ncells);
p.gpa.free(s.cells);
s.cells = cells;
}
- s.cols = p.screen_w;
- s.rows = p.screen_h;
+ s.cols = v.screen_w;
+ s.rows = v.screen_h;
s.cursor = null;
s.pointer_shape = .arrow;
if (comptime pdf_enabled) if (p.pdf_hover_preview) |preview| {
@@ -193,7 +195,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
// the pointer per-text (the macOS I-beam) read this as "target" and
// afford it the arrow instead.
if (p.look_hover_preview != null) s.pointer_shape = .target;
- if (p.drag == .move or p.drag == .column_move) s.pointer_shape = .box;
+ if (v.drag == .move or v.drag == .column_move) s.pointer_shape = .box;
for (&s.body_layers) |*layer| layer.rows = 0;
for (&s.tag_layers) |*layer| layer.rows = 0;
s.placements.clearRetainingCapacity();
@@ -221,12 +223,12 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
// Separators have their own role; a scrollbar need not frame the page.
const whole = s.regions[0].rect;
s.fill(whole.x, whole.y, whole.w, whole.h, .{ .bg = .{ .rgb = chrome.border } });
- for (0..p.ncol) |c| if (p.cols[c].n == 0) s.fill(p.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), p.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } });
+ for (0..p.view().ncol) |c| if (v.cols[c].n == 0) s.fill(v.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), v.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } });
for (&p.panes, 0..) |*slot, id| {
const pane = slot.* orelse continue;
s.body_layers[id].rows = 0;
- try renderPane(p, s, arena, pane, p.rects[id], id, id == p.active);
+ try renderPane(p, s, arena, pane, v.rects[id], id, id == v.active);
}
// Each notice once, as a tag layer, and the grid's chip a copy of it.
for (s.regionList()) |region| {
@@ -235,7 +237,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
try paintHeaders(p, s);
- switch (p.drag) {
+ switch (v.drag) {
.border_v => |d| {
if (d.cur_x < s.cols) {
var row: u16 = p.topBarHeight();
@@ -243,19 +245,19 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = p.topBarHeight(), .w = 1, .h = s.rows -| p.topBarHeight() } });
}
if (d.corner) |k| if (d.cur_y < s.rows) {
- const first = if (k.col == d.left_col) p.col_x[k.col] else d.cur_x +| 1;
- const end = if (k.col == d.left_col) d.cur_x else p.col_x[k.col] +| p.col_w[k.col] -| 1;
+ const first = if (k.col == d.left_col) v.col_x[k.col] else d.cur_x +| 1;
+ const end = if (k.col == d.left_col) d.cur_x else v.col_x[k.col] +| v.col_w[k.col] -| 1;
var col = first;
while (col <= end and col < s.cols) : (col += 1) s.overlayDash(col, d.cur_y, "╌");
if (col > first) s.addRegion(.{ .kind = .guide, .rect = .{ .x = first, .y = d.cur_y, .w = col - first, .h = 1 } });
};
},
// A column that went away mid-drag has nothing to guide.
- .border_h => |d| if (d.cur_y < s.rows and d.col < p.ncol and p.col_x[d.col] < s.cols) {
- const end = @min(s.cols, p.col_x[d.col] + p.col_w[d.col]);
- var col = p.col_x[d.col];
+ .border_h => |d| if (d.cur_y < s.rows and d.col < v.ncol and v.col_x[d.col] < s.cols) {
+ const end = @min(s.cols, v.col_x[d.col] + v.col_w[d.col]);
+ var col = v.col_x[d.col];
while (col < end) : (col += 1) s.overlayDash(col, d.cur_y, "╌");
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = p.col_x[d.col], .y = d.cur_y, .w = end - p.col_x[d.col], .h = 1 } });
+ s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[d.col], .y = d.cur_y, .w = end - v.col_x[d.col], .h = 1 } });
},
.column_move => |d| rail: {
const source = layout.columnBySerial(p, d.serial) orelse break :rail;
@@ -263,7 +265,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
// Where the column's left edge would land, reordered or not.
const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) {
.stay => break :rail,
- .reorder => |target| if (target < source) p.col_x[target] else p.col_x[target] + p.col_w[target],
+ .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target],
.edge => |x| x,
};
// The layers under an outside rail stop a cell short of it:
@@ -292,13 +294,13 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
if (row > run) s.addRegion(.{ .kind = .guide, .rect = .{ .x = x, .y = run, .w = 1, .h = row - run } });
},
.move => |d| if (d.cur_x < s.cols) {
- if (layout.movePlacement(p, d.id, d.cur_x, d.cur_y)) |placement| if (placement.row < s.rows and p.col_x[placement.preview_col] + p.col_w[placement.preview_col] <= s.cols) {
- var col: u16 = p.col_x[placement.preview_col];
- while (col < p.col_x[placement.preview_col] + p.col_w[placement.preview_col]) : (col += 1) {
+ if (layout.movePlacement(p, d.id, d.cur_x, d.cur_y)) |placement| if (placement.row < s.rows and v.col_x[placement.preview_col] + v.col_w[placement.preview_col] <= s.cols) {
+ var col: u16 = v.col_x[placement.preview_col];
+ while (col < v.col_x[placement.preview_col] + v.col_w[placement.preview_col]) : (col += 1) {
s.set(col, placement.row, "╌", .{ .fg = .{ .rgb = chrome.lineno } });
}
s.set(d.cur_x, placement.row, "▌", .{ .fg = .{ .rgb = chrome.lineno } });
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = p.col_x[placement.preview_col], .y = placement.row, .w = p.col_w[placement.preview_col], .h = 1 } });
+ s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[placement.preview_col], .y = placement.row, .w = v.col_w[placement.preview_col], .h = 1 } });
s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = placement.row, .w = 1, .h = 1 } });
};
},
@@ -307,7 +309,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
}
// debug overlay: a small stats box drawn last, top-right ("Debug")
- if (p.settings.debug) if (p.panes[p.active]) |at| {
+ if (p.settings.debug) if (p.panes[v.active]) |at| {
var nlive: usize = 0;
for (p.panes) |slot| {
if (slot != null) nlive += 1;
@@ -336,7 +338,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
const text = std.fmt.bufPrint(
&ov_buf,
"pardes resizes={d}\ntheme {s}\nfont {s}\nterms {d} cols {d}\nactive #{d} {d}x{d}\nscroll {d}/{d}\n{s}",
- .{ p.resize_count, p.theme().name, font_name[0..@min(font_name.len, 64)], nlive, p.ncol, p.active, at.cols, at.rows, sb_off, sb_total, timings },
+ .{ p.resize_count, p.theme().name, font_name[0..@min(font_name.len, 64)], nlive, v.ncol, v.active, at.cols, at.rows, sb_off, sb_total, timings },
) catch "";
// wide enough for the longest theme name compiled in, which is the
// only row here whose width is not ours to choose
@@ -419,7 +421,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
.font_role = .tagline,
});
// In window mode the box holds the pane's letter instead of its mode.
- const label: ?u8 = if (p.window_pick != null) layout.windowLabel(p, id) else null;
+ const label: ?u8 = if (p.view().window_pick != null) layout.windowLabel(p, id) else null;
s.set(r.x, tag_y, if (label) |*letter| @as(*const [1]u8, letter) else switch (pane.body.mode) {
.normal => config.tag_normal,
.insert => config.tag_insert,
@@ -467,11 +469,12 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
/// The workspace and column tags: each line a tag layer, and the grid's
/// rows copies of those; the column grips, which are the grid's alone.
fn paintHeaders(p: *Pardes, s: *Surface) !void {
+ const v = p.view();
const chrome = p.chromeTheme();
// global tagbar: full width, top rows — unless a native shell has
// taken its commands over, in which case the rows are not ours to draw
if (s.region(.workspace_tag, Region.none)) |region| {
- const top = if (p.header != null and p.headerColumn() == null) p.header_top else 0;
+ const top = if (v.header != null and p.headerColumn() == null) v.header_top else 0;
const layer = &s.tag_layers[MAX_PANES + MAX_COLS];
var viewport = region.rect;
const inset = @min(TAG_TEXT_INSET, viewport.w);
@@ -482,28 +485,28 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void {
joinHeaderRows(s, layer, chrome.tag_fg);
}
const column_rows = layout.columnBarHeight(p);
- if (column_rows > 0) for (0..p.ncol) |c| {
+ if (column_rows > 0) for (0..p.view().ncol) |c| {
const region = s.region(.column_tag, c) orelse continue;
- const active = if (layout.findPane(p, p.active)) |found| found.col == c else false;
+ const active = if (layout.findPane(p, v.active)) |found| found.col == c else false;
const bg = if (active) chrome.tag_active_bg else chrome.tag_bg;
const fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
- if (p.col_x[c] < s.cols) {
+ if (v.col_x[c] < s.cols) {
// A grip is muted until it is grabbed; then it lights, as a
// pane's box does for the active pane, so the drag shows what it
// holds.
- const grip = @min(config.GUTTER, p.col_w[c]);
- const inset = @min(TAG_TEXT_INSET, p.col_w[c]);
- const grabbed = p.drag == .column_move and layout.columnBySerial(p, p.drag.column_move.serial) == c;
+ const grip = @min(config.GUTTER, v.col_w[c]);
+ const inset = @min(TAG_TEXT_INSET, v.col_w[c]);
+ const grabbed = v.drag == .column_move and layout.columnBySerial(p, v.drag.column_move.serial) == c;
const grip_bg = if (grabbed) chrome.column_box else chrome.column_box_dim;
const ink = inkOn(grip_bg);
- s.fill(p.col_x[c], region.rect.y, grip, @min(1, column_rows), .{ .bg = .{ .rgb = grip_bg }, .fg = .{ .rgb = ink }, .font_role = .tagline });
- s.fill(p.col_x[c], region.rect.y + 1, grip, column_rows -| 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
- s.fill(p.col_x[c] + grip, region.rect.y, inset - grip, column_rows, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
+ s.fill(v.col_x[c], region.rect.y, grip, @min(1, column_rows), .{ .bg = .{ .rgb = grip_bg }, .fg = .{ .rgb = ink }, .font_role = .tagline });
+ s.fill(v.col_x[c], region.rect.y + 1, grip, column_rows -| 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
+ s.fill(v.col_x[c] + grip, region.rect.y, inset - grip, column_rows, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
}
- const top = if (p.header != null and p.headerColumn() == c) p.header_top else 0;
+ const top = if (v.header != null and p.headerColumn() == c) v.header_top else 0;
const layer = &s.tag_layers[MAX_PANES + c];
try renderHeaderLayer(p, layer, .column, @intCast(c), region.rect, tagline.columnTag(p, c), top, bg, fg);
- if (p.col_x[c] < s.cols) joinHeaderRows(s, layer, fg);
+ if (v.col_x[c] < s.cols) joinHeaderRows(s, layer, fg);
// Laid out at its full width; only shown short of the rail.
layer.viewport.w -|= region.clip;
};
@@ -575,6 +578,7 @@ fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct {
/// of `text` and on, laid out at the tagline's pitch -- as wide as its
/// widest line and never narrower than its viewport.
fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, viewport: Rect, text: []const u8, top: usize, bg: [3]u8, fg: [3]u8) !void {
+ const v = p.view();
if (viewport.w == 0 or viewport.h == 0) {
// No layer, and nothing of an earlier frame's left in it.
layer.rows = 0;
@@ -589,7 +593,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count);
layer.kind = kind;
layer.id = id;
- layer.serial = if (kind == .column) p.cols[id].serial else 0;
+ layer.serial = if (kind == .column) v.cols[id].serial else 0;
layer.viewport = viewport;
layer.cols = columns;
layer.rows = viewport.h;
@@ -599,12 +603,12 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
// A notice band carries a PANE id, not a column index, so it must not
// answer to the column being edited -- that would scroll and select
// its text with the column tag's offsets and give it a second caret.
- const editing: ?*Text = if (p.header != null and switch (kind) {
+ const editing: ?*Text = if (v.header != null and switch (kind) {
.workspace => p.headerColumn() == null,
.column => p.headerColumn() == id,
.pane, .notice, .body => false,
}) tagline.focusedHeader(p) else null;
- const scroll = if (editing != null) p.header_scroll else 0;
+ const scroll = if (editing != null) v.header_scroll else 0;
for (0..viewport.h) |index| {
const line: u16 = @intCast(index);
const shown = modal.lineSlice(text, index + top);
@@ -617,13 +621,13 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
// (joined from this); not on a column a carried column's pointer is
// aiming at a place over; nor under a held middle or right sweep,
// which paints what it sweeps instead.
- const hovered = p.pointer_inside and !(kind == .column and p.drag == .column_move) and p.header_sweep == null;
+ const hovered = v.pointer_inside and !(kind == .column and v.drag == .column_move) and v.header_sweep == null;
if (hovered) {
- const tag_hit = p.pointer_tag_hit;
+ const tag_hit = v.pointer_tag_hit;
const col: ?usize = if (tag_hit) |pointer|
(if (pointer.kind == kind and pointer.id == id and pointer.line == line) pointer.col else null)
- else if (p.hover_row == viewport.y + line and p.hover_col >= viewport.x and p.hover_col - viewport.x < viewport.w)
- p.hover_col - viewport.x
+ else if (v.hover_row == viewport.y + line and v.hover_col >= viewport.x and v.hover_col - viewport.x < viewport.w)
+ v.hover_col - viewport.x
else
null;
if (col) |hover| if (wordBoundsAtCol(shown, panes.File.rawAtDisplay(shown, hover + scroll))) |bounds| {
@@ -636,7 +640,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
};
}
if (editing) |t| {
- if (tagline.headerSelection(t, try edit.flatSurface(p, t), line + p.header_top)) |span| {
+ if (tagline.headerSelection(t, try edit.flatSurface(p, t), line + v.header_top)) |span| {
var col = panes.File.rawDisplayCol(shown, span.lo) -| scroll;
const end = panes.File.rawDisplayCol(shown, span.hi) -| scroll;
while (col < end and col < columns) : (col += 1) {
@@ -645,12 +649,12 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
}
}
const caret = panes.File.rawDisplayCol(shown, @min(@as(usize, @intCast(@max(0, t.cur_col))), shown.len)) -| scroll;
- const asking = if (p.panes[p.active]) |active| active.prompt != .none else false;
- if (!asking and t.cur_row == line + p.header_top and caret < columns) layer.cursor = .{ .x = @intCast(caret), .y = line, .bar = t.mode == .insert };
+ 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 };
}
// A middle or right sweep held over this header, tinted by its
// button as a pane tag's is.
- if (p.header_sweep) |sweep| if (sweep.column(p)) |column| {
+ if (v.header_sweep) |sweep| if (sweep.column(p)) |column| {
const mine = switch (kind) {
.workspace => column == null,
.column => column == id,
@@ -675,6 +679,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v
/// A pane's tag rows, painted once into their layer, a row to a line, and
/// copied into the grid; the grid's caret where the layer has it.
fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void {
+ const v = p.view();
const capacity = layout.tagCapacity(p, r.w -| TAG_TEXT_INSET);
// Too narrow for a layer: only the grid's gap cell.
if (r.w <= TAG_TEXT_INSET) return paintPaneTag(p, s, arena, pane, r, id, active);
@@ -696,7 +701,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
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.
- if (p.window_pick == id) {
+ if (v.window_pick == id) {
for (0..rows) |row| temporary.tint(0, @intCast(row), temporary.cols, p.theme().sel_bg, p.theme().sel_fg);
}
const tag_fg: Color = .{ .rgb = if (active) chrome.tag_active_fg else chrome.tag_fg };
@@ -711,8 +716,8 @@ 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 (p.window_pick == id) p.theme().sel_bg else if (active) chrome.tag_active_bg else chrome.tag_bg;
- layer.cursor = if (p.header != null) null else if (temporary.cursor) |cursor|
+ layer.bg = if (v.window_pick == id) p.theme().sel_bg else if (active) chrome.tag_active_bg else chrome.tag_bg;
+ 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
null;
@@ -731,12 +736,13 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
/// A notice chip, painted once as a tag layer at the tagline's pitch, and the
/// grid's chip a copy of its right end, where its text is.
fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region) !void {
+ const v = p.view();
const chrome = p.chromeTheme();
const id: usize = region.owner;
const pane = p.panes[id].?;
const i: usize = region.notice;
const kind = pane.notices.kinds[i];
- const r = p.rects[id];
+ const r = v.rects[id];
const chip = region.rect.w;
var leader_buf: [16]u8 = undefined;
const text = Messages.noticeText(p, pane, i, &leader_buf);
@@ -749,7 +755,7 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
s.fill(region.rect.x, region.rect.y, chip, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
if (text.len == 0) return;
const printed = Messages.printRight(s, region.rect.x, region.rect.y, chip -| 1, text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
- if (kind != .prompt or id != p.active or pane.prompt == .del_side or pane.prompt == .repl_choice) return;
+ 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)]);
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 };
@@ -776,7 +782,7 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
const layer = &s.tag_layers[NOTICE_LAYER_BASE + id * Pane.Notices.max + i];
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 == p.active and pane.prompt != .del_side and pane.prompt != .repl_choice) caret: {
+ 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);
if (typed < dropped) break :caret;
@@ -934,10 +940,10 @@ test "an unfocused grip shows on its tag in the grid, in every native theme" {
defer arena.deinit();
for (pardes.themes[0..colors.native_count], 0..) |theme, index| {
colors.setThemeIndex(p, index);
- p.active = 1;
+ p.view().active = 1;
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
- const r = p.rects[0];
+ 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);
// ponytail: dark and helix have always had a faint grip (1.2:1); flagged, not changed here.
@@ -959,12 +965,12 @@ test "a grip's four states, focused or not and clean or dirty, are each its own
colors.setThemeIndex(p, index);
var states: [4]State = undefined;
for (&states, 0..) |*state, i| {
- p.active = if (i & 1 == 0) 0 else 1;
+ p.view().active = if (i & 1 == 0) 0 else 1;
const saved = pane.file.?.saved_revision;
pane.file.?.revision = if (i & 2 != 0) saved + 1 else saved;
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
- const r = p.rects[0];
+ const r = p.view().rects[0];
const y = p.tagTop(pane, r);
state.* = .{ .first = s.at(r.x, y).*, .second = s.at(r.x + 1, y).*, .dirty = s.region(.grip, 0).?.dirty };
try std.testing.expectEqual(i & 2 != 0, state.dirty);
@@ -988,7 +994,7 @@ test "every theme draws a file's name, a +Errors and a Term word in a tint, neve
defer p.deinit();
_ = try p.setTestFile("text\n");
try std.testing.expect(p.executeBuiltinLine(0, "Term+sh"));
- const terminal = p.active;
+ const terminal = p.view().active;
p.acknowledgeShell(terminal, "/bin/sh", false);
try @import("Output.zig").openErrors(p, 0, try gpa.dupe(u8, "oops\n"));
while (p.nextEffect()) |_| {}
@@ -1004,11 +1010,11 @@ test "every theme draws a file's name, a +Errors and a Term word in a tint, neve
colors.setThemeIndex(p, index);
// Each pane focused in turn: every word on both grounds.
for (probes) |focused| {
- p.active = focused.id;
+ p.view().active = focused.id;
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
for (probes) |probe| {
- const r = p.rects[probe.id];
+ const r = p.view().rects[probe.id];
const y = p.tagTop(p.panes[probe.id].?, r);
// The row's text, and the column each byte of it is drawn at.
var row: [512]u8 = undefined;
@@ -1045,7 +1051,7 @@ test "a tag of three rows has its grip on the first, and band under it that stil
p.sync();
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
- const r = p.rects[0];
+ const r = p.view().rects[0];
const top = p.tagTop(pane, r);
try std.testing.expect(pane.tag_rows >= 3);
const chrome = p.chromeTheme();
@@ -1073,11 +1079,11 @@ test "place puts every part where the painters and layers put it, in every layou
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
for (0..16) |step| {
- if (step & 4 != 0) try std.testing.expect(p.executeBuiltinLine(p.active, "Msg a placed notice"));
+ if (step & 4 != 0) try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg a placed notice"));
if (step == 8) try std.testing.expect(p.executeBuiltinLine(1, "Collapse"));
if (step == 12) try std.testing.expect(p.executeBuiltinLine(1, "Collapse"));
if (step == 10) {
- const pane = p.panes[p.active].?;
+ const pane = p.panes[p.view().active].?;
pane.tag.own = try std.testing.allocator.dupe(u8, "Second\nthird");
}
p.sync();
@@ -1086,7 +1092,7 @@ test "place puts every part where the painters and layers put it, in every layou
try std.testing.expectEqual(Region.Kind.page, s.regions[0].kind);
for (p.panes, 0..) |slot, id| {
const pane = slot orelse continue;
- const r = p.rects[id];
+ const r = p.view().rects[id];
if (r.w <= config.GUTTER or r.h == 0) continue;
const grip = s.region(.grip, id).?;
try std.testing.expectEqual(Rect{ .x = r.x, .y = p.tagTop(pane, r), .w = config.GUTTER, .h = pane.tag_rows }, grip.rect);
@@ -1125,13 +1131,13 @@ test "place puts every part where the painters and layers put it, in every layou
}
try std.testing.expectEqual(@as(usize, pane.notices.len), notices);
}
- for (0..p.ncol) |c| {
+ for (0..p.view().ncol) |c| {
const region = s.region(.column_tag, c);
if (layout.columnBarHeight(p) == 0) {
try std.testing.expect(region == null);
continue;
}
- try std.testing.expectEqual(Rect{ .x = p.col_x[c] + TAG_TEXT_INSET, .y = p.topBarHeight(), .w = p.col_w[c] - TAG_TEXT_INSET, .h = layout.columnBarHeight(p) }, region.?.rect);
+ try std.testing.expectEqual(Rect{ .x = p.view().col_x[c] + TAG_TEXT_INSET, .y = p.topBarHeight(), .w = p.view().col_w[c] - TAG_TEXT_INSET, .h = layout.columnBarHeight(p) }, region.?.rect);
}
}
}
@@ -1142,7 +1148,7 @@ test "the word under the pointer on a notice is lit in its layer and in the grid
_ = try p.setTestFile("text\n");
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg Look here"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg Look here"));
p.sync();
var s = try p.render(arena.allocator());
const notice = for (s.regionList()) |region| {
@@ -1152,9 +1158,9 @@ test "the word under the pointer on a notice is lit in its layer and in the grid
// "here", the chip's last word, before its blank edge.
const here = notice.rect.x + notice.rect.w - 5;
try std.testing.expectEqualStrings("h", row[here].grapheme());
- p.pointer_inside = true;
- p.hover_col = here + 1;
- p.hover_row = notice.rect.y;
+ p.view().pointer_inside = true;
+ p.view().hover_col = here + 1;
+ p.view().hover_row = notice.rect.y;
_ = arena.reset(.retain_capacity);
s = try p.render(arena.allocator());
const lit = s.cells[@as(usize, notice.rect.y) * s.cols ..][0..s.cols];
@@ -1182,7 +1188,7 @@ test "a notice wider than its band, as a shader's compile error is, draws its en
const long = std.mem.asBytes(&@as([3][126]u8, @splat("Shader /home/someone/shaders/test_shadertoy_invalid.glsl: error: Linking fragment stage: No function definition (body) found: ".*)));
for ([_][]const u8{ "Msg " ++ long, "" }) |line| {
// The Msg builtin, and the path a failed compile takes (Post.zig).
- if (line.len > 0) try std.testing.expect(p.executeBuiltinLine(p.active, line)) else p.setMessage(p.active, long);
+ if (line.len > 0) try std.testing.expect(p.executeBuiltinLine(p.view().active, line)) else p.setMessage(p.view().active, long);
p.sync();
for (0..30) |_| p.update(.tick);
_ = arena.reset(.retain_capacity);
@@ -1230,12 +1236,12 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev
1, 2 => {
text.clearRetainingCapacity();
for (0..random.uintAtMost(usize, 60)) |_| try text.appendSlice(std.testing.allocator, words[random.uintLessThan(usize, words.len)]);
- if (random.boolean()) p.setMessage(p.active, text.items) else {
+ if (random.boolean()) p.setMessage(p.view().active, text.items) else {
const line = try std.fmt.allocPrint(arena.allocator(), "Msg {s}", .{text.items});
- _ = p.executeBuiltinLine(p.active, line);
+ _ = p.executeBuiltinLine(p.view().active, line);
}
},
- 3 => _ = p.executeBuiltinLine(p.active, commands[random.uintLessThan(usize, commands.len)]),
+ 3 => _ = p.executeBuiltinLine(p.view().active, commands[random.uintLessThan(usize, commands.len)]),
// Typing, escaping and entering, into a prompt when one is up.
4 => p.update(.{ .key = .{ .cp = switch (random.uintLessThan(u8, 9)) {
0 => pardes.Key.escape,
@@ -1248,7 +1254,7 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev
else => 'a' + random.uintLessThan(u21, 26),
} } }),
// A tag of several rows.
- 5 => if (p.panes[p.active]) |pane| {
+ 5 => if (p.panes[p.view().active]) |pane| {
text.clearRetainingCapacity();
for (0..random.uintAtMost(usize, 5)) |_| try text.appendSlice(std.testing.allocator, if (random.boolean()) " Look\nmore \u{754c}" else "\n" ++ &@as([150]u8, @splat('x')));
if (pane.tag.own) |own| std.testing.allocator.free(own);
@@ -1256,8 +1262,8 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev
},
// Hover, and clicks: into a tag, a header, a body, a grip.
6 => {
- const col = random.uintAtMost(u16, p.screen_w);
- const row = random.uintAtMost(u16, p.screen_h);
+ const col = random.uintAtMost(u16, p.view().screen_w);
+ const row = random.uintAtMost(u16, p.view().screen_h);
if (random.boolean()) p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = col, .row = row } }) else {
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = row } });
@@ -1278,13 +1284,13 @@ test "a wide glyph cut by a tag's or a notice's edge is joined into the grid as
_ = try p.setTestFile("wide\n");
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
- const pane = p.panes[p.active].?;
+ const pane = p.panes[p.view().active].?;
// Both alignments, so one of them puts a wide glyph across each edge.
for ([_][]const u8{ std.mem.asBytes(&@as([30][3]u8, @splat("\u{754c}".*))), "x" ++ std.mem.asBytes(&@as([30][3]u8, @splat("\u{754c}".*))) }) |wide| {
if (pane.tag.own) |own| std.testing.allocator.free(own);
pane.tag.own = try std.testing.allocator.dupe(u8, wide);
var message: [200]u8 = undefined;
- try std.testing.expect(p.executeBuiltinLine(p.active, try std.fmt.bufPrint(&message, "Msg {s}", .{wide})));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, try std.fmt.bufPrint(&message, "Msg {s}", .{wide})));
p.sync();
_ = arena.reset(.retain_capacity);
const s = try p.render(arena.allocator());
@@ -1332,7 +1338,7 @@ test "a body with context rows is painted once, and the grid's rows are what a p
@memset(cells, .{});
var plain: Surface = .{ .cols = s.cols, .rows = s.rows, .cells = cells };
pane.view.layered = false;
- try body_layer.renderBody(p, &plain, arena.allocator(), pane, p.rects[0], 0, true, null);
+ try body_layer.renderBody(p, &plain, arena.allocator(), pane, p.view().rects[0], 0, true, null);
pane.view.layered = true;
for (0..body.rect.h) |row| {
const y = body.rect.y + row;