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

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