From ffdffc9e410df8465cca53b393332038b066ecd3 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sat, 19 Jul 2025 17:29:52 +0200 Subject: [PATCH] adapted custom shape rendering --- src/core/draw/participant/custom.typ | 35 +++++++++++++++++---------- src/core/draw/participant/default.typ | 6 +---- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/core/draw/participant/custom.typ b/src/core/draw/participant/custom.typ index 48344cb..c46c1c9 100644 --- a/src/core/draw/participant/custom.typ +++ b/src/core/draw/participant/custom.typ @@ -1,32 +1,41 @@ #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": * #let name = "custom" #let render(x, y, p, bottom) = { - let m = measure(p.display-name) let style = p.resolved-style - let image-m = measure(style.custom-image) - let y0 = if bottom {y - m.height / 1pt - SYM-GAP} else {y + m.height / 1pt + image-m.height / 1pt + SYM-GAP} - draw.content((x - image-m.width / 2pt, y0), style.custom-image, anchor: "north-west") + let shape = align( + center, + stack( + dir: ttb, + spacing: normalize-units(style.spacing) * 1pt, + style.image, + p.display-name + ) + ) + let anchor = if bottom {"north"} else {"base"} draw.content( (x, y), - p.display-name, - anchor: if bottom {"north"} else {"base"} + shape, + anchor: anchor ) } #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 - // measure(style.custom-image).height + SYM-GAP * 1pt + h - - return m + return ( + width: calc.max(name-m.width, img-m.width), + height: name-m.height + spacing + img-m.height + ) } #let default-style = ( - : + image: none, + spacing: 5pt ) \ No newline at end of file diff --git a/src/core/draw/participant/default.typ b/src/core/draw/participant/default.typ index 2025bf9..4394178 100644 --- a/src/core/draw/participant/default.typ +++ b/src/core/draw/participant/default.typ @@ -13,11 +13,7 @@ fill: style.fill, stroke: style.stroke ) - let anchor = if bottom { - "north" - } else { - "base" - } + let anchor = if bottom {"north"} else {"base"} draw.content( (x, y), name,