forked from HEL/circuiteria
		
	fixed extender ports + added align-out param
This commit is contained in:
		| @@ -1,14 +1,23 @@ | ||||
| #import "@preview/cetz:0.2.2": draw | ||||
| #import "element.typ" | ||||
| #import "ports.typ": add-port | ||||
|  | ||||
| #let draw-shape(id, tl, tr, br, bl, fill, stroke) = { | ||||
| #let draw-shape(id, tl, tr, br, bl, fill, stroke, h-ratio: 75%, align-out: true) = { | ||||
|   let (x, y) = bl | ||||
|   let (width, height) = (tr.at(0) - x, tr.at(1) - y) | ||||
|  | ||||
|   tl = (x, y + height * 0.75) | ||||
|   let tr2 = (x + width, y + height * 0.75) | ||||
|   let ratio = h-ratio / 100% | ||||
|  | ||||
|   tl = (x, y + height * ratio) | ||||
|   let tr2 = (x + width, y + height * ratio) | ||||
|   let br = (x + width, y) | ||||
|   (tr, tr2) = (tr2, tr) | ||||
|    | ||||
|   if align-out { | ||||
|     (tr, tr2) = (tr2, tr) | ||||
|   } else { | ||||
|     (tr, tr2) = (tr, tr) | ||||
|   } | ||||
|  | ||||
|   let f = draw.group(name: id, { | ||||
|     draw.merge-path( | ||||
|       inset: 0.5em, | ||||
| @@ -28,7 +37,9 @@ | ||||
| /// Draws a bit extender | ||||
| /// | ||||
| /// #examples.extender | ||||
| /// For parameters description, see #doc-ref("element.elmt") | ||||
| /// For other parameters description, see #doc-ref("element.elmt") | ||||
| /// - h-ratio (ratio): The height ratio of the left side relative to the full height | ||||
| /// - align-out (bool): If true, the output and input ports are aligned, otherwise, the output port is centered on the right side | ||||
| #let extender( | ||||
|   x: none, | ||||
|   y: none, | ||||
| @@ -39,6 +50,8 @@ | ||||
|   fill: none, | ||||
|   stroke: black + 1pt, | ||||
|   id: "", | ||||
|   h-ratio: 75%, | ||||
|   align-out: true, | ||||
|   debug: ( | ||||
|     ports: false | ||||
|   ) | ||||
| @@ -51,9 +64,14 @@ | ||||
|       (id: "out"), | ||||
|     ) | ||||
|   ) | ||||
|   let out-pct = if align-out {h-ratio / 2} else {50%} | ||||
|   let ports-y = ( | ||||
|     "in": (h) => {h - h * (h-ratio / 200%)}, | ||||
|     "out": (h) => {h * (out-pct / 100%)} | ||||
|   ) | ||||
|    | ||||
|   element.elmt( | ||||
|     draw-shape: draw-shape, | ||||
|     draw-shape: draw-shape.with(h-ratio: h-ratio, align-out: align-out), | ||||
|     x: x, | ||||
|     y: y, | ||||
|     w: w, | ||||
| @@ -61,9 +79,16 @@ | ||||
|     name: name, | ||||
|     name-anchor: name-anchor, | ||||
|     ports: ports, | ||||
|     auto-ports: false, | ||||
|     ports-y: ports-y, | ||||
|     fill: fill, | ||||
|     stroke: stroke, | ||||
|     id: id, | ||||
|     debug: debug | ||||
|   ) | ||||
|  | ||||
|   let in-pos = (rel: (0, h * (h-ratio / 200%)), to: id+".south-west") | ||||
|   let out-pos = (id+".south-east", out-pct, id+".north-east") | ||||
|   add-port(id, "west", ports.west.first(), in-pos) | ||||
|   add-port(id, "east", ports.east.first(), out-pos) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user