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