Expand description
Trait + types + registry for Teksilo’s widget previewer infrastructure.
This crate is framework-side, UI-free: it defines the
WidgetCatalog trait, the KnobSpec / KnobValues types, and the
inventory-backed registry. The 3-pane previewer GUI lives in the
sibling teksilo-preview-ui crate;
per-application binaries (teksilo-widgets-previewer, etc.) link the
two together along with their own widget set.
§Authoring a catalog impl
ⓘ
use teksilo_preview::{
register_widget_catalog, KnobSpec, KnobValues, PreviewVariant,
KnobOverrides, WidgetCatalog,
};
use teksilo_core::widget::Widget;
use my_widgets::Button;
impl WidgetCatalog for Button {
fn id() -> &'static str { "button" }
fn group() -> &'static str { "Controls" }
fn display_name() -> &'static str { "Button" }
fn knobs() -> KnobSpec {
KnobSpec::new()
.text("label", "Label", "Click me")
.bool_("disabled", "Disabled", false)
}
fn variants() -> Vec<PreviewVariant> {
vec![
PreviewVariant::defaults("default"),
PreviewVariant::knobs("disabled",
KnobOverrides::new().bool_("disabled", true)),
]
}
fn build(_variant: &str, knobs: &KnobValues) -> Box<dyn Widget> {
let label = knobs.text("label").get();
Box::new(Button::new(label).enabled(!knobs.bool_("disabled").get()))
}
}
register_widget_catalog!(Button);Macros§
- doc_
snippet - Register a documentation image subject for a widget source file.
- register_
widget_ catalog - Register a
WidgetCatalogimpl with the global inventory. - register_
widget_ catalog_ at - Register a
WidgetCatalogimpl with an explicit source file path. Useful when several catalog impls live in a single sharedpreview_catalog.rsmodule — each call declares the source file that the user would open in their editor to find the widget itself, so thatpreviewer --file=<that path>resolves to the right entry. The line value is set to 1 since the call site does not correspond to the widget’s own location.
Structs§
- DocSnippet
- One registered documentation image subject.
- Enum
Info - Resolved dropdown metadata for an enum-typed knob — the Rust enum path, its
variant idents (in declaration order), and the default’s index. Lets a
design tool render a dropdown and emit
enum_path::variant. - Knob
Decl - Knob
Overrides - Variant override map: knob id → preset value. Built incrementally
with
KnobOverrides::new().bool_("disabled", true)…and supplied toPreviewVariant::knobs(...). - Knob
Spec - Ordered list of knob declarations. Order is preserved by the inspector when rendering the form.
- Knob
Values - Runtime container of one
Signal<T>per declared knob, populated from aKnobSpecand an optional set of variant overrides. - Slotted
Child - One child handed to
WidgetCatalog::build_with_children: a pre-registered widget id plus, forWidgetCategory::ContainerBparents, the name of the slot it fills (Nonefor the ordered children of aWidgetCategory::ContainerAparent). - Source
Loc - Widget
Id - Unique identifier for a widget in the arena.
Enums§
- Knob
Kind - A typed knob declaration. Each kind maps 1:1 to a
Signal<T>inKnobValuesand to one row in the inspector’s auto-generated form. - Knob
Value - Concrete value for a knob, used by
PreviewVariant::Knobsto override the spec’s defaults for a specific named variant. - Preview
Variant - Widget
Category - How a catalog widget accepts children. Drives the designer’s outline
rendering and the runtime
WidgetCatalog::build_with_childrenfactory. Default isWidgetCategory::Leaf.
Traits§
- Catalog
Entry - Object-safe trait collected by
inventory. Each implementor is a zero-sized shim generated byregister_widget_catalog!that forwards to the correspondingWidgetCatalogimpl. - Widget
Catalog - Static-method trait implemented by widget authors.
Functions§
- builder_
property_ groups - The shared
WidgetBuilderproperties, grouped for a sectioned (ToolBox) presentation. Each entry is(group label, the group's knobs). - entries_
by_ group - Group entries by
group()and return them sorted within each group. The outerVecis sorted by group name. The innerVecs are sorted by display name. - find_
by_ file - Find an entry whose
source().filematchespath(suffix match — seecrate::source_loc::SourceLoc::matches_path). - find_
by_ id - Find an entry by its widget id (
Button::id()). - iter_
doc_ snippets - Iterate every documentation snippet registered into the current binary’s link graph.
- iter_
entries - Iterate over every catalog entry registered into the current binary’s link graph. Order is stable across runs but not lexicographic — sort callers if a particular ordering is required.
Type Aliases§
- Scenario
Builder - Builder fn used by
PreviewVariant::Scenario. Returns a freshly constructed widget instance — the previewer wraps it for layout and paint just like any other root child.