Skip to main content

teksilo_preview/
lib.rs

1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! Trait + types + registry for Teksilo's widget previewer
5//! infrastructure.
6//!
7//! This crate is **framework-side, UI-free**: it defines the
8//! `WidgetCatalog` trait, the `KnobSpec` / `KnobValues` types, and the
9//! `inventory`-backed registry. The 3-pane previewer GUI lives in the
10//! sibling [`teksilo-preview-ui`](../teksilo_preview_ui/index.html) crate;
11//! per-application binaries (`teksilo-widgets-previewer`, etc.) link the
12//! two together along with their own widget set.
13//!
14//! # Authoring a catalog impl
15//!
16//! ```ignore
17//! use teksilo_preview::{
18//!     register_widget_catalog, KnobSpec, KnobValues, PreviewVariant,
19//!     KnobOverrides, WidgetCatalog,
20//! };
21//! use teksilo_core::widget::Widget;
22//! use my_widgets::Button;
23//!
24//! impl WidgetCatalog for Button {
25//!     fn id() -> &'static str { "button" }
26//!     fn group() -> &'static str { "Controls" }
27//!     fn display_name() -> &'static str { "Button" }
28//!     fn knobs() -> KnobSpec {
29//!         KnobSpec::new()
30//!             .text("label", "Label", "Click me")
31//!             .bool_("disabled", "Disabled", false)
32//!     }
33//!     fn variants() -> Vec<PreviewVariant> {
34//!         vec![
35//!             PreviewVariant::defaults("default"),
36//!             PreviewVariant::knobs("disabled",
37//!                 KnobOverrides::new().bool_("disabled", true)),
38//!         ]
39//!     }
40//!     fn build(_variant: &str, knobs: &KnobValues) -> Box<dyn Widget> {
41//!         let label = knobs.text("label").get();
42//!         Box::new(Button::new(label).enabled(!knobs.bool_("disabled").get()))
43//!     }
44//! }
45//! register_widget_catalog!(Button);
46//! ```
47
48mod builder_props;
49mod catalog;
50mod doc_snippet;
51mod knob;
52mod registry;
53mod source_loc;
54mod variant;
55
56pub use builder_props::builder_property_groups;
57pub use catalog::{CatalogEntry, SlottedChild, WidgetCatalog, WidgetCategory};
58pub use doc_snippet::{DocSnippet, iter_doc_snippets};
59pub use knob::{EnumInfo, KnobDecl, KnobKind, KnobOverrides, KnobSpec, KnobValue, KnobValues};
60pub use registry::{entries_by_group, find_by_file, find_by_id, iter_entries};
61pub use source_loc::SourceLoc;
62pub use teksilo_core::widget_id::WidgetId;
63pub use variant::{PreviewVariant, ScenarioBuilder};
64
65// Internal re-exports used by the `register_widget_catalog!` macro.
66// Hidden from the public API; exposed only because the macro must
67// reference these symbols through the crate path.
68#[doc(hidden)]
69pub mod __widget {
70    pub use teksilo_core::widget::Widget;
71}
72
73#[doc(hidden)]
74pub mod __widget_id {
75    pub use teksilo_core::widget_id::WidgetId;
76}
77
78#[doc(hidden)]
79pub use inventory as __inventory;