Expand description
Drawing of data-model elements onto a Renderer
canvas. Each function takes an element (or its geometry) plus a
Style drawing surface and paints it; the functions
are generic over the renderer backend so the same code drives both the
on-screen painter and the SVG exporter. widget/tools own interaction
and frame orchestration and delegate the actual painting here.
Modules§
- block 🔒
- bounds
- Coarse, Painter-free world-space bounds for broad-phase spatial queries.
- hit_
test 🔒 - Bounding-box estimators for hit-testing pin/port labels and stubs. These
mirror the geometry the drawing primitives use, but return the rect rather
than painting — driving click/drag/marquee targets in
widget. They measure text through whicheverRendererbackend the caller holds, so a hit test is exercisable without an egui context. - image 🔒
- layout 🔒
- Pure position/alignment helpers shared by the drawing primitives and by the
hit-testing in
widget. No drawing happens here — each function maps an element’s geometry to a label anchor (and itsAlign2). - path 🔒
- pin 🔒
- port 🔒
- route 🔒
- selection 🔒
- text 🔒
- text_
box - Drawing and geometry for free-floating
Textannotations.box_rectis shared between the boundary drawing here and the shape’sgui_recthit-test inwidget.
Structs§
- Block
Paint - What a block’s body is painted from beyond its rect: the accent it strokes with, whether its interface is frozen, and whether it opens a scope.
- Course
- Where a wire is drawn: its solved geometry, and the hops it makes over the
wires it crosses. The hops depend on the wires around it, so the caller
computes them over what it draws (
crate::widget::drawing::Drawing::hops). - PinExtent
- Bounding box of a whole pin as drawn — its stub plus the name and tag labels
— at the given
side/offset. Tools frame selected pins with this so the idle selection rectangle and the drag preview enclose the same parts and the frame doesn’t change shape when a drag begins. - PinPaint
- One pin’s per-draw adjustments: the drag shift, a forced side, and the resolved stub accent (derived from route roles, never stored on the pin).
- Rendered
Path - TagSlot
- Shared tag-rect computation used by both block pins and ports.
left/rightare the shape’s edge x-coordinates;line_ythe stub’s y.
Enums§
- Label
Pass - Which of its labels a route render includes. A tool that draws a label itself — dragged, or under an in-place editor — leaves that one out.
- Render
Segment - Route
Render Mode
Constants§
- ADD_
NAME_ PLACEHOLDER - Placeholder text shown faint at an empty editor or label slot to prompt input.
The pin name/type prompts also appear as a faint static overlay when the pin’s
shape is selected (see
draw_label_placeholders). - ADD_
ROUTE_ LABEL_ PLACEHOLDER - ADD_
TAG_ PLACEHOLDER - Short prompt for the compact tag editors (pin tag, block tag).
- ADD_
TEXT_ PLACEHOLDER - ADD_
TITLE_ PLACEHOLDER - ADD_
TYPE_ PLACEHOLDER - HANDLE_
GRAB - How near its corner a press grabs a resize handle: twice the radius the handle draws at, on every resizable shape.
- HANDLE_
RADIUS - The radius a grown resize handle draws at, and the armed one.
- NEW_
PIN_ ANIM_ TIME - Grow time for a handle’s activation transition.
- NEW_
PIN_ GROW_ RANGE - How near the cursor must be for a marker to grow into the full control. The resize tool activates on the resting-dot range; the route tool grows the control only this close so the dot reads as a target before it arms.
- NEW_
PIN_ INACTIVE_ SCALE - Resting dot radius as a fraction of
PORT_RADIUS(a small, unobtrusive marker). - RESIZE_
INACTIVE_ SCALE - Resting size of a resize handle, as a fraction of
HANDLE_RADIUS. A corner handle is a coarser target than a route/new-pin anchor, so it rests 30% larger thanNEW_PIN_INACTIVE_SCALEto stay easy to spot and grab. - SHEET_
INSET - How far inside its outline the second line of a scope-opening block runs. A quarter cell reads as its own line at a glance yet stays outboard of everything the block draws inside itself — the pin names start half a cell in, the size readout half a cell in from the left.
Functions§
- block_
title_ position - block_
type_ position - clamp_
label_ offset - Clamp a block label’s horizontal
offsetso its text of widthtext_widthstays within the block’s horizontal extent, given the label’s horizontal anchor —Align::Centerfor the title,Align::Min(left) for the type,Align::Max(right) for the tag. When the text is wider than the block the label is pinned flush to its anchored edge. - clamped_
block_ title_ position - Like
block_title_position, but clamps the horizontal offset so a title of widthtext_widthstays within the block (pinning flush when wider). Used at draw time so a later resize can’t leave a stale offset drawing outside the block. - clamped_
block_ type_ position - Like
block_type_position, but clamps the horizontal offset so a type label of widthtext_widthstays within the block (pinning flush when wider). Used at draw time so a later resize can’t leave a stale offset drawing outside. - draw_
block_ boundary - A block’s stroked boundary: its outline, plus — for a block that opens a scope — a second line inset within it, the classical contains-a-sheet notation. Every mode that draws a block body draws it through here, so the inset rides whatever stroke and fill that mode chose.
- draw_
block_ frame - Draw a block’s body: the outline fill, then the title. Drawn before the block’s pins and labels so its opaque fill sits under them, never over them. The type label is left to the caller (it is block-only; ports/areas that share this frame have no type).
- draw_
block_ image - Draw
assetstretched to fillbbox. The image’s intrinsic aspect ratio is not preserved — the box is resized freely by its corners. The painter resolves and caches the image; an asset the document does not hold (None, which the zero icon’s null hash also reads as) or one that fails to parse draws nothing. - draw_
block_ title - draw_
block_ type - draw_
block_ type_ placeholder - Faint “Add type” prompt at a block’s empty type slot. Like the tag placeholder, but suppressed on a locked block (whose type isn’t editable) — the caller gates that.
- draw_
box_ outline - draw_
label_ placeholders - Draw faint “Add Name”/“Add Type” prompts at a pin’s empty label slots, in the
same positions
draw_pin_labelswould use. Called only while the pin’s shape is selected, so the user sees where to double-click to add a label. - draw_
lock_ hint - Draw the padlock hint in a selected locked block’s upper-right corner: a
passive sign that the block is locked, not a button. Renders the lock action
icon’s SVG tinted to
Role::LockedHintIconso it reads as dim and stays identical to the overlay lock button. Sits clear of the top-right resize handle and is skipped when the block is too small to hold it without crowding. - draw_
pin - Draw a pin: its stub (in
paint.accent, elsePinStem), itsname, and itstag. - draw_
pin_ labels - Draw a pin/port’s
name(centered onpos, inpin_font) andtype_label(centered one grid below, in the smallerpin_subtitle_font).h_alignis the horizontal alignment (RIGHT for East, LEFT for West, CENTER for ports). Empty labels draw nothing. - draw_
pin_ placeholders - Draw the faint “Add Name”/“Add Type”/“+tag” prompts for one block pin’s empty label slots — used by the selected-block render so empty fields are discoverable. The “+tag” prompt is only drawn for a shown (not hidden) tag.
- draw_
pin_ stub - Draw a pin/port stub from
edge(the outline’s outer face — seepin_stub_endpoints) out totip, with an arrowhead flush against the shape so input and output pins read symmetrically: - draw_
port - draw_
port_ outline - Draws a pentagon whose point faces the direction of
side(East or West). - draw_
refused_ conflict - A conflict a move would create, hatched over the cells the two shapes would share. Only the overlaps that refuse the move are drawn: on a group move an overlap the selection already had refuses nothing, and marking it would claim a refusal that is not happening.
- draw_
selection_ frame - Draw the four corner resize handles for
bbox. Each handle rests as a small dot and grows into the full handle as the pointer approaches, exactly like the route/new-pin anchor targets. Whenmodeis set, that corner is being resized and draws armed (an inverted filled disk) as click-success feedback. - draw_
size_ readout - Draw a block’s size in grid cells inside its upper-left corner, where the pin gutter above the first slot leaves the one interior region no label occupies. Shown only while the block is being resized, on the rect the drop will commit. Returns the drawn extent.
- draw_
standing_ conflict - A conflict the document already holds. Nothing refuses one — a paste has no overlap check, and the group rule exempts what a selection arrived with — but two shapes sharing cells is a routing fault the router has to work around, so it is marked until it is cleared.
- draw_
tag_ placeholder - Draw the faint “+tag” prompt where an empty (but shown) pin/port tag would
sit — outboard over the stub, placed by
pin_tag_location.left/rightare the shape’s edge x-coordinates,sidethe side the label hangs off, andline_ythe stub’s y. Only drawn when the tag is shown; an empty hidden tag stays invisible. - estimate_
bbox_ for_ pin_ name pin_name_rect_atfor a block pin given itsside/offset.- estimate_
bbox_ for_ pin_ stub - Hit region for a pin/port stub (the red line): the stub segment, widened to
+/-
GRID_SIZE / 3vertically so it presents an easy click target.left/rightare the shape’s edge x-coordinates;line_ythe stub’s y. - estimate_
bbox_ for_ pin_ type pin_type_rect_atfor a block pin given itsside/offset.- first_
line - A pin/port label’s first line. Name and type are single-line, but a
document may carry a trailing
\n-separated line inname; this drops it. - horizontal_
label_ anchor - World-space anchor where a horizontal route label is drawn (its bottom center, nudged up off the wire). Shared with the in-place editor so it can sit exactly over the text it replaces.
- label_
side_ for_ y - The
LabelSidea block label snaps to when its anchor is dragged toy: the top third of the block is Top, the bottom third Bottom, the middle Center. Shared by the live drag preview and the drag-commit so both agree. - pin_
label_ anchors - The two draw anchors for a pin’s labels, both vertically centered: the
name on
pos(the pin’s stub), and the type oneGRID_SIZEbelow — nudged up byTYPE_SHIM_Y. Content-independent, so the render, placeholder, and hit-test paths place both lines identically. Returns(name_pos, type_pos). - pin_
name_ rect_ at - Rect of a pin’s name line at world anchor
pos/h_align, positioned exactly asdraw_pin_labels(centered on the stub). An empty name is sized to the “Add Name” placeholder so the slot stays a click/placeholder target while the shape is selected. - pin_
tag_ location - Position and alignment for the
taglabel, which sits above the stub line hugging the shape edge: right-justified on the West side, left-justified on the East side (opposite to hownameis justified).left/rightare the shape’s edge x-coordinates (the inner end of the stub);line_yis the stub’s y. - pin_
text_ location - pin_
type_ rect_ at - Rect of a pin’s type line — the sibling of
pin_name_rect_at, measured in the smaller subtitle font and placed just below the name. - port_
text_ center - render_
path_ with_ chamfered_ corners - render_
pins_ with_ box - render_
route - render_
route_ label_ at - Draw one of
route’s labels atat, oriented along the wire there. An unnamed route shows the faint “add name” prompt (mirroring the pin placeholder); a named one shows the name incolor. - render_
text_ anchors - Draw a route’s text-anchor diamonds (the spots a new label can attach).
- render_
waypoint_ handles - Draw waypoint handles: a user-pinned (locked) corner prominently, a structural bend the router laid down faint and small.
- resize_
handle_ at - The handle a press at
posgrabs on a selection framingbbox. - resize_
handles - The four corner handles of a selection framing
bbox, each with the resize it starts. - route_
text_ color - The color
route’s label text takes undermode: the wire’s accent when set, else the mode’s resting or highlight color.