diff options
Diffstat (limited to 'anim/src/ui.zig')
| -rw-r--r-- | anim/src/ui.zig | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/anim/src/ui.zig b/anim/src/ui.zig index 589bfb6..eeac127 100644 --- a/anim/src/ui.zig +++ b/anim/src/ui.zig @@ -555,13 +555,14 @@ pub const Ui = struct { 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); + u.pinNames(cx, y, names, inks, size, 0); } /// 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 { + /// second right of it ("" for a side kept free), the rest a count, or + /// by name where they fit before `room` (an x; 0: none); 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, room: f32) void { const p = theme.metric.pin; const by = y + 8 + size * 0.86; const ink = struct { @@ -573,7 +574,15 @@ pub const Ui = struct { // 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, 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); + var x = cx + p.under_names + u.width(.mono, size, names[1]) + advance(size) / 2; + var end = x; + for (names[2..]) |n| end += u.width(.mono, size, n) + advance(size) / 2; + if (names.len > 2 and end - advance(size) / 2 <= room) { + for (names[2..], 2..) |n, i| { + u.text(.mono_bold, size, x, by, n, ink(inks, i)); + x += u.width(.mono, size, n) + advance(size) / 2; + } + } else if (names.len > 2) u.text(.mono_bold, size, x, by, u.print("+{d}", .{names.len - 2}), theme.color.text.primary); } } |
