82 lines
1.8 KiB
Typst
Raw Normal View History

2024-05-16 23:35:53 +02:00
#import "@preview/cetz:0.2.2": draw
#import "element.typ"
#let draw-shape(id, tl, tr, br, bl, fill, stroke) = {
let f = draw.rect(
radius: 0.5em,
inset: 0.5em,
fill: fill,
stroke: stroke,
name: id,
bl, tr
)
return (f, tl, tr, br, bl)
}
2024-05-17 14:19:27 +02:00
/// Draws a block element
///
/// #box(width: 100%, align(center)[
/// #circuit({
/// element.block(
/// x: 0, y: 0,
/// w: 2, h: 2,
/// id: "block",
/// ports: (
/// north: ((id: "clk", clock: true),),
/// west: (
/// (id: "in1", name: "A"),
/// (id: "in2", name: "B"),
/// ),
/// east: (
/// (id: "out", name: "C"),
/// )
/// )
/// )
/// wire.stub("block-port-clk", "north")
/// wire.stub("block-port-in1", "west")
/// wire.stub("block-port-in2", "west")
/// wire.stub("block-port-out", "east")
/// })
/// ])
/// - x (number, dictionary): see `elmt()`
/// - y (number, dictionary): see `elmt()`
/// - w (number): see `elmt()`
/// - h (number): see `elmt()`
/// - name (none, str): see `elmt()`
/// - name-anchor (str): see `elmt()`
/// - ports: (dictionary): see `elmt()`
/// - ports-margins: (dictionary): see `elmt()`
/// - fill (none, color): see `elmt()`
/// - stroke (stroke): see `elmt()`
/// - id (str): see `elmt()`
/// - debug (dictionary): see `elmt()`
2024-05-16 23:35:53 +02:00
#let block(
x: none,
y: none,
w: none,
h: none,
name: none,
name-anchor: "center",
ports: (),
ports-margins: (),
fill: none,
stroke: black + 1pt,
id: "",
debug: (
ports: false
)
) = element.elmt(
draw-shape: draw-shape,
x: x,
y: y,
w: w,
h: h,
name: name,
name-anchor: name-anchor,
ports: ports,
ports-margins: ports-margins,
fill: fill,
stroke: stroke,
id: id,
debug: debug
)