adapted custom shape rendering
This commit is contained in:
		| @@ -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 | ||||
| ) | ||||
| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user