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:
@@ -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
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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
4
tests/sequence/sync/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# generated by tytanic, do not edit
|
||||||
|
|
||||||
|
diff/**
|
||||||
|
out/**
|
||||||
BIN
tests/sequence/sync/ref/1.png
Normal file
BIN
tests/sequence/sync/ref/1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
37
tests/sequence/sync/test.typ
Normal file
37
tests/sequence/sync/test.typ
Normal 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")
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user