refactored event styling

This commit is contained in:
2025-07-28 21:36:00 +02:00
parent f308ef7f4a
commit c6e01b6b3b
4 changed files with 14 additions and 6 deletions

View File

@@ -24,7 +24,7 @@
let y1 = ctx.y - size let y1 = ctx.y - size
for (i, line) in ctx.lifelines.enumerate() { for (i, line) in ctx.lifelines.enumerate() {
line.events.push((type: "delay-start", y: y0)) line.events.push((type: "delay-start", y: y0))
line.events.push((type: "delay-end", y: y1, stroke: style.stroke)) line.events.push((type: "delay-end", y: y1, style: style))
ctx.lifelines.at(i) = line ctx.lifelines.at(i) = line
} }
if delay.name != none { if delay.name != none {

View File

@@ -1,18 +1,26 @@
#import "/src/cetz.typ": styles
#import "/src/consts.typ": * #import "/src/consts.typ": *
#import "/src/core/utils.typ": get-ctx, set-ctx #import "/src/core/utils.typ": get-ctx, set-ctx
#let render(evt) = get-ctx(ctx => { #let render(evt) = get-ctx(ctx => {
let style = styles.resolve(
ctx.style,
merge: evt.style,
root: "event",
base: ()
)
let par-name = evt.participant let par-name = evt.participant
let i = ctx.pars-i.at(par-name) let i = ctx.pars-i.at(par-name)
let par = ctx.participants.at(i) let par = ctx.participants.at(i)
let line = ctx.lifelines.at(i) let line = ctx.lifelines.at(i)
let entry = (type: evt.event, y: ctx.y) let entry = (type: evt.event, y: ctx.y, style: style)
if evt.event == "disable" { if evt.event == "disable" {
line.level -= 1 line.level -= 1
} else if evt.event == "enable" { } else if evt.event == "enable" {
line.level += 1 line.level += 1
entry.insert("style", evt.lifeline-style)
} else if evt.event == "create" { } else if evt.event == "create" {
ctx.y -= CREATE-OFFSET ctx.y -= CREATE-OFFSET
entry.y = ctx.y entry.y = ctx.y

View File

@@ -156,7 +156,7 @@
draw.line( draw.line(
(x, last-y), (x, last-y),
(x, event.y), (x, event.y),
stroke: event.stroke stroke: event.style.stroke
) )
last-y = event.y last-y = event.y
} }

View File

@@ -43,13 +43,13 @@
),) ),)
} }
#let _evt(participant, event) = { #let _evt(participant, event, ..style) = {
return (( return ((
type: "evt", type: "evt",
draw: evt-render, draw: evt-render,
participant: participant, participant: participant,
event: event, event: event,
lifeline-style: auto style: style.named()
),) ),)
} }