diff options
Diffstat (limited to 'examples/live/src/main.zig')
| -rw-r--r-- | examples/live/src/main.zig | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/examples/live/src/main.zig b/examples/live/src/main.zig index 65bf6cd..5e7fe64 100644 --- a/examples/live/src/main.zig +++ b/examples/live/src/main.zig @@ -87,6 +87,12 @@ pub const Session = struct { scope: scope.Scope = .{}, /// `capture` appends what is heard to `<stem>.capture.f32`. capturing: bool = false, + /// Each byte's place in the code as drawn, and the text's revision they + /// were laid out at: a layout shapes every piece of the text, and the + /// text moves at a key, not at a frame. + places: [Editor.capacity.text + 1]sk.text.Caret = undefined, + laid: sk.text.Layout = .{}, + laid_at: ?u32 = null, }; /// `capture` starts or stops appending what is heard to the sketch's file @@ -314,7 +320,7 @@ pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void { }); f.image(ss.picture, .{ .x = 0, .y = 0, .w = room[0], .h = room[1] }, .{}); sound(s, ss, f, room); - code(s, f, room); + code(s, ss, f, room); } /// The out tape over the sample clock, as much as keeps the host's lead @@ -424,14 +430,21 @@ fn box(at: []const sk.text.Caret, i: usize, space: f32) sk.Rect { /// caret at each range's head that says the mode (a block in normal and /// select, a bar in insert), the mode's name in the corner; the problem as /// a red mark under its byte and its words under the text. Every place is -/// measured: one layout gives each byte's, another draws. -fn code(s: *const State, f: *sk.Frame, room: [2]f32) void { +/// measured: one layout gives each byte's (kept until the text moves), +/// another draws. +fn code(s: *const State, ss: *Session, f: *sk.Frame, room: [2]f32) void { const text = s.ed.bytes(f.scratch) catch return; const ranges = f.scratch.create([pe.max_selections]pe.Selection) catch return; const got = s.ed.ranges(f.scratch, ranges) catch return; const p = paragraph(f.scratch, &s.ed, text); - const at = f.scratch.alloc(sk.text.Caret, text.len + 1) catch return; - const laid = sk.text.places(text, p, at); + const at = ss.places[0 .. text.len + 1]; + // a revision counts keys, it does not name a text: a jump can land on + // another text with the same count + if (ss.laid_at != s.ed.revision or f.in.jumped) { + ss.laid = sk.text.places(text, p, at); + ss.laid_at = s.ed.revision; + } + const laid = ss.laid; const space = sk.text.size(.code, scale, " ")[0]; const problem = s.problem.len > 0; const words: [2]f32 = if (problem) sk.text.size(.code, scale, s.problem.text()) else .{ 0, 0 }; |
