diff options
Diffstat (limited to 'core/draw.zig')
| -rw-r--r-- | core/draw.zig | 94 |
1 files changed, 66 insertions, 28 deletions
diff --git a/core/draw.zig b/core/draw.zig index c3c80934..a7513468 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -160,10 +160,12 @@ pub fn place(p: *Pardes, s: *Surface) void { 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() } }); + 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() + layout.noticeRowHeight(p)) } }); } if (p.settings.workspace_tag) s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } }); + const foot = layout.noticeRowHeight(p); + if (foot > 0) s.addRegion(.{ .kind = .notice_row, .rect = .{ .x = 0, .y = s.rows - foot, .w = s.cols, .h = foot } }); } /// A pane's grip in the grid: `box` focused, else halfway between its ring @@ -346,7 +348,7 @@ 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.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 (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) + layout.noticeRowHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } }); for (&p.panes, 0..) |*slot, id| { const pane = slot.* orelse continue; @@ -359,6 +361,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { } try paintHeaders(p, s); + try paintNoticeRow(p, s); // debug overlay: a small stats box drawn last, top-right ("Debug") if (p.settings.debug) if (p.panes[v.active]) |at| { @@ -572,6 +575,43 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void { }; } +/// The notice row (Messages.noticeRow), the live messages' index at the +/// window's foot: a header layer at the tagline's pitch in the workspace +/// tag's colours, the glyph in its kind's, a message gone dim and the +/// counts at the right end dimmed. +fn paintNoticeRow(p: *Pardes, s: *Surface) !void { + const region = s.region(.notice_row, Region.none) orelse return; + const chrome = p.chromeTheme(); + var viewport = region.rect; + const inset = @min(TAG_TEXT_INSET, viewport.w); + s.fill(viewport.x, viewport.y, inset, viewport.h, .{ .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline }); + viewport.x += inset; + viewport.w -= inset; + var buf: [Messages.notice_row_cap]u8 = undefined; + const row = Messages.noticeRow(p, layout.tagCapacity(p, viewport.w) -| 1, &buf); + 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) }; + 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])); + if (p.messages.headline()) |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 }; + }; + if (lead.faded(p.clock.now_ns, p.settings.message_linger_ms)) for (cells[0..left]) |*cell| { + if (std.meta.eql(cell.style.fg, ink)) cell.style.fg = dim; + }; + } + for (cells[right..]) |*cell| if (std.meta.eql(cell.style.fg, ink)) { + cell.style.fg = dim; + }; + joinHeaderRows(s, layer, chrome.tagline_fg); +} + /// Copy a header's layer into the grid under it, row by row, and its caret. fn joinHeaderRows(s: *Surface, layer: *const pardes.Layer, fg: [3]u8) void { const v = layer.viewport; @@ -664,7 +704,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, .notice_row => false, }) tagline.focusedHeader(p) else null; const scroll = if (editing != null) v.header_scroll else 0; for (0..viewport.h) |index| { @@ -716,7 +756,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, .notice_row => false, }; const swept = sweep.span(text.len); const start = modal.lineStartOffset(text, index + top); @@ -1131,8 +1171,8 @@ test "place puts every part where the painters and layers put it, in every layou } } -test "the word under the pointer on a notice is lit in its layer and in the grid's copy" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 41, .rows = 12 }); +test "the word under the pointer on the notice row is lit in its layer and in the grid's copy" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 61, .rows = 12 }); defer p.deinit(); _ = try p.setTestFile("text\n"); var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); @@ -1140,36 +1180,35 @@ test "the word under the pointer on a notice is lit in its layer and in the grid 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| { - if (region.kind == .notice) break region; - } else return error.TestExpectedNotice; - const row = s.cells[@as(usize, notice.rect.y) * s.cols ..][0..s.cols]; - // "here", the chip's last word, before its blank edge. - const here = notice.rect.x + notice.rect.w - 5; + const foot = s.region(.notice_row, Region.none) orelse return error.TestExpectedNoticeRow; + try std.testing.expectEqual(s.rows - 1, foot.rect.y); + const row = s.cells[@as(usize, foot.rect.y) * s.cols ..][0..s.cols]; + // "here": the message's last word, `ยท /test.txt Look here`, 17 + // columns in. + const here: u16 = TAG_TEXT_INSET + 17; try std.testing.expectEqualStrings("h", row[here].grapheme()); p.view().pointer_inside = true; p.view().hover_col = here + 1; - p.view().hover_row = notice.rect.y; + p.view().hover_row = foot.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]; - const sel: Color = .{ .rgb = p.theme().sel_bg }; + const lit = s.cells[@as(usize, foot.rect.y) * s.cols ..][0..s.cols]; + const sel: Color = .{ .rgb = p.theme().tag_sel_bg orelse p.theme().sel_bg }; for (lit[here..][0..4]) |cell| try std.testing.expectEqual(sel, cell.style.bg); try std.testing.expect(!std.meta.eql(sel, lit[here - 2].style.bg)); - const layer = for (s.tagLayers()) |*layer| { - if (layer.rows != 0 and layer.kind == .notice) break layer; - } else return error.TestExpectedNotice; + const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER]; + try std.testing.expectEqual(TagKind.notice_row, layer.kind); const lit_in_layer = for (layer.cells) |cell| { if (std.meta.eql(sel, cell.style.bg)) break true; } else false; try std.testing.expect(lit_in_layer); } -test "a notice wider than its band, as a shader's compile error is, draws its end and nothing past it" { +test "a message wider than the notice row, as a shader's compile error is, gives way to the row's right end and draws nothing past the row" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 }); defer p.deinit(); - // A gui-shaped core: its tagline is narrower than the body, so a notice's - // band holds more columns than its chip has cells. + // A gui-shaped core: its tagline is narrower than the body, so the + // row's layer holds more columns than the grid has cells. p.update(.{ .resize = .{ .cols = 80, .rows = 20, .row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 } } }); _ = try p.setTestFile("text\n"); var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); @@ -1182,13 +1221,12 @@ test "a notice wider than its band, as a shader's compile error is, draws its en for (0..30) |_| p.update(.tick); _ = arena.reset(.retain_capacity); const s = try p.render(arena.allocator()); - const notice = for (s.regionList()) |region| { - if (region.kind == .notice) break region; - } else return error.TestExpectedNotice; - // Text up to the chip's blank last cell, and no padding ink. - const row = s.cells[@as(usize, notice.rect.y) * s.cols ..][notice.rect.x..][0..notice.rect.w]; - try std.testing.expectEqualStrings(" ", row[row.len - 1].grapheme()); - try std.testing.expect(!std.mem.eql(u8, " ", row[row.len - 2].grapheme())); + const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER]; + try std.testing.expectEqual(layout.tagCapacity(p, s.cols - TAG_TEXT_INSET), layer.cols); + // The counts at the row's end, whole, a blank cell short of it. + const cells = layer.cells[0..layer.cols]; + try std.testing.expectEqualStrings(" ", cells[cells.len - 1].grapheme()); + try std.testing.expectEqualStrings("m", cells[cells.len - 2].grapheme()); } } |
