summaryrefslogtreecommitdiff
path: root/anim/src/aside.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/aside.zig')
-rw-r--r--anim/src/aside.zig29
1 files changed, 17 insertions, 12 deletions
diff --git a/anim/src/aside.zig b/anim/src/aside.zig
index 5400da5..c2c0ef8 100644
--- a/anim/src/aside.zig
+++ b/anim/src/aside.zig
@@ -1,7 +1,8 @@
//! A text beside what it speaks of, for a scene that builds its parts in
//! place rather than in the column's panes (the introduction): the
//! column's `bubble` (design/README.md, "column"), standing alone. Go 40
-//! on 54, code in mono 35, at most 40 characters a line, 16 of padding;
+//! on 54, code in mono 35, at most 40 characters a line (twice as many
+//! for a text `above` a subject across both columns: `Asides.wrap`), 16 of padding;
//! the newest on `raised` paper, primary; an older one loses its paper and
//! dims to `dim` (`dim`, 18 f). It arrives rising 8 (its object's fade,
//! 18 f, `enter`) and leaves with its fade (12 f, `exit`). No stem: its
@@ -28,10 +29,12 @@ pub const Aside = struct {
level: f32,
/// 0 newest, 1 the account (no paper, `dim`).
dim: anim.Value,
+ /// Characters a line, at most.
+ wrap: usize = chars,
pub fn draw(a: *const Aside, f: *sk.Frame, placed: anim.Placed) void {
const u = (ui.Ui{ .f = f, .at = placed }).moved(0, (1 - placed.pose.opacity) * theme.time.caption_rise);
- const wrapped = wrap(u, a.text);
+ const wrapped = wrap(u, a.text, a.wrap);
const top = a.level - first;
const h = first * 2 + @as(f32, @floatFromInt(wrapped.len - 1)) * line_pitch;
var w: f32 = 0;
@@ -54,13 +57,15 @@ pub const Asides = struct {
spans: [8][2]f32 = undefined,
n: usize = 0,
read_by: f32 = 0,
+ /// Characters a line, at most, of the texts it says.
+ wrap: usize = chars,
pub fn say(a: *Asides, s: *anim.Frame, text: []const u8, x: f32, level: f32) void {
s.wait(@max(a.read_by - s.cursor, 0));
const dim = s.value(0);
- const made = s.new(Aside{ .text = text, .x = x, .level = level, .dim = dim });
+ const made = s.new(Aside{ .text = text, .x = x, .level = level, .dim = dim, .wrap = a.wrap });
const obj = s.custom(made, .{ .x = -640, .y = -360, .scale = ui.scale });
- const span = [2]f32{ level - first, level + first + @as(f32, @floatFromInt(lines(text) - 1)) * line_pitch };
+ const span = [2]f32{ level - first, level + first + @as(f32, @floatFromInt(lines(text, a.wrap) - 1)) * line_pitch };
const at = s.cursor;
var in_the_way = false;
for (a.shown[0..a.n], a.dims[0..a.n], a.spans[0..a.n]) |*o, d, other| {
@@ -105,7 +110,7 @@ fn easeGlide(x: f32) f32 {
}
/// How many lines `wrap` makes of `text` (a newline breaks one where the author says).
-fn lines(text: []const u8) usize {
+fn lines(text: []const u8, most: usize) usize {
var count: usize = 0;
var paragraphs = std.mem.splitScalar(u8, text, '\n');
while (paragraphs.next()) |paragraph| {
@@ -114,7 +119,7 @@ fn lines(text: []const u8) usize {
count += 1;
while (it.next()) |word| {
const seen = (std.unicode.utf8CountCodepoints(word) catch word.len) - std.mem.count(u8, word, "`");
- if (n > 0 and n + 1 + seen > chars) {
+ if (n > 0 and n + 1 + seen > most) {
count += 1;
n = 0;
}
@@ -135,7 +140,7 @@ fn width(u: ui.Ui, line: []const u8) f32 {
/// Lines of at most `chars` visible characters, broken at spaces; a code
/// run keeps its backticks on each line it spans.
-fn wrap(u: ui.Ui, text: []const u8) []const []const u8 {
+fn wrap(u: ui.Ui, text: []const u8, most: usize) []const []const u8 {
var out: std.ArrayList([]const u8) = .empty;
var paragraphs = std.mem.splitScalar(u8, text, '\n');
while (paragraphs.next()) |paragraph| {
@@ -145,7 +150,7 @@ fn wrap(u: ui.Ui, text: []const u8) []const []const u8 {
while (it.next()) |word| {
const seen = std.unicode.utf8CountCodepoints(word) catch word.len;
const ticks = std.mem.count(u8, word, "`");
- if (n > 0 and n + 1 + seen - ticks > chars) {
+ if (n > 0 and n + 1 + seen - ticks > most) {
out.append(u.f.scratch, line.items) catch break;
line = .empty;
n = 0;
@@ -164,10 +169,10 @@ fn wrap(u: ui.Ui, text: []const u8) []const []const u8 {
}
test "lines of at most forty characters, backticks not counted" {
- try std.testing.expectEqual(@as(usize, 1), lines("Its address space, 128 TiB, to scale."));
- try std.testing.expectEqual(@as(usize, 2), lines("Its address space, 128 TiB, to scale: mapped only at each end."));
+ try std.testing.expectEqual(@as(usize, 1), lines("Its address space, 128 TiB, to scale.", chars));
+ try std.testing.expectEqual(@as(usize, 2), lines("Its address space, 128 TiB, to scale: mapped only at each end.", chars));
// Four code runs of nine: 39 shown, 47 with their backticks.
- try std.testing.expectEqual(@as(usize, 1), lines("`012345678` `012345678` `012345678` `012345678`"));
+ try std.testing.expectEqual(@as(usize, 1), lines("`012345678` `012345678` `012345678` `012345678`", chars));
// A newline breaks where the author says.
- try std.testing.expectEqual(@as(usize, 2), lines("And all of it at once:\nthe map."));
+ try std.testing.expectEqual(@as(usize, 2), lines("And all of it at once:\nthe map.", chars));
}