fixed sync alignment with unequal elements
All checks were successful
CI / tests (push) Successful in 18s
All checks were successful
CI / tests (push) Successful in 18s
fixes #21
This commit is contained in:
@@ -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
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user