forked from HEL/chronos
adapted custom shape rendering
This commit is contained in:
@ -1,32 +1,41 @@
|
|||||||
#import "/src/cetz.typ": draw
|
#import "/src/cetz.typ": draw
|
||||||
|
|
||||||
#import "/src/core/utils.typ": normalize-measure
|
#import "/src/core/utils.typ": normalize-measure, normalize-units
|
||||||
#import "/src/consts.typ": *
|
#import "/src/consts.typ": *
|
||||||
|
|
||||||
#let name = "custom"
|
#let name = "custom"
|
||||||
|
|
||||||
#let render(x, y, p, bottom) = {
|
#let render(x, y, p, bottom) = {
|
||||||
let m = measure(p.display-name)
|
|
||||||
let style = p.resolved-style
|
let style = p.resolved-style
|
||||||
let image-m = measure(style.custom-image)
|
let shape = align(
|
||||||
let y0 = if bottom {y - m.height / 1pt - SYM-GAP} else {y + m.height / 1pt + image-m.height / 1pt + SYM-GAP}
|
center,
|
||||||
draw.content((x - image-m.width / 2pt, y0), style.custom-image, anchor: "north-west")
|
stack(
|
||||||
|
dir: ttb,
|
||||||
|
spacing: normalize-units(style.spacing) * 1pt,
|
||||||
|
style.image,
|
||||||
|
p.display-name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
let anchor = if bottom {"north"} else {"base"}
|
||||||
draw.content(
|
draw.content(
|
||||||
(x, y),
|
(x, y),
|
||||||
p.display-name,
|
shape,
|
||||||
anchor: if bottom {"north"} else {"base"}
|
anchor: anchor
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#let get-size(par) = {
|
#let get-size(par) = {
|
||||||
let m = normalize-measure(par.display-name)
|
let name-m = normalize-measure(par.display-name)
|
||||||
|
let img-m = normalize-measure(par.resolved-style.image)
|
||||||
|
let spacing = normalize-units(par.resolved-style.spacing)
|
||||||
|
|
||||||
// measure(style.custom-image).width
|
return (
|
||||||
// measure(style.custom-image).height + SYM-GAP * 1pt + h
|
width: calc.max(name-m.width, img-m.width),
|
||||||
|
height: name-m.height + spacing + img-m.height
|
||||||
return m
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#let default-style = (
|
#let default-style = (
|
||||||
:
|
image: none,
|
||||||
|
spacing: 5pt
|
||||||
)
|
)
|
@ -13,11 +13,7 @@
|
|||||||
fill: style.fill,
|
fill: style.fill,
|
||||||
stroke: style.stroke
|
stroke: style.stroke
|
||||||
)
|
)
|
||||||
let anchor = if bottom {
|
let anchor = if bottom {"north"} else {"base"}
|
||||||
"north"
|
|
||||||
} else {
|
|
||||||
"base"
|
|
||||||
}
|
|
||||||
draw.content(
|
draw.content(
|
||||||
(x, y),
|
(x, y),
|
||||||
name,
|
name,
|
||||||
|
Reference in New Issue
Block a user