refactored separator to use CeTZ style
This commit is contained in:
@@ -1,47 +1,65 @@
|
||||
#import "/src/cetz.typ": draw
|
||||
#import "/src/cetz.typ": draw, styles
|
||||
|
||||
#import "/src/consts.typ": *
|
||||
#import "/src/core/utils.typ": get-ctx, set-ctx
|
||||
#import "/src/core/utils.typ": normalize-units, set-y, with-ctx-style
|
||||
|
||||
#let render(sep) = get-ctx(ctx => {
|
||||
ctx.y -= Y-SPACE
|
||||
#let separator-default-style = (
|
||||
inset: (
|
||||
x: 3pt, y: 5pt
|
||||
),
|
||||
fill: auto,
|
||||
stroke: auto,
|
||||
gap: 3pt,
|
||||
outset: 20pt
|
||||
)
|
||||
|
||||
let x0 = ctx.x-pos.first() - 20
|
||||
let x1 = ctx.x-pos.last() + 20
|
||||
let m = measure(
|
||||
box(
|
||||
sep.name,
|
||||
inset: (left: 3pt, right: 3pt, top: 5pt, bottom: 5pt)
|
||||
)
|
||||
#let render(sep) = with-ctx-style((ctx, glob-style) => {
|
||||
let style = styles.resolve(
|
||||
glob-style,
|
||||
merge: sep.style,
|
||||
root: "separator",
|
||||
base: separator-default-style
|
||||
)
|
||||
let gap = normalize-units(style.gap)
|
||||
let outset = normalize-units(style.outset)
|
||||
|
||||
ctx.y -= glob-style.y-space
|
||||
|
||||
let x0 = ctx.x-pos.first() - outset
|
||||
let x1 = ctx.x-pos.last() + outset
|
||||
let name = box(
|
||||
sep.name,
|
||||
inset: style.inset,
|
||||
stroke: style.stroke,
|
||||
fill: style.fill
|
||||
)
|
||||
let m = measure(name)
|
||||
let w = m.width / 1pt
|
||||
let h = m.height / 1pt
|
||||
let cx = (x0 + x1) / 2
|
||||
let xl = cx - w / 2
|
||||
let xr = cx + w / 2
|
||||
|
||||
ctx.y -= h / 2
|
||||
draw.rect(
|
||||
(x0, ctx.y),
|
||||
(x1, ctx.y - 3),
|
||||
stroke: none,
|
||||
fill: white
|
||||
)
|
||||
draw.line((x0, ctx.y), (x1, ctx.y))
|
||||
ctx.y -= 3
|
||||
draw.line((x0, ctx.y), (x1, ctx.y))
|
||||
draw.content(
|
||||
((x0 + x1) / 2, ctx.y + 1.5),
|
||||
sep.name,
|
||||
anchor: "center",
|
||||
padding: (5pt, 3pt),
|
||||
frame: "rect",
|
||||
fill: COL-SEP-NAME
|
||||
)
|
||||
ctx.y -= h / 2
|
||||
let y0 = ctx.y
|
||||
let y2 = y0 - h
|
||||
let y1 = (y0 + y2) / 2
|
||||
|
||||
set-ctx(c => {
|
||||
c.y = ctx.y
|
||||
return c
|
||||
})
|
||||
let gap-y0 = y1 + gap / 2
|
||||
let gap-y1 = gap-y0 - gap
|
||||
|
||||
draw.rect(
|
||||
(x0, gap-y0),
|
||||
(x1, gap-y1),
|
||||
stroke: none,
|
||||
fill: style.fill
|
||||
)
|
||||
draw.line((x0, gap-y0), (x1, gap-y0))
|
||||
draw.line((x0, gap-y1), (x1, gap-y1))
|
||||
draw.content(
|
||||
(cx, y1),
|
||||
name,
|
||||
anchor: "mid"
|
||||
)
|
||||
|
||||
set-y(y2)
|
||||
})
|
||||
|
Reference in New Issue
Block a user