Skip to main content

Module render

Module render 

Source
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 whichever Renderer backend 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 its Align2).
path 🔒
pin 🔒
port 🔒
route 🔒
selection 🔒
text 🔒
text_box
Drawing and geometry for free-floating Text annotations. box_rect is shared between the boundary drawing here and the shape’s gui_rect hit-test in widget.

Structs§

BlockPaint
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).
RenderedPath
TagSlot
Shared tag-rect computation used by both block pins and ports. left/right are the shape’s edge x-coordinates; line_y the stub’s y.

Enums§

LabelPass
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.
RenderSegment
RouteRenderMode

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 than NEW_PIN_INACTIVE_SCALE to 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 offset so its text of width text_width stays within the block’s horizontal extent, given the label’s horizontal anchor — Align::Center for 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 width text_width stays 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 width text_width stays 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 asset stretched to fill bbox. 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_labels would 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::LockedHintIcon so 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, else PinStem), its name, and its tag.
draw_pin_labels
Draw a pin/port’s name (centered on pos, in pin_font) and type_label (centered one grid below, in the smaller pin_subtitle_font). h_align is 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 — see pin_stub_endpoints) out to tip, 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. When mode is 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/right are the shape’s edge x-coordinates, side the side the label hangs off, and line_y the stub’s y. Only drawn when the tag is shown; an empty hidden tag stays invisible.
estimate_bbox_for_pin_name
pin_name_rect_at for a block pin given its side/offset.
estimate_bbox_for_pin_stub
Hit region for a pin/port stub (the red line): the stub segment, widened to +/- GRID_SIZE / 3 vertically so it presents an easy click target. left/right are the shape’s edge x-coordinates; line_y the stub’s y.
estimate_bbox_for_pin_type
pin_type_rect_at for a block pin given its side/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 in name; 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 LabelSide a block label snaps to when its anchor is dragged to y: 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 one GRID_SIZE below — nudged up by TYPE_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 as draw_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 tag label, which sits above the stub line hugging the shape edge: right-justified on the West side, left-justified on the East side (opposite to how name is justified). left/right are the shape’s edge x-coordinates (the inner end of the stub); line_y is 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 at at, oriented along the wire there. An unnamed route shows the faint “add name” prompt (mirroring the pin placeholder); a named one shows the name in color.
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 pos grabs on a selection framing bbox.
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 under mode: the wire’s accent when set, else the mode’s resting or highlight color.