adapted queue shape rendering
This commit is contained in:
@ -1,60 +1,120 @@
|
|||||||
#import "/src/cetz.typ": draw
|
#import "/src/cetz.typ": draw
|
||||||
|
|
||||||
#import "/src/core/utils.typ": normalize-measure
|
#import "/src/core/utils.typ": normalize-measure
|
||||||
#import "/src/consts.typ": *
|
|
||||||
|
|
||||||
#let name = "queue"
|
#let name = "queue"
|
||||||
|
|
||||||
#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 w = (m.width + QUEUE-PAD.last() * 2) / 1pt
|
let m = normalize-measure(box(
|
||||||
let h = (m.height + QUEUE-PAD.first() * 2) / 1pt
|
p.display-name,
|
||||||
let total-h = h
|
inset: style.inset
|
||||||
let ry = total-h / 2
|
))
|
||||||
let rx = ry / 2
|
|
||||||
let total-w = w + 3 + 3 * rx
|
let w = m.width
|
||||||
|
let h = m.height
|
||||||
|
let ry = h / 2
|
||||||
|
let rx = ry / 2
|
||||||
|
let total-w = w + 3 * rx
|
||||||
|
|
||||||
|
let y0 = if bottom {y} else {y + h}
|
||||||
|
let y1 = y0 - h
|
||||||
|
let ym = y0 - ry
|
||||||
|
|
||||||
|
let xll = x - total-w / 2
|
||||||
|
let xrr = x + total-w / 2
|
||||||
|
let xlm = xll + rx
|
||||||
|
let xrm = xrr - rx
|
||||||
|
let xrl = xrm - rx
|
||||||
|
|
||||||
|
/*
|
||||||
|
/A----------/B\ --- y0
|
||||||
|
Fh G C --- ym
|
||||||
|
\E----------\D/ --- y1
|
||||||
|
|
||||||
|
|| |||
|
||||||
|
|| ||\-- xrr
|
||||||
|
|| |\--- xrm
|
||||||
|
|| \---- xrl
|
||||||
|
|\--------------- xlm
|
||||||
|
\---------------- xll
|
||||||
|
|
||||||
|
h <-> G == w
|
||||||
|
F <-> h == rx
|
||||||
|
G <-> C == 2 * rx == ry
|
||||||
|
A <-> E == B <-> D == 2 * ry == h
|
||||||
|
*/
|
||||||
|
|
||||||
let x0 = x - total-w / 2
|
|
||||||
let y0 = if bottom {y} else {y + total-h}
|
|
||||||
let y1 = y0 - total-h
|
|
||||||
let x-left = x0 + rx
|
|
||||||
let x-right = x-left + w + rx
|
|
||||||
draw.merge-path(
|
draw.merge-path(
|
||||||
close: true,
|
close: true,
|
||||||
fill: style.fill,
|
fill: style.fill,
|
||||||
stroke: style.stroke,
|
stroke: style.stroke,
|
||||||
{
|
{
|
||||||
draw.bezier((x-right, y0), (x-right + rx, y0 - ry), (x-right + rx/2, y0), (x-right + rx, y0 - ry/2))
|
draw.bezier(
|
||||||
draw.bezier((), (x-right, y1), (x-right + rx, y1 + ry/2), (x-right + rx/2, y1))
|
(xrm, y0),
|
||||||
draw.line((), (x-left, y1))
|
(xrr, ym),
|
||||||
draw.bezier((), (x-left - rx, y0 - ry), (x-left - rx/2, y1), (x-left - rx, y1 + ry/2))
|
(xrm + rx/2, y0),
|
||||||
draw.bezier((), (x-left, y0), (x-left - rx, y0 - ry/2), (x-left - rx/2, y0))
|
(xrr, ym + ry/2)
|
||||||
|
)
|
||||||
|
draw.bezier(
|
||||||
|
(),
|
||||||
|
(xrm, y1),
|
||||||
|
(xrr, ym - ry/2),
|
||||||
|
(xrm + rx/2, y1)
|
||||||
|
)
|
||||||
|
draw.line((), (xlm, y1))
|
||||||
|
draw.bezier(
|
||||||
|
(),
|
||||||
|
(xll, ym),
|
||||||
|
(xlm - rx/2, y1),
|
||||||
|
(xll, ym - ry/2)
|
||||||
|
)
|
||||||
|
draw.bezier(
|
||||||
|
(),
|
||||||
|
(xlm, y0),
|
||||||
|
(xll, ym + ry/2),
|
||||||
|
(xlm - rx/2, y0)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
draw.merge-path(
|
draw.merge-path(
|
||||||
stroke: style.stroke,
|
stroke: style.stroke,
|
||||||
{
|
{
|
||||||
draw.bezier((x-right, y0), (x-right - rx, y0 - ry), (x-right - rx/2, y0), (x-right - rx, y0 - ry/2))
|
draw.bezier(
|
||||||
draw.bezier((), (x-right, y1), (x-right - rx, y1 + ry/2), (x-right - rx/2, y1))
|
(xrm, y0),
|
||||||
|
(xrl, ym),
|
||||||
|
(xrm - rx/2, y0),
|
||||||
|
(xrl, ym + ry/2)
|
||||||
|
)
|
||||||
|
draw.bezier(
|
||||||
|
(),
|
||||||
|
(xrm, y1),
|
||||||
|
(xrl, ym - ry/2),
|
||||||
|
(xrm - rx/2, y1)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
draw.content(
|
draw.content(
|
||||||
((x-left + x-right - rx) / 2, y0 - ry),
|
((xlm + xrl) / 2, ym),
|
||||||
p.display-name,
|
p.display-name,
|
||||||
anchor: "mid"
|
anchor: "mid"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#let get-size(par) = {
|
#let get-size(par) = {
|
||||||
let m = normalize-measure(par.display-name)
|
let m = normalize-measure(box(
|
||||||
|
par.display-name,
|
||||||
|
inset: par.resolved-style.inset
|
||||||
|
))
|
||||||
|
|
||||||
// w + QUEUE-PAD.last() * 2 + 3 * (h + QUEUE-PAD.first() * 2) / 4
|
let rx = m.height / 4
|
||||||
// h + QUEUE-PAD.first() * 2
|
|
||||||
|
|
||||||
return m
|
return (
|
||||||
|
width: m.width + 3 * rx,
|
||||||
|
height: m.height
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#let default-style = (
|
#let default-style = (
|
||||||
:
|
inset: (x: 3pt, y: 5pt)
|
||||||
)
|
)
|
Reference in New Issue
Block a user