summaryrefslogtreecommitdiff
path: root/src/host/overlay.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 21:34:41 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:22:02 -0300
commit2348776791e9dd17afeb12a06ba42a4a71917bcf (patch)
tree780c4b12b76c8b97a28408dd40944d65f159fdc7 /src/host/overlay.zig
parent590ba7b9b579b97e34b51ab7e3460ebc85713343 (diff)
downloadsketchbook-2348776791e9dd17afeb12a06ba42a4a71917bcf.tar.gz
sketchbook-2348776791e9dd17afeb12a06ba42a4a71917bcf.zip
sketchbook: a drawing layer on top, host fixes for replay and migration
Diffstat (limited to 'src/host/overlay.zig')
-rw-r--r--src/host/overlay.zig13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/host/overlay.zig b/src/host/overlay.zig
index 919fff6..5219a83 100644
--- a/src/host/overlay.zig
+++ b/src/host/overlay.zig
@@ -16,7 +16,10 @@ fn shade(path: []const u8) abi.Color {
}
pub fn drawMemory(out: *List, arena: std.mem.Allocator, layout: memory.Layout, state: []const u8, width: f32) !void {
- const rows = (layout.fields.len + 1) / 2;
+ // Arrays show as wholes: their element leaves (`list[].x`) are left out.
+ var top_level: usize = 0;
+ for (layout.fields) |leaf| top_level += @intFromBool(leaf.dims.len == 0);
+ const rows = (top_level + 1) / 2;
const legend_top: f32 = 24;
const hex_top = legend_top + @as(f32, @floatFromInt(rows)) * 14 + 16;
const shown = @min(state.len, shown_bytes);
@@ -26,7 +29,11 @@ pub fn drawMemory(out: *List, arena: std.mem.Allocator, layout: memory.Layout, s
// Legend: two fixed-width columns filled down then across.
const column = (width - 60) / 2;
- for (layout.fields, 0..) |leaf, i| {
+ var row: usize = 0;
+ for (layout.fields) |leaf| {
+ if (leaf.dims.len != 0) continue;
+ const i = row;
+ row += 1;
var value: std.Io.Writer.Allocating = .init(arena);
try fields.format(leaf, state, &value.writer);
const name = if (leaf.path.len > 26) try std.fmt.allocPrint(arena, "{s}...", .{leaf.path[0..23]}) else leaf.path;
@@ -42,7 +49,7 @@ pub fn drawMemory(out: *List, arena: std.mem.Allocator, layout: memory.Layout, s
var colors: [shown_bytes]abi.Color = @splat(.{ .r = 0x9f, .g = 0x9f, .b = 0x9f });
for (layout.fields) |leaf| {
- if (leaf.offset >= shown) continue;
+ if (leaf.offset >= shown or leaf.dims.len != 0) continue;
@memset(colors[leaf.offset..@min(shown, leaf.offset + leaf.size)], shade(leaf.path));
}
for (state[0..shown], 0..) |byte, i| {