forked from HEL/circuiteria
feat: add pentagon-shaped ports
Add an optional pentagon shape for block and group ports, configured via the element-level `port-shape`, `port-kind` and `port-size` parameters. Individual ports can override them with `shape`, `kind`, `size`, `stroke` and `fill`. Clock ports with a pentagon shape drop the clock triangle and default to a gray fill. Wires attach to the outer end of the pentagon by default. With the new `shell` parameter on `element.elmt` they attach to the inner tip instead. Each port is exposed as a CeTZ group with a `default` anchor plus the cardinal sub-anchors `.east`, `.west`, `.north` and `.south` on the pentagon's bounding box, so wires can attach to any face. For non-pentagon ports the sub-anchors collapse to the default attach point, and the bare `<elmt-id>-port-<port-id>` anchor resolves as before. Add the `port-shape` and `port-shape-attach` examples and the `gallery/test_port_shape` gallery entry.
This commit is contained in:
1 parent
c14e2ceab9
commit
d9abaf4a53
9 files changed
+8247
-6732
No files matched your search
@@ -228,9 +228,64 @@ wire.stub("g2-port-in", "west")
|
||||
wire.stub("g2-port-out", "east")
|
||||
```, vertical: true)
|
||||
|
||||
#let port-shape = example(```
|
||||
// Block with pentagon-shaped ports.
|
||||
// - port-shape / port-kind / port-size are element-level defaults.
|
||||
// - Any port field (shape, kind, size, stroke, fill) overrides per port.
|
||||
// - kind: "in" → tip points into the block (default)
|
||||
// kind: "out" → tip points away from the block
|
||||
// - clock ports with shape: "pentagon" drop their triangle and default
|
||||
// to a gray fill.
|
||||
element.block(
|
||||
id: "b", w: 3, h: 3, x: 0, y: 0,
|
||||
fill: util.colors.yellow.lighten(60%),
|
||||
port-shape: "pentagon",
|
||||
port-size: 1em,
|
||||
ports: (
|
||||
// west: default input
|
||||
west: ((id: "in", name: "D"),),
|
||||
// east: output — tip points away
|
||||
east: ((id: "out", name: "Q", kind: "out"),),
|
||||
// north: clock port — pentagon replaces the triangle, gray fill
|
||||
north: ((id: "clk", name: "CLK", clock: true),),
|
||||
// south: styled output with per-port fill and stroke
|
||||
south: ((id: "rdy", name: "RDY", kind: "out",
|
||||
fill: util.colors.blue, stroke: red + 1.5pt),),
|
||||
),
|
||||
)
|
||||
// Wires connect at the outer end of each pentagon.
|
||||
wire.stub("b-port-in", "west")
|
||||
wire.stub("b-port-out", "east")
|
||||
wire.stub("b-port-clk", "north")
|
||||
wire.stub("b-port-rdy", "south")
|
||||
```)
|
||||
|
||||
#let intersection = example(```
|
||||
wire.wire("w1", ((0, 0), (1, 1)), style: "zigzag")
|
||||
wire.wire("w2", ((0, 0), (1, -.5)),
|
||||
style: "zigzag", zigzag-ratio: 80%)
|
||||
wire.intersection("w1.zig")
|
||||
```)
|
||||
|
||||
#let port-shape-attach = example(
|
||||
```
|
||||
// Pentagon ports expose `.east`, `.west`, `.north`,
|
||||
// `.south` sub-anchors on the pentagon boundary,
|
||||
// letting wires attach to any face.
|
||||
element.block(x: 0, y: 0, w: 2, h: 2, id: "a",
|
||||
port-shape: "pentagon",
|
||||
ports: (west: ((id: "p", name: "P"),),))
|
||||
draw.circle((-2, 0.5), radius: .05, name: "L")
|
||||
draw.circle(( 3, 1.5), radius: .05, name: "R")
|
||||
draw.circle((-1, 2.5), radius: .05, name: "T")
|
||||
// .west = outer flat base
|
||||
wire.wire("w1", ("L", "a-port-p.west"), style: "direct")
|
||||
// .east = tip inside the block
|
||||
wire.wire("w2", ("R", "a-port-p.east"),
|
||||
style: "direct", color: red)
|
||||
// .north = top edge midpoint
|
||||
wire.wire("w3", ("T", "a-port-p.north"),
|
||||
style: "direct", color: blue)
|
||||
```,
|
||||
vertical: true,
|
||||
)
|
||||
Reference in new issue
Block a user