Skip to main content

Crate teksilo_preview

Crate teksilo_preview 

Source
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 WidgetCatalog impl with the global inventory.
register_widget_catalog_at
Register a WidgetCatalog impl with an explicit source file path. Useful when several catalog impls live in a single shared preview_catalog.rs module — each call declares the source file that the user would open in their editor to find the widget itself, so that previewer --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.
EnumInfo
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.
KnobDecl
KnobOverrides
Variant override map: knob id → preset value. Built incrementally with KnobOverrides::new().bool_("disabled", true)… and supplied to PreviewVariant::knobs(...).
KnobSpec
Ordered list of knob declarations. Order is preserved by the inspector when rendering the form.
KnobValues
Runtime container of one Signal<T> per declared knob, populated from a KnobSpec and an optional set of variant overrides.
SlottedChild
One child handed to WidgetCatalog::build_with_children: a pre-registered widget id plus, for WidgetCategory::ContainerB parents, the name of the slot it fills (None for the ordered children of a WidgetCategory::ContainerA parent).
SourceLoc
WidgetId
Unique identifier for a widget in the arena.

Enums§

KnobKind
A typed knob declaration. Each kind maps 1:1 to a Signal<T> in KnobValues and to one row in the inspector’s auto-generated form.
KnobValue
Concrete value for a knob, used by PreviewVariant::Knobs to override the spec’s defaults for a specific named variant.
PreviewVariant
WidgetCategory
How a catalog widget accepts children. Drives the designer’s outline rendering and the runtime WidgetCatalog::build_with_children factory. Default is WidgetCategory::Leaf.

Traits§

CatalogEntry
Object-safe trait collected by inventory. Each implementor is a zero-sized shim generated by register_widget_catalog! that forwards to the corresponding WidgetCatalog impl.
WidgetCatalog
Static-method trait implemented by widget authors.

Functions§

builder_property_groups
The shared WidgetBuilder properties, 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 outer Vec is sorted by group name. The inner Vecs are sorted by display name.
find_by_file
Find an entry whose source().file matches path (suffix match — see crate::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§

ScenarioBuilder
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.