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);