diff --git a/src/diagram.typ b/src/diagram.typ index 1078454..c2c2656 100644 --- a/src/diagram.typ +++ b/src/diagram.typ @@ -9,6 +9,15 @@ ),) } +#let _evt(participant, event) = { + return (( + type: "evt", + participant: participant, + event: event, + lifeline-style: auto + ),) +} + #let diagram(elements) = { if elements == none { return diff --git a/src/lib.typ b/src/lib.typ index eb85b65..8574fbd 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -1,4 +1,4 @@ -#import "diagram.typ": diagram, from-plantuml, _gap +#import "diagram.typ": diagram, from-plantuml, _gap, _evt #import "sequence.typ": _seq #import "group.typ": _grp diff --git a/src/renderer.typ b/src/renderer.typ index e3a3f78..b4d6605 100644 --- a/src/renderer.typ +++ b/src/renderer.typ @@ -49,6 +49,18 @@ p.max-lifelines = calc.max(p.max-lifelines, p.lifeline-lvl) participants.at(i2) = p } + } else if elmt.type == "evt" { + let par-name = elmt.participant + let i = pars-i.at(par-name) + let par = participants.at(i) + if elmt.event == "disable" or elmt.event == "destroy" { + par.lifeline-lvl -= 1 + + } else if elmt.event == "enable" { + par.lifeline-lvl += 1 + par.max-lifelines = calc.max(par.max-lifelines, par.lifeline-lvl) + } + participants.at(i) = par } } @@ -173,6 +185,29 @@ // Gap } else if elmt.type == "gap" { y -= elmt.size + + // Event + } else if elmt.type == "evt" { + let par-name = elmt.participant + let i = pars-i.at(par-name) + let par = participants.at(i) + let line = lifelines.at(i) + if elmt.event == "disable" { + line.level -= 1 + line.lines.push(("disable", y)) + + } else if elmt.event == "destroy" { + line.lines.push(("destroy", y)) + + } else if elmt.event == "enable" { + line.level += 1 + line.lines.push(("enable", y, elmt.lifeline-style)) + + } else if elmt.event == "create" { + shapes += participant.render(x-pos, par, y: y) + line.lines.push(("create", y)) + } + lifelines.at(i) = line } }