Expand description
What a WebAssembly workbench and printCAD say to each other.
The component interface (wit/workbench.wit) carries these types as
JSON text; this crate is their one definition, used by the host
(wb_wasm) and by the guest SDK. Ids (features, bodies) travel as
UUID strings, lengths in millimetres, angles in degrees unless a field
says otherwise, and every position is in world space.
§Versions
The crate’s major and minor version are the contract’s: 0.1.x speaks
printcad:workbench@0.1. A patch release only adds, so a package
written against an earlier 0.1.x keeps building and running:
- Enums the host sends and a package matches on (
Event,PanelEvent,MenuScope,PanelSlot,Button) are#[non_exhaustive], as arekernel_api’sFaceSurfaceandProfileSegment: a match on them needs a wildcard arm, so a new variant does not break it, and binds a variant’s fields with.., so a new field does not either. (Theexhaustivefeature lifts this for printCAD itself, which makes every variant it sends; a package leaves it off.) - Structs a package fills in derive
Default; fill them with..Default::default()and a new field does not break the literal. - Struct-like variants a package builds (
Widget,Request,Cell,DiagramShape,MarkKind,Plan, andkernel_api’sSolidOpand the enums inside it) never gain a field within a minor version: a new option comes as a new variant, or as a new struct that derivesDefault. - A field added to a struct carries
#[serde(default)], so what an earlier package sends still reads.
A new minor version (0.2) is a new contract, which a host of 0.1 does not load.
Re-exports§
pub use kernel_api;
Modules§
- calls
- panel
- The document commands a bench calls through
host.call. Each is an ordinary recorded edit: one undo step per gesture, sent to peers. Functions building a declared panel’s blocks: layout, fields, words and colours, each a block with the common settings filled in and the rest at its default. The SDK re-exports them beside its section and item-list builders; printCAD’s own panels use them too.
Structs§
- Action
- Alert
- A
Widget::Alert: a note asWidget::Notedraws it; with anid, a click on it comes back asPanelEvent::Button. - Badge
- A glyph badge at an item’s end: a constraint on an element. A click
comes back as
PanelEvent::Badge. - Bind
- A number field’s parameter: feature
feature’s parameterkey. - Body
- Body
History - Callout
- A note of a
Widget::Diagrampointing at a feature of it: a dot atanchor, a leader toat, andtextthere. - Capabilities
- What a package asks to reach beyond itself. The user grants each.
- Caption
- A
Widget::Caption: words in the panel’s text size, or the small one, in a tone (Neutralis the panel’s secondary text,Muteddimmer still), or in the primary text colour. - Card
- A
Widget::Card: a raised card, its icon and title on the first line, then its children. - Cells
- A
Widget::Cells:childrenin rows ofcolumnscells, left to right, each column as wide as its widest cell; rows sit close and columns a little apart. Column titles as strong captions, then a caption per reading, make a table that reads as the panel’s text. - Check
- A
Widget::Check:textbeside its box, in its section’s label column underlabelwhen that is not empty. Told asPanelEvent::Toggle. - Color
Field - A
Widget::Color: a button showingcolorthat opens the system’s colour picker; each change isPanelEvent::Color. - Command
- Cosmetic
Thread - A thread drawn on a round face, never modelled: the face keeps its
size (a bore its tap drill, a shank its major diameter) and a helix of
the thread’s pitch is drawn just off it, inside a bore and outside a
shank, in every bench and never exported. A thread with a
designationis also named where the app lists threads: a callout at the face’s end, the parts list, and a STEP export’s callouts. - Dimension
- A measure of a
Widget::Diagram: the distance fromfromtoto, drawn as a dimension lineoffsetaway from them (to the left of the way fromfromtoto; negative for the right), its ends led out to the points, withtexton it. - Edge
Circle - A circular edge’s centre and axis (world space) and radius, mm.
- EdgeRef
- Entry
- A
Widget::Entry: told once typing ends (PanelEvent::Text). - Example
- A working use of a command.
- Face
Loops - What
geom.face_loopsanswers. - FaceRef
- Feature
Info - How a feature shows in the tree, the property panel and the hover card.
- Feature
Status - How a feature’s work stands: a setup run, an operation checked.
- Field
Grid - A
Widget::Grid: two columns, a field’s label in the first and its control in the second, the column as wide as the grid’s longest label. A widget with no label takes one cell, so two of them make a row. Rows sit close, or a little apart whenroomy. - Fields
- A
Widget::Fields: its fields’ labels in one column as wide as the longest, within the theme’s limits, apart from the section’s; orlabel_widthwide. - File
Kind - A kind of file a dialog offers: its label and extensions, without the dot.
- File
ToWrite - A file to write into the folder
Request::SaveFilesasks for: a plain file name, no folder in it. - Fill
- A
Widget::Fill. - Filter
Field - A
Widget::Filter: a search field narrowing the item lists that name it, by their label, secondary words and tags, and a kind selector whenkindsnames any (the first, “All” say, passes every item; the others pass items of thatkind). The host filters as the user types; withby_benchit leaves the lists whole and tells the bench (PanelEvent::Filter) instead. - Floating
Card - A card over the view, next to what it edits: a quick edit of a value
or two (a dimension, a corner’s size). Anything with more to it is a
task in the right panel. The host draws
widgetsas it draws a task panel’s, with OK and Cancel under them; Enter is OK and Escape Cancel. OK and Cancel reach the bench asPanelEvent::CardClose. Edits wait in the bench until OK: the host makes what OK writes one undo step, and takes back anything written while the card was open on Cancel. A click in the view elsewhere is OK, while OK is allowed. - Flow
- A
Widget::Flow: side by side, going on to the next line when the panel is narrow unlessno_wrap. AWidget::Fillamong them takes what the others leave. - Frame
- Everything a bench shows. The host keeps it and asks again only after
an event reached the bench, the document changed, the selection
changed, or the bench asked (
redraw); world-space drawing is projected by the host every frame, so the view moves freely without asking. - Gallery
- A
Widget::Gallery: small square pictures side by side, going on to the next line, each over its name; theselectedone ringed in the accent. A click isPanelEvent::Choicewith the tile’s place. - Gap
- A
Widget::Gap. - Hud
- Inline
- A
Widget::Inline. - Input
- Something the user did while the bench is active, with what was under the cursor.
- Item
- One row of a list: what an
ItemListholds, or alone as aWidget::Item. - Item
List - A
Widget::Items: rows a click selects (PanelEvent::Select), or withmultia click with Ctrl adds to (PanelEvent::Selection), a double click opens (PanelEvent::Activate); the pointer over one is told asPanelEvent::Hover, so the bench lights it in the view. - Kept
Mesh - A kept mesh as a frame draws it: its handle and how.
- Label
- List
Item - Loop
Edge - Manifest
bench.toml: what a package is and what it may reach.- Mark
- Menu
Item - Mesh
- A mesh drawn in the scene, never picked.
- Node
- A feature of the document as a bench sees it.
- Opened
File - A file the user picked to open: its name, without the folder, and its bytes.
- Panel
Action - A small icon button: in a section’s title, on its own
(
Widget::Action: a cross at a row’s end that takes it out), or an entry of an item’s menu (labelthen names it). A click comes back asPanelEvent::Button(a section’s or one on its own) orPanelEvent::ContextMenu(a menu’s) withid. - Panel
Section - A
Widget::Section: a fold the user opens and closes, its title in small capitals, the count of what it holds, a one-line summary while closed, icon actions at its right end, and its children, whose fields share one label column. - Param
- Parameter
- A number of a feature that a formula may set.
- Pick
Chip - A
Widget::PickChip: a click arms it (PanelEvent::Pick), its cross clears it (PanelEvent::Clear). - Picture
- A picture a panel shows, as rows of sRGB pixels with their alpha.
The host keeps it by
key, so a picture shown again under the same key is not sent to the screen again: a key names one picture. - Plot
- A
Widget::Plot: lines along a stripheightpoints tall, each series scaled to its own largest value, all on one x range from zero. - Plot
Series - A line of a
Plot: its points as[x, y], in its tone. - Pointer
- Where the cursor is and what it is over.
- Polyline
- A line through world points, drawn a constant
widthpixels wide over the scene. - Quantity
- A
Widget::Quantity: a number as aWidget::Numbersays it, with how it drags and how wide it is. Bound to a parameter (bind), it takes formulas as a boundNumberdoes. Changes come back asPanelEvent::Number; a stepper’s buttons as the value one up or down. - Range
- A
Widget::Range: a slider overmintomax, its value written beside it withdecimalsandsuffix(%); told asPanelEvent::Number. - Rebuild
- One body’s plan.
- Rebuild
Request - The bodies to rebuild, each with its features of this bench in history order.
- Region
- A flat region in world space: an outline and the holes in it, all on
one plane, filled and, with
hatch, hatched in lines that far apart. - Registration
- What a bench declares once, when it is loaded (
describe). - RowButton
- A
Widget::RowButton:textat the left of a frameless button the panel’s width, told asPanelEvent::Button. Thecurrentone (where what the panel moves stands) is in the accent, strong, and takes no click. - Section
- What
geom.sectionanswers. - Section
Curve - Section
Loop - Curves of a section end to end: closed round a solid’s cut, open where a sheet’s edge stops it.
- Select
- A
Widget::Select: one ofoptions, told asPanelEvent::Choice. - Selectable
- A
Widget::Selectable: words that light up whileselected, told asPanelEvent::Buttonwhen clicked; a few in aWidget::Flowpick one of them. - Settings
Group - A
Widget::Settings: under its overlinetitle(none when empty), a bordered group with one row per child, the child’s label at the left and its control at the right, a line between rows. AWidget::Hintedchild’s hint shows under its label; aWidget::Checkwith no label is a switch, itstextthe label. The Preferences search narrows the rows by label and hint. - Stack
- A
Widget::Stack: its children the panel’s spacing apart, or close together whentight, as a task’s lines of text and fields sit. - Status
- Status
Line - A
Widget::Status, and a task header’s state (TaskHeader). - Stepper
- A
Quantitydrawn as a stepper:text(the value when empty) between a down and an up button, each with its state and its words on hover. - Swatch
- A colour of a
Swatchesblock, as sRGB. - Swatches
- A
Widget::Swatches: small squares of colour, side by side and going on to the next line; a click isPanelEvent::Choicewith the swatch’s place. - Tag
- A small rounded name in an item’s row: an element a constraint ties.
A click comes back as
PanelEvent::Tag. - Task
- Task
Header - A
Widget::TaskHeader: in a task’s panel, the header above it showssubtitleunder the title andstatusas a pill beside it, as the app’s own tasks do; anywhere else they draw in the panel. - Tile
- A choice of a
Gallery: its picture over its name. - Toggle
Button - One button of
Toggles. - Toggles
- A
Widget::Toggles: icon buttons in a row under one label, each lit whileonand its words shown on hover, the way an editor shows its alignment and wrapping. A click comes back asPanelEvent::Buttonwith the button’sid; whether lighting one puts the others out is the bench’s to decide. - Tool
- Tool
Hint - TriMesh
- Triangular mesh generated from kernel bodies for viewports and export.
- Vertex
Ref - A vertex of a body’s solid, where it sits.
Enums§
- Button
- Button
Style - Cell
- A cell of a
Widget::Sheet. - Diagram
Shape - A shape of a
Widget::Diagram, in its coordinates. - Diagram
Stroke - A line of a
Widget::Diagram: what it stands for, not its colour, so the host draws it in the design’s own. - Dim
- Event
- Feature
State - GapSize
- How much room a
Widget::Gapleaves. - Mark
Kind - What a
Markdraws. - Menu
Scope - Note
Kind - Panel
Event - What the user did to a panel widget, by the widget’s id.
- Panel
Slot - Which declared panel an event came from.
- Param
Kind - Plan
- What a
Rebuildasks of the kernel. - Request
- Something a bench asks the host to do once its call returns.
- SolidOp
- One step in a body’s build history. Shape-producing steps (
Sweep,Loft,Pipe,Primitive) carry aBooleanOp; the remaining steps modify or combine the running solid directly. - Tone
- How a mark, a tag or a status reads: what it means, not its colour.
- Tool
Behavior - Widget
- One element of a declared panel. The host draws it with the app’s
widgets and sends back a
PanelEventwhen the user changes it.
Constants§
- API_
VERSION - The version of this contract, as a package’s manifest names it in
api. A host loads packages of its own major version. - CONTRACT_
VERSION - The full version of the contract this build speaks, patch included:
what a manifest’s
min_contractis held against. - WIT
- The component interface: the WIT world
workbenchof packageprintcad:workbench, whose values cross as JSON of this crate’s types.
Functions§
- api_
compatible - Whether a package built against
apiruns on this host. - contract_
satisfies - Whether this build’s contract is at least
min, a version such as0.1.4(aprintcad:workbench@prefix is read past). Only the numbers it names count, so0.1asks for any 0.1.x. - retain_
widgets widgetskeeping only thosekeepholds to, at any depth: a widget left out goes with what it holds. A widget held alone (a hint’s, a fill’s) stays whateverkeepsays of it.- walk_
widgets - Every widget of
widgets, at any depth, each before its children.
Type Aliases§
- Rgb
- Linear RGB in 0..=1.