diff --git a/src/core/draw/sequence.typ b/src/core/draw/sequence.typ index 512c6ca..b1f0659 100644 --- a/src/core/draw/sequence.typ +++ b/src/core/draw/sequence.typ @@ -394,6 +394,11 @@ set-ctx(c => { c.y = end-info.y c.lifelines = ctx.lifelines + c.last-drawn = ( + type: "seq", + start-info: start-info, + end-info: end-info + ) return c }) }) diff --git a/src/core/draw/sync.typ b/src/core/draw/sync.typ index 1a300a7..b681947 100644 --- a/src/core/draw/sync.typ +++ b/src/core/draw/sync.typ @@ -1,11 +1,17 @@ #import "/src/core/utils.typ": get-ctx, is-elmt, set-ctx +#import "/src/cetz.typ": draw #let render(sync) = get-ctx(ctx => { set-ctx(c => { - c.sync-ys = () + c.sync = ( + bottoms: (), + starts: (), + y: ctx.y + ) return c }) + // Compute heights for e in sync.elmts { assert(is-elmt(e), message: "Sync element can only contain chronos elements, found " + repr(e)) assert( @@ -17,16 +23,34 @@ c.y = ctx.y return c }) - (e.draw)(e) + draw.hide({ + (e.draw)(e) + }) set-ctx(c => { - c.sync-ys.push(c.y) + c.sync.starts.push(c.last-drawn.start-info.y) + c.sync.bottoms.push(c.y) return c }) } set-ctx(c => { - c.y = calc.min(..c.sync-ys) - c.remove("sync-ys") + c.sync-y = calc.min(..c.sync.starts) + return c + }) + + // Draw aligned elements + for (i, e) in sync.elmts.enumerate() { + set-ctx(c => { + let dy = c.sync.starts.at(i) - ctx.y + c.y = c.sync-y - dy + return c + }) + (e.draw)(e) + } + + set-ctx(c => { + c.y = calc.min(..c.sync.bottoms) + c.remove("sync") return c }) }) \ No newline at end of file diff --git a/tests/sequence/sync/.gitignore b/tests/sequence/sync/.gitignore new file mode 100644 index 0000000..40223be --- /dev/null +++ b/tests/sequence/sync/.gitignore @@ -0,0 +1,4 @@ +# generated by tytanic, do not edit + +diff/** +out/** diff --git a/tests/sequence/sync/ref/1.png b/tests/sequence/sync/ref/1.png new file mode 100644 index 0000000..a7d4067 Binary files /dev/null and b/tests/sequence/sync/ref/1.png differ diff --git a/tests/sequence/sync/test.typ b/tests/sequence/sync/test.typ new file mode 100644 index 0000000..35098d8 --- /dev/null +++ b/tests/sequence/sync/test.typ @@ -0,0 +1,37 @@ +#set page(width: auto, height: auto) +#import "/src/lib.typ": * + +#diagram({ + _par("a") + _par("b") + _par("c") + _sync({ + _seq("b", "a") + _seq("b", "c") + }) + _gap() + _sync({ + _seq("b", "a", comment: [Comment]) + _seq("b", "c") + }) + _gap() + _sync({ + _seq("b", "a") + _seq("b", "c", comment: [Comment]) + }) + _gap() + _sync({ + _seq("b", "a", comment: [Two\ lines]) + _seq("b", "c", comment: [Comment]) + }) + + _sync({ + _seq("b", "a") + _seq("b", "c", slant: 10) + }) + + _sync({ + _seq("b", "a") + _seq("b", "b") + }) +})