refactored separator to use CeTZ style
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
#import "/src/cetz.typ": draw
|
||||
#import "/src/cetz.typ": draw, styles
|
||||
|
||||
#import "/src/consts.typ": default-style
|
||||
|
||||
#let is-elmt(elmt) = {
|
||||
if type(elmt) != dictionary {
|
||||
@ -93,19 +95,31 @@
|
||||
)
|
||||
})
|
||||
|
||||
#let extract-ctx(cetz-ctx) = {
|
||||
let state = cetz-ctx.at("shared-state", default: (:))
|
||||
return state.at("chronos", default: (:))
|
||||
}
|
||||
|
||||
#let set-ctx(func) = draw.set-ctx(c => {
|
||||
let ctx = c.shared-state.chronos
|
||||
let ctx = extract-ctx(c)
|
||||
let new-ctx = func(ctx)
|
||||
assert(new-ctx != none, message: "set-ctx must return a context!")
|
||||
c.shared-state.chronos = new-ctx
|
||||
let state = c.at("shared-state", default: (:))
|
||||
state.chronos = new-ctx
|
||||
c.shared-state = state
|
||||
return c
|
||||
})
|
||||
|
||||
#let get-ctx(func) = draw.get-ctx(c => {
|
||||
let ctx = c.shared-state.chronos
|
||||
let ctx = extract-ctx(c)
|
||||
func(ctx)
|
||||
})
|
||||
|
||||
#let set-y(new-y) = set-ctx(c => {
|
||||
c.y = new-y
|
||||
return c
|
||||
})
|
||||
|
||||
#let expand-parent-group(x0, x1) = set-ctx(ctx => {
|
||||
if ctx.groups.len() != 0 {
|
||||
let group = ctx.groups.last()
|
||||
@ -114,4 +128,18 @@
|
||||
ctx.groups.last() = group
|
||||
}
|
||||
return ctx
|
||||
})
|
||||
|
||||
#let with-ctx-style(func) = draw.get-ctx(cetz-ctx => {
|
||||
let ctx = extract-ctx(cetz-ctx)
|
||||
let glob-style = styles.resolve(
|
||||
cetz-ctx.style,
|
||||
root: "chronos",
|
||||
base: default-style
|
||||
)
|
||||
|
||||
// Normalize because it is used very frequently
|
||||
glob-style.y-space = normalize-units(glob-style.y-space)
|
||||
|
||||
func(ctx, glob-style)
|
||||
})
|
Reference in New Issue
Block a user