fixed sync alignment with unequal elements
All checks were successful
CI / tests (push) Successful in 18s

fixes #21
This commit is contained in:
2026-01-21 15:20:26 +01:00
parent a7db89b214
commit 34ec00768f
5 changed files with 75 additions and 5 deletions

View File

@@ -394,6 +394,11 @@
set-ctx(c => { set-ctx(c => {
c.y = end-info.y c.y = end-info.y
c.lifelines = ctx.lifelines c.lifelines = ctx.lifelines
c.last-drawn = (
type: "seq",
start-info: start-info,
end-info: end-info
)
return c return c
}) })
}) })

View File

@@ -1,11 +1,17 @@
#import "/src/core/utils.typ": get-ctx, is-elmt, set-ctx #import "/src/core/utils.typ": get-ctx, is-elmt, set-ctx
#import "/src/cetz.typ": draw
#let render(sync) = get-ctx(ctx => { #let render(sync) = get-ctx(ctx => {
set-ctx(c => { set-ctx(c => {
c.sync-ys = () c.sync = (
bottoms: (),
starts: (),
y: ctx.y
)
return c return c
}) })
// Compute heights
for e in sync.elmts { for e in sync.elmts {
assert(is-elmt(e), message: "Sync element can only contain chronos elements, found " + repr(e)) assert(is-elmt(e), message: "Sync element can only contain chronos elements, found " + repr(e))
assert( assert(
@@ -17,16 +23,34 @@
c.y = ctx.y c.y = ctx.y
return c return c
}) })
draw.hide({
(e.draw)(e) (e.draw)(e)
})
set-ctx(c => { 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 return c
}) })
} }
set-ctx(c => { set-ctx(c => {
c.y = calc.min(..c.sync-ys) c.sync-y = calc.min(..c.sync.starts)
c.remove("sync-ys") 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 return c
}) })
}) })

4
tests/sequence/sync/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# generated by tytanic, do not edit
diff/**
out/**

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -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")
})
})