diff options
Diffstat (limited to 'anim/src/rows.zig')
| -rw-r--r-- | anim/src/rows.zig | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/anim/src/rows.zig b/anim/src/rows.zig index 4d8a42b..9e5bbba 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -233,9 +233,13 @@ pub fn span(u: ui.Ui, w: f32, y0: f32, y1: f32, name: []const u8, newest: bool, const x = w - theme.metric.slot.span; const c = if (newest) theme.mark(.current).solid else theme.color.rule; u.bracket(x, y0 + 3, y1 - @as(f32, if (open) 0 else 3), c, theme.metric.bracket.quiet, -1, open); - const micro = theme.size.sans.micro; const mid = (y0 + y1) / 2 + 6; - u.text(.sans_medium, micro, x - 14 - u.width(.sans_medium, micro, name), mid, name, if (newest) t.bright else t.dim); + u.text(.sans_medium, theme.size.sans.micro, spanNameX(u, w, name), mid, name, if (newest) t.bright else t.dim); +} + +/// Where a `span`'s name begins, in a panel `w` wide. +pub fn spanNameX(u: ui.Ui, w: f32, name: []const u8) f32 { + return w - theme.metric.slot.span - 14 - u.width(.sans_medium, theme.size.sans.micro, name); } /// `call` `row`: `#n` at 12 (a gold plaque 40 wide on the newest), the @@ -266,18 +270,19 @@ pub fn fitted(u: ui.Ui, text: []const u8, width: f32) []const u8 { /// then a faint `…`. `current`: a gold plaque 50 wide on the number (its /// edges out `fire`), ember across; `marked`: the number as on the plaque, /// which its panel draws where the mark is (it slides). `trail`: the bar -/// (0 newest). -pub fn line(u: ui.Ui, y: f32, w: f32, number: u32, text: []const u8, styles: []const u8, state: union(enum) { plain, current: f32, marked, trail: usize }) void { +/// (0 newest). `widen`: how much more room the numbers of the window take +/// than three characters (`numberRoom`); the text moves right by as much. +pub fn line(u: ui.Ui, y: f32, w: f32, number: u32, widen: f32, text: []const u8, styles: []const u8, state: union(enum) { plain, current: f32, marked, trail: usize }) void { const gold = theme.mark(.current); switch (state) { - .current => |fire| u.current(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = row_h }, theme.metric.plaque.line, fire), + .current => |fire| u.current(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = row_h }, theme.metric.plaque.line + widen, fire), .trail => |k| u.trail(theme.stroke.rule, y, k), .plain, .marked => {}, } const on = state == .current or state == .marked; const num = u.print("{d}", .{number}); - u.text(if (on) .mono_bold else .mono, size, m.line_number_end - @as(f32, @floatFromInt(num.len)) * adv, baseline(y), num, if (on) gold.on_solid else t.faint); - const limit: usize = m.source_chars; + u.text(if (on) .mono_bold else .mono, size, m.line_number_end + widen - @as(f32, @floatFromInt(num.len)) * adv, baseline(y), num, if (on) gold.on_solid else t.faint); + const limit: usize = m.source_chars - @as(usize, @intFromFloat(widen / adv)); const end = @min(text.len, limit); var i: usize = 0; while (i < end) { @@ -285,11 +290,17 @@ pub fn line(u: ui.Ui, y: f32, w: f32, number: u32, text: []const u8, styles: []c while (j < end and styles[j] == styles[i]) j += 1; if (std.mem.indexOfNone(u8, text[i..j], " ") != null) { const class = styles[i]; - u.text(codeFace(class), size, m.line_text + @as(f32, @floatFromInt(i)) * adv, baseline(y), text[i..j], codeInk(class)); + u.text(codeFace(class), size, m.line_text + widen + @as(f32, @floatFromInt(i)) * adv, baseline(y), text[i..j], codeInk(class)); } i = j; } - if (text.len > limit) u.text(.mono, size, m.line_text + @as(f32, @floatFromInt(limit)) * adv, baseline(y), "\u{2026}", t.faint); + if (text.len > limit) u.text(.mono, size, m.line_text + widen + @as(f32, @floatFromInt(limit)) * adv, baseline(y), "\u{2026}", t.faint); +} + +/// How much wider than three characters a column of line numbers up to +/// `widest` is: nothing for a small program; SQLite's lines have six digits. +pub fn numberRoom(widest: u32) f32 { + return @as(f32, @floatFromInt(@max(std.fmt.count("{d}", .{widest}), 3) - 3)) * adv; } /// pardes's classes: none, keyword, string, number, comment. @@ -316,7 +327,7 @@ fn codeFace(class: u8) ui.Face { pub const Run = struct { first: u8, len: u8, - kind: enum { number, pointer, allocator, unread }, + kind: enum { number, pointer, text, allocator, unread }, /// Its mark: struck (heat), read (shows), held is in the heat. heat: ui.Heat = .none, read: f32 = 0, @@ -327,19 +338,34 @@ pub const Run = struct { /// region ink with `lead` at 18 (at 60% on a row that holds no drawn /// thing), the bytes from 132 on a pitch of 30, 12 more after the /// eighth; a field's bytes on raised paper in their ink (a pointer's in -/// the region it points into), an allocator's dim with no paper, never +/// the region it points into, text's in a string's), an allocator's (and +/// any that are no field of what the dump is about) dim with no paper, never /// read two dots a byte; a word's padding bytes faint. `reading` is drawn /// by the caller at 640. pub fn bytes(u: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *const [16]bool, runs: []const Run, region: u24, lead: usize, holds_drawn: bool, moment: Recording.Moment) void { + bytesAt(u, y, addr, values, known, runs, region, lead, holds_drawn, moment, 0); +} + +/// How far right of their column a row's bytes (and its reading) go to +/// leave its address room: none for one of eight digits, 42 for a stack +/// address's twelve. +pub fn addressRoom(addr: u64) f32 { + const b = theme.metric.bytes; + return @max(b.address + @as(f32, @floatFromInt(ui.digits(addr))) * adv + adv - b.first, 0); +} + +/// `bytes`, the sixteen bytes `shift` right of their column (`addressRoom`). +pub fn bytesAt(at: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *const [16]bool, runs: []const Run, region: u24, lead: usize, holds_drawn: bool, moment: Recording.Moment, shift: f32) void { const b = theme.metric.bytes; const base = baseline(y); - _ = u.address(b.address, base, addr, .{ .ink = if (holds_drawn) ui.rgb(region) else ui.mix(region, theme.color.page, theme.metric.context.lead_alpha), .lead = lead }); - if (holds_drawn) u.bracket(b.bracket, y + 3, y + row_h - 3, ui.mix(region, theme.color.page, theme.metric.context.lead_alpha), theme.metric.bracket.quiet, 1, false); + _ = at.address(b.address, base, addr, .{ .ink = if (holds_drawn) ui.rgb(region) else ui.mix(region, theme.color.page, theme.metric.context.lead_alpha), .lead = lead }); + if (holds_drawn) at.bracket(b.bracket, y + 3, y + row_h - 3, ui.mix(region, theme.color.page, theme.metric.context.lead_alpha), theme.metric.bracket.quiet, 1, false); + const u = at.moved(shift, 0); for (runs) |run| { const x0 = byteX(run.first) - 4; const x1 = byteX(run.first + run.len - 1) + 28; const r: Rect = .{ .x = x0, .y = y + 1, .w = x1 - x0, .h = row_h - 2 }; - const field = run.kind == .number or run.kind == .pointer; + const field = run.kind == .number or run.kind == .pointer or run.kind == .text; if (field) u.fill(r, theme.color.raised); // Marks per run, never per byte: struck (the paper solid), read (a // frame 3 out), held (a tick in the gap at the run's left). @@ -367,6 +393,7 @@ pub fn bytes(u: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *const [ const run_ink: ui.Color = switch (run.kind) { .number => ui.rgb(t.primary), .pointer => ui.rgb(if (run.len == 8) ink(regionOf(moment, word)) else t.primary), + .text => ui.rgb(theme.color.string), .allocator => ui.rgb(t.dim), .unread => ui.rgb(t.faint), }; |
