forked from HEL/circuiteria
feat: Add port-name-padding parameter
Replaces the hard-coded 2pt padding used when placing port name labels. Configurable per element via port-name-padding on elmt (forwarded by block and group), defaulting to 2pt to preserve existing layout.
This commit is contained in:
1 parent
0d1478c765
commit
563bb7b1d2
8 files changed
+6952
-6733
No files matched your search
@@ -196,6 +196,7 @@ element.group(
|
||||
fill: util.colors.blue.lighten(60%),
|
||||
padding: 2em,
|
||||
outside-port-names: true,
|
||||
port-name-padding: 4pt,
|
||||
ports: (
|
||||
west: ((id: "in", name: "D"),),
|
||||
east: ((id: "out", name: "Q"),),
|
||||
@@ -209,12 +210,14 @@ wire.wire("wG1in", ("g1-port-in", "b1-port-d"), directed: true)
|
||||
wire.wire("wG1out", ("b1-port-q", "g1-port-out"), directed: true)
|
||||
|
||||
// outside-port-names: false — labels inside the border (block style)
|
||||
// with extra padding via port-name-padding
|
||||
element.group(
|
||||
id: "g2", name: "inside",
|
||||
stroke: (dash: "dashed"),
|
||||
fill: util.colors.orange.lighten(60%),
|
||||
padding: 2em,
|
||||
outside-port-names: false,
|
||||
port-name-padding: 0.4em,
|
||||
ports: (
|
||||
west: ((id: "in", name: "D"),),
|
||||
east: ((id: "out", name: "Q"),),
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
@@ -6,7 +6,7 @@
|
||||
#set page(width: auto, height: auto, margin: .5cm)
|
||||
|
||||
#circuit({
|
||||
// --- Group with port labels OUTSIDE (default) ---
|
||||
// --- Group with port labels INSIDE (outside-port-names: false) ---
|
||||
element.group(
|
||||
id: "cpu",
|
||||
name: "CPU (labels outside)",
|
||||
@@ -14,6 +14,7 @@
|
||||
stroke: (dash: "dashed"),
|
||||
fill: util.colors.yellow.lighten(60%),
|
||||
padding: 1em,
|
||||
port-name-padding: .5em,
|
||||
outside-port-names: true,
|
||||
ports: (
|
||||
west: (
|
||||
@@ -51,6 +52,7 @@
|
||||
fill: util.colors.yellow.lighten(60%),
|
||||
padding: 4em,
|
||||
outside-port-names: false,
|
||||
port-name-padding: 0.5em,
|
||||
ports: (
|
||||
west: (
|
||||
(id: "in1", name: "D1"),
|
||||
|
||||
+6933
-6730
File diff suppressed because it is too large.
Load diff
@@ -27,6 +27,7 @@
|
||||
name-anchor: "center",
|
||||
ports: (),
|
||||
ports-margins: (),
|
||||
port-name-padding: 2pt,
|
||||
fill: none,
|
||||
radius: 0.5em,
|
||||
stroke: black + 1pt,
|
||||
@@ -44,6 +45,7 @@
|
||||
name-anchor: name-anchor,
|
||||
ports: ports,
|
||||
ports-margins: ports-margins,
|
||||
port-name-padding: port-name-padding,
|
||||
fill: fill,
|
||||
stroke: stroke,
|
||||
id: id,
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
/// - `clock` (`bool`): Whether it is a clock port (triangle symbol)
|
||||
/// - `vertical` (`bool`): Whether the name should be drawn vertically
|
||||
/// - ports-margins (dictionary): Dictionary of ports margins (used with automatic port placement). They keys are cardinal directions ("north", "east", "south", "west"). The values are tuples of (`<start>`, `<end>`) margins (numbers)
|
||||
/// - port-name-padding (number, length): Padding between the port name label and the port anchor point (default `2pt`)
|
||||
/// - fill (none, color): Fill color
|
||||
/// - stroke (stroke): Border stroke
|
||||
/// - id (str): The block id (for future reference)
|
||||
@@ -56,6 +57,7 @@
|
||||
name-anchor: "center",
|
||||
ports: (:),
|
||||
ports-margins: (:),
|
||||
port-name-padding: 2pt,
|
||||
fill: none,
|
||||
stroke: black + 1pt,
|
||||
id: "",
|
||||
@@ -140,7 +142,8 @@
|
||||
tl, tr, br, bl,
|
||||
ports,
|
||||
ports-margins,
|
||||
debug: debug.ports
|
||||
debug: debug.ports,
|
||||
name-padding: port-name-padding,
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -25,6 +25,7 @@
|
||||
/// - ports (dictionary): see #doc-ref("element.elmt")
|
||||
/// - ports-margins (dictionary): see #doc-ref("element.elmt")
|
||||
/// - outside-port-names (bool): If `true` (default), port name labels are drawn outside the group border so they do not overlap child elements. Set to `false` to draw labels inside, matching the block behaviour
|
||||
/// - port-name-padding (number, length): Padding between the port name label and the group border (default `2pt`). Accepts anything CeTZ accepts as `padding` (number or length)
|
||||
/// - debug (dictionary): see #doc-ref("element.elmt")
|
||||
#let group(
|
||||
body,
|
||||
@@ -38,6 +39,7 @@
|
||||
ports: (:),
|
||||
ports-margins: (:),
|
||||
outside-port-names: true,
|
||||
port-name-padding: 2pt,
|
||||
debug: (
|
||||
ports: false
|
||||
)
|
||||
@@ -95,6 +97,7 @@
|
||||
ports-margins,
|
||||
debug: debug.ports,
|
||||
outside-name: outside-port-names,
|
||||
name-padding: port-name-padding,
|
||||
)
|
||||
|
||||
if name != none {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
next: none,
|
||||
debug: false,
|
||||
outside-name: false,
|
||||
name-padding: 2pt,
|
||||
) = {
|
||||
let name = port.at("name", default: "")
|
||||
let name-rotate = port.at("vertical", default: false)
|
||||
@@ -43,7 +44,7 @@
|
||||
draw.content(
|
||||
pos,
|
||||
anchor: name-anchor,
|
||||
padding: 2pt,
|
||||
padding: name-padding,
|
||||
angle: if name-rotate {90deg} else {0deg},
|
||||
name
|
||||
)
|
||||
@@ -75,6 +76,7 @@
|
||||
ports-margins,
|
||||
debug: false,
|
||||
outside-name: false,
|
||||
name-padding: 2pt,
|
||||
) = {
|
||||
let sides = (
|
||||
"north": (tl, tr),
|
||||
@@ -125,6 +127,7 @@
|
||||
next: pos-next,
|
||||
debug: debug,
|
||||
outside-name: outside-name,
|
||||
name-padding: name-padding,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user