summaryrefslogtreecommitdiff
path: root/anim/src/ui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/ui.zig')
-rw-r--r--anim/src/ui.zig81
1 files changed, 79 insertions, 2 deletions
diff --git a/anim/src/ui.zig b/anim/src/ui.zig
index 48d2f64..6120bbb 100644
--- a/anim/src/ui.zig
+++ b/anim/src/ui.zig
@@ -281,6 +281,40 @@ pub const Ui = struct {
return end;
}
+ /// `value` of a class a type or a signature gives, from `x` at mono
+ /// 20: `fd`, the number and faint what it is open on (`3 "note"`);
+ /// `boolean`, `true` or `false`; `character`, its code as a small
+ /// number and faint the character quoted (`0x41 'A'`). Returns where
+ /// it ends.
+ pub fn typed(u: Ui, x: f32, baseline: f32, v: u64, class: Class, ink: Ink) f32 {
+ const size = theme.size.mono.context;
+ const adv = advance(size);
+ const t = theme.color.text;
+ switch (class) {
+ .fd => |on| {
+ const number = u.print("{d}", .{@as(i32, @bitCast(@as(u32, @truncate(v))))});
+ u.text(ink.face, size, x, baseline, number, ink.ink);
+ const end = x + @as(f32, @floatFromInt(number.len)) * adv;
+ if (on.len == 0) return end;
+ u.text(.mono, size, end + 8, baseline, on, t.faint);
+ return end + 8 + u.width(.mono, size, on);
+ },
+ .boolean => {
+ const word = if (v != 0) "true" else "false";
+ u.text(ink.face, size, x, baseline, word, ink.ink);
+ return x + @as(f32, @floatFromInt(word.len)) * adv;
+ },
+ .character => {
+ const code = u.print("0x{x:0>2}", .{v & 0xff});
+ u.text(ink.face, size, x, baseline, code, ink.ink);
+ const end = x + @as(f32, @floatFromInt(code.len)) * adv;
+ const quoted = quote(u, @truncate(v));
+ u.text(.mono, size, end + 8, baseline, quoted, t.faint);
+ return end + 8 + u.width(.mono, size, quoted);
+ },
+ }
+ }
+
/// `arrow`: the sign between two things in a chain, 30 wide from `x`
/// on the row whose middle is `mid`, faint: grammar, not data.
/// Returns where it ends.
@@ -403,15 +437,41 @@ pub const Ui = struct {
/// edge at (`cx`, `y`), a head 10 by 10 on it, the first name left of
/// the stub and the others right, bold, primary.
pub fn pinUnder(u: Ui, cx: f32, y: f32, names: []const []const u8, ink: anytype, size: f32) void {
+ u.pinUnderInked(cx, y, names, &.{}, ink, size);
+ }
+
+ /// The same, each name in its own ink (`pinNames`).
+ pub fn pinUnderInked(u: Ui, cx: f32, y: f32, names: []const []const u8, inks: []const u24, ink: anytype, size: f32) void {
const p = theme.metric.pin;
const rise = size + 10;
+ // A keyline of page round the stub and its head: an arrow between
+ // nodes that runs under it is seen to pass behind, not to join it.
+ const key = theme.stroke.rule;
+ u.fill(.{ .x = cx - p.stub / 2 - key, .y = y + p.under_head[0] - 1, .w = p.stub + 2 * key, .h = rise - p.under_head[0] + 1 }, theme.color.page);
+ sk.draw.polygon(u.f, &.{ .{ cx, y }, .{ cx - p.under_head[1] / 2 - key - 1, y + 1 + p.under_head[0] + key }, .{ cx + p.under_head[1] / 2 + key + 1, y + 1 + p.under_head[0] + key } }, u.at.pen(.{ .fill = rgb(theme.color.page) }));
u.fill(.{ .x = cx - p.stub / 2, .y = y + p.under_head[0] - 1, .w = p.stub, .h = rise - p.under_head[0] + 1 }, ink);
sk.draw.polygon(u.f, &.{ .{ cx, y + 1 }, .{ cx - p.under_head[1] / 2, y + 1 + p.under_head[0] }, .{ cx + p.under_head[1] / 2, y + 1 + p.under_head[0] } }, u.at.pen(.{ .fill = rgb(ink) }));
if (names.len == 0) return;
+ u.pinNames(cx, y, names, inks, size);
+ }
+
+ /// The names of a `pin` `under`: the first left of the stub, the
+ /// second right of it ("" for a side kept free), the rest a count;
+ /// each bold in `inks` (a variable's: where it lives) or primary.
+ pub fn pinNames(u: Ui, cx: f32, y: f32, names: []const []const u8, inks: []const u24, size: f32) void {
+ const p = theme.metric.pin;
const by = y + 8 + size * 0.86;
- u.text(.mono_bold, size, cx - p.under_names - u.width(.mono, size, names[0]), by, names[0], theme.color.text.primary);
+ const ink = struct {
+ fn of(all: []const u24, i: usize) u24 {
+ return if (i < all.len) all[i] else theme.color.text.primary;
+ }
+ }.of;
+ u.text(.mono_bold, size, cx - p.under_names - u.width(.mono, size, names[0]), by, names[0], ink(inks, 0));
// One name a side: a node's neighbour has its own. The rest are a count.
- if (names.len > 1) u.text(.mono_bold, size, cx + p.under_names, by, if (names.len > 2) u.print("{s} +{d}", .{ names[1], names.len - 2 }) else names[1], theme.color.text.primary);
+ if (names.len > 1) {
+ u.text(.mono_bold, size, cx + p.under_names, by, names[1], ink(inks, 1));
+ if (names.len > 2) u.text(.mono_bold, size, cx + p.under_names + u.width(.mono, size, names[1]) + advance(size) / 2, by, u.print("+{d}", .{names.len - 2}), theme.color.text.primary);
+ }
}
/// `bracket`: a span marked at its edge, a stroke down `y0 .. y1` at
@@ -557,6 +617,23 @@ pub const Value = struct {
}
};
+/// The classes of `value` a type or a signature gives (`Ui.typed`); `fd`
+/// carries what the descriptor is open on.
+pub const Class = union(enum) { fd: []const u8, boolean, character };
+
+/// A character as C writes it, quoted: `'A'`, `'\n'`, `'\x00'`.
+pub fn quote(u: Ui, c: u8) []const u8 {
+ return switch (c) {
+ '\n' => "'\\n'",
+ '\t' => "'\\t'",
+ '\r' => "'\\r'",
+ 0 => "'\\0'",
+ '\'' => "'\\''",
+ '\\' => "'\\\\'",
+ else => if (std.ascii.isPrint(c)) u.print("'{c}'", .{c}) else u.print("'\\x{x:0>2}'", .{c}),
+ };
+}
+
/// `address`'s options.
pub const Address = struct {
ink: Color = rgb(theme.color.region.code_),