summaryrefslogtreecommitdiff
path: root/dev/gui
diff options
context:
space:
mode:
Diffstat (limited to 'dev/gui')
-rw-r--r--dev/gui/gui.zig79
1 files changed, 73 insertions, 6 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 7d8259e0..66074f42 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -4319,6 +4319,18 @@ fn scrollColumn(g: *const Gui, chrome: *const pardes.Chrome, col: u16, layout: C
return .{ x0, x0 + w };
}
+/// Whether a pane's box, at `edge` of its row, shows a mark and no mode:
+/// draw.zig renderPane writes the mode in the box's first cell (blank in
+/// normal mode) and a live message's mark (Messages.markOf: `✗ ! ? ⋯`) in
+/// its second, which the cell shells show beside it; a button holds one
+/// glyph, the mode's bars are decor, so the mark takes their place.
+fn boxMark(line: []const pardes.Cell, edge: usize) bool {
+ if (edge + 1 >= line.len or line[edge].printableAscii() != ' ') return false;
+ const second = &line[edge + 1];
+ // A dirty box's `*` is the cell shells' form of the button's fill.
+ return !second.default and second.printableAscii() != ' ' and second.printableAscii() != '*';
+}
+
/// acme's button for the grip whose first cell is (col, row), in window
/// pixels: the scroll column wide, its tag row tall, from the rule above to
/// the rule below, so button and scrollbar read as one strip.
@@ -4420,8 +4432,11 @@ fn emitSurfaceCell(
else
emitInstance(g, instances, next.*, col, row, body_layout, win_w, win_h, .tagline, line, at, cursor, is_cursor, page);
// A grip's glyph is the cell at its left edge, and a blank one is
- // no glyph: its marks are decor.
- const glyph = &line[at - @min(here.grip_offset, at)];
+ // no glyph: its marks are decor. A pane's button holds one glyph:
+ // its mode's, else its mark (boxMark).
+ const edge = at - @min(here.grip_offset, at);
+ const mark = here.pane_grip and here.grip_top and boxMark(line, edge);
+ const glyph = &line[if (mark) edge + 1 else edge];
const grip = here.grip and here.grip_top and !glyph.default and glyph.printableAscii() != ' ' and !glyph.style.invisible;
const offset: u16 = if (grip) @min(here.grip_offset, at) else 0;
// An anchor starts at its column's rule: its left edge is inset by
@@ -4442,7 +4457,14 @@ fn emitSurfaceCell(
const center = (b[0] + b[2]) / 2 - @as(f32, @floatFromInt(col - offset)) * body_layout.w;
const shift: f32 = if (cached != null) @as(f32, @floatFromInt(@as(u32, offset) * g.cell_w)) + @as(f32, @floatFromInt(config.GUTTER * g.cell_w)) / 2 - center else 0;
const resolved = resolveCell(g, glyph[0..1], 0, null, .tagline, false, page);
- const ink = if (here.pane_grip) inkOn(gripFill(chrome, here.focus, here.dirty, here.reading)) else resolved.fg;
+ const fill = gripFill(chrome, here.focus, here.dirty, here.reading);
+ // A mark in its kind's ink (Messages.ink), held to its floor on
+ // the button's fill, which is not a tag's ground when focused
+ // or dirty (UX D4).
+ const ink = if (mark) switch (glyph.style.fg) {
+ .rgb => |rgb| pardes.colors.pushAway(rgb, &.{fill}, pardes.colors.Roles.ink_floor),
+ else => inkOn(fill),
+ } else if (here.pane_grip) inkOn(fill) else resolved.fg;
instances[next.*].fr = @as(f32, @floatFromInt(ink[0])) / 255;
instances[next.*].fg = @as(f32, @floatFromInt(ink[1])) / 255;
instances[next.*].fb = @as(f32, @floatFromInt(ink[2])) / 255;
@@ -5392,13 +5414,13 @@ fn gripDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ce
}
}
// The marks are the first row's alone, where its cell is blank (no
- // mode glyph), centered in the button, in its ink from the region's
- // state.
+ // mode glyph) and no message's mark takes the button (boxMark),
+ // centered in the button, in its ink from the region's state.
const x = grip.rect.x;
const y = grip.rect.y;
if (x >= cols) continue;
const cell = &cells[@as(usize, y) * cols + x];
- if (cell.default or cell.printableAscii() != ' ') continue;
+ if (cell.default or cell.printableAscii() != ' ' or boxMark(cells[@as(usize, y) * cols ..][0..cols], x)) continue;
const rgb = inkOn(gripFill(chrome, grip.active, grip.dirty, grip.reading));
const center_x = @floor((button[0] + button[2]) / 2);
const center_y = @as(f32, @floatFromInt(y)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(y, win_h, g.cell_h, g.tagline_height))) + @as(f32, @floatFromInt(g.tagline_height)) / 2;
@@ -8355,3 +8377,48 @@ test "a band over a terminal's body has the tag rule under its last row, as a ba
}
try std.testing.expect(found);
}
+
+test "a pane's mark is its button's glyph where the mode draws none, in its kind's ink held to 4.5:1 on the button's fill, and the mode's bars give way to it (S2 09a: the window drew the box, then the path)" {
+ const gpa = std.testing.allocator;
+ var cells: [12]pardes.Cell = @splat(.{ .default = false, .style = .{ .font_role = .tagline } });
+ // draw.zig renderPane's box: the mode blank (normal), the mark beside it.
+ const err: [3]u8 = .{ 0xff, 0x7e, 0xa2 };
+ cells[1] = .{ .default = false, .style = .{ .fg = .{ .rgb = err }, .bold = true, .font_role = .tagline } };
+ @memcpy(cells[1].text[0..3], "\u{2717}");
+ cells[1].len = 3;
+ const grip = [_]pardes.Region{.{ .kind = .grip, .serial = 1, .active = true, .rect = .{ .x = 0, .y = 0, .w = 2, .h = 1 } }};
+ var cover: [12]Cover = undefined;
+ coverFrame(&cover, 6, 2, &.{}, &.{}, &grip);
+ const chrome: pardes.Chrome = .{};
+ var g = testGui(10, 20, 8, 16);
+ g.atlas = try Atlas.init(gpa, font_ttf);
+ defer g.atlas.deinit(gpa);
+ g.px = 20;
+ g.tagline_px = 16;
+ defer g.words.deinit(gpa);
+ defer g.decor.deinit(gpa);
+ var instances: [4]CellInstance = undefined;
+ var next: u32 = 0;
+ for (0..2) |col| emitSurfaceCell(&g, &chrome, &instances, &next, @intCast(col), 0, fixedCellLayout(&g), 100, 100, cells[0..6], cover[0..6], col, null, false, bg_default);
+ try std.testing.expectEqual(@as(u32, 4), next);
+ // Each of the box's two cells draws its slice of the mark's glyph, in
+ // the err ink pushed off the focused button's fill.
+ const fill = gripFill(&chrome, true, false, false);
+ const want = pardes.colors.pushAway(err, &.{fill}, pardes.colors.Roles.ink_floor);
+ try std.testing.expect(pardes.colors.contrast(want, fill) >= pardes.colors.Roles.ink_floor);
+ const drawn = g.atlas.glyphForCodepoint(0x2717);
+ try std.testing.expect(g.atlas.glyphs.get(.{ .face = drawn.face, .glyph = drawn.glyph, .role = .tagline, .decoration = .{ .bold = true }, .centered = true }) != null);
+ for ([_]usize{ 1, 3 }) |i| {
+ try std.testing.expectEqual(@as(f32, @floatFromInt(want[0])) / 255, instances[i].fr);
+ try std.testing.expectEqual(@as(f32, @floatFromInt(want[1])) / 255, instances[i].fg);
+ try std.testing.expectEqual(@as(f32, @floatFromInt(want[2])) / 255, instances[i].fb);
+ }
+ // The mode's two bars are not drawn under it; without a mark they are.
+ const layout = fixedCellLayout(&g);
+ try gripDecor(&g, gpa, &grip, &cells, &chrome, layout, 6, 2, 100, 100);
+ const marked = g.decor.items.len;
+ g.decor.clearRetainingCapacity();
+ cells[1] = cells[2];
+ try gripDecor(&g, gpa, &grip, &cells, &chrome, layout, 6, 2, 100, 100);
+ try std.testing.expectEqual(marked + 2, g.decor.items.len);
+}