From ff8ec72a42db921319c8c8f8ea80dcf7dd2fc28a Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Fri, 18 Jul 2025 17:30:00 +0200 Subject: [PATCH] changed internal lifelines structure --- src/core/draw/event.typ | 8 +++--- src/core/draw/participant.typ | 53 ++++++++++++++++------------------- src/core/draw/sequence.typ | 12 ++++---- src/core/renderer.typ | 2 +- 4 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/core/draw/event.typ b/src/core/draw/event.typ index bc39297..15ab0cc 100644 --- a/src/core/draw/event.typ +++ b/src/core/draw/event.typ @@ -6,23 +6,23 @@ let i = ctx.pars-i.at(par-name) let par = ctx.participants.at(i) let line = ctx.lifelines.at(i) - let entry = (evt.event, ctx.y) + let entry = (type: evt.event, y: ctx.y) if evt.event == "disable" { line.level -= 1 } else if evt.event == "enable" { line.level += 1 - entry.push(evt.lifeline-style) + entry.insert("style", evt.lifeline-style) } else if evt.event == "create" { ctx.y -= CREATE-OFFSET - entry.at(1) = ctx.y + entry.y = ctx.y (par.draw)(par, y: ctx.y) } else if evt.event == "destroy" { } else { panic("Unknown event '" + evt.event + "'") } - line.lines.push(entry) + line.events.push(entry) set-ctx(c => { c.lifelines.at(i) = line c.y = ctx.y diff --git a/src/core/draw/participant.typ b/src/core/draw/participant.typ index d7c87e3..3d57fcf 100644 --- a/src/core/draw/participant.typ +++ b/src/core/draw/participant.typ @@ -318,59 +318,54 @@ let rects = () let destructions = () - let lines = () + let stack = () // Compute lifeline rectangles + destruction positions - for line in ctx.lifelines.at(p.i).lines { - let event = line.first() - if event == "create" { + for event in ctx.lifelines.at(p.i).events { + if event.type == "create" { last-y = line.at(1) - } else if event == "enable" { - if lines.len() == 0 { + } else if event.type == "enable" { + if stack.len() == 0 { draw.line( (x, last-y), - (x, line.at(1)), + (x, event.y), stroke: p.line-stroke ) } - lines.push(line) + stack.push(event) - } else if event == "disable" or event == "destroy" { + } else if event.type == "disable" or event.type == "destroy" { let lvl = 0 - if lines.len() != 0 { - let l = lines.pop() - lvl = lines.len() + if stack.len() != 0 { + let e = stack.pop() + lvl = stack.len() rects.push(( x + lvl * LIFELINE-W / 2, - l.at(1), - line.at(1), - l.at(2) + e.y, + event.y, + e.style )) - last-y = line.at(1) + last-y = event.y } - if event == "destroy" { - destructions.push((x + lvl * LIFELINE-W / 2, line.at(1))) + if event.type == "destroy" { + destructions.push((x + lvl * LIFELINE-W / 2, event.y)) } - } else if event == "delay-start" { + } else if event.type == "delay-start" { draw.line( (x, last-y), - (x, line.at(1)), + (x, event.y), stroke: p.line-stroke ) - last-y = line.at(1) - } else if event == "delay-end" { + last-y = event.y + } else if event.type == "delay-end" { draw.line( (x, last-y), - (x, line.at(1)), - stroke: ( - dash: "loosely-dotted", - paint: gray.darken(40%), - thickness: .8pt - ) + (x, event.y), + stroke: event.stroke ) - last-y = line.at(1) + last-y = event.y } } diff --git a/src/core/draw/sequence.typ b/src/core/draw/sequence.typ index 49103e6..9082a90 100644 --- a/src/core/draw/sequence.typ +++ b/src/core/draw/sequence.typ @@ -102,23 +102,23 @@ if seq.disable-src { let src-line = ctx.lifelines.at(i1) src-line.level -= 1 - src-line.lines.push(("disable", start-info.y)) + src-line.events.push((type: "disable", y: start-info.y)) ctx.lifelines.at(i1) = src-line } if seq.destroy-src { let src-line = ctx.lifelines.at(i1) - src-line.lines.push(("destroy", start-info.y)) + src-line.events.push((type: "destroy", y: start-info.y)) ctx.lifelines.at(i1) = src-line } if seq.disable-dst { let dst-line = ctx.lifelines.at(i2) dst-line.level -= 1 - dst-line.lines.push(("disable", end-info.y)) + dst-line.events.push((type: "disable", y: end-info.y)) ctx.lifelines.at(i2) = dst-line } if seq.destroy-dst { let dst-line = ctx.lifelines.at(i2) - dst-line.lines.push(("destroy", end-info.y)) + dst-line.events.push((type: "destroy", y: end-info.y)) ctx.lifelines.at(i2) = dst-line } if seq.enable-dst { @@ -341,12 +341,12 @@ if seq.create-dst { let dst-line = ctx.lifelines.at(i2) - dst-line.lines.push(("create", end-info.y)) + dst-line.events.push((type: "create", y: end-info.y)) ctx.lifelines.at(i2) = dst-line } if seq.enable-dst { let dst-line = ctx.lifelines.at(i2) - dst-line.lines.push(("enable", end-info.y, seq.lifeline-style)) + dst-line.events.push((type: "enable", y: end-info.y, style: seq.lifeline-style)) ctx.lifelines.at(i2) = dst-line } diff --git a/src/core/renderer.typ b/src/core/renderer.typ index 1bb3297..e3a9363 100644 --- a/src/core/renderer.typ +++ b/src/core/renderer.typ @@ -333,7 +333,7 @@ groups: (), lifelines: participants.map(_ => ( level: 0, - lines: () + events: () )) ) chronos-ctx.insert(