Skip to main content

teksilo_preview_ui/
lib.rs

1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! GUI for Teksilo's widget previewer.
5//!
6//! This crate is a *library*. Per-application binaries
7//! (`teksilo-widgets-previewer`, `<app>-previewer`) call
8//! [`run_previewer`] from their `main`, linking against this crate
9//! plus `teksilo-preview` plus their own widget set with the `preview`
10//! feature enabled. Each binary's `inventory` link graph determines
11//! which widgets the previewer surfaces.
12
13mod app_state;
14mod canvas;
15mod cli;
16mod doc_export;
17mod inspector;
18mod knob_form;
19mod navigator;
20mod png_export;
21mod shot;
22mod toolbar;
23#[cfg(test)]
24mod touch_tests;
25
26pub use cli::{PreviewerArgs, PreviewerOptions};
27pub use doc_export::{
28    DocExportOptions, DocExportReport, SubjectOutcome, export_doc_images, print_report,
29};
30
31use teksilo_app::{TeksiloAppBuilder, ThemeMode};
32use teksilo_core::WindowConfig;
33
34/// Launch the previewer window with the given options. Blocks until
35/// the window is closed.
36pub fn run_previewer(opts: PreviewerOptions) {
37    let title = opts.window_title.clone();
38    let initial_size = opts.window_size;
39    let initial_widget = opts.initial_widget.clone();
40    let initial_variant = opts.initial_variant.clone();
41
42    // Resolve the initial theme from the OS desktop palette. This
43    // matches the toolbar's default `CanvasTheme::Native` selection
44    // so the chrome (which `ctx.set_theme` reskins app-wide) and the
45    // toolbar's highlighted button agree on frame 1. We use
46    // `ThemeMode::Manual` here rather than `ThemeMode::Native` /
47    // `ThemeMode::FollowSystem` because the toolbar's pickers later
48    // call `ctx.set_theme(...)` directly — those builder-time modes
49    // would override on the next OS event and fight the user's
50    // explicit choice.
51    let initial_canvas_theme = crate::app_state::CanvasTheme::Native;
52    let initial_density = opts.density;
53    TeksiloAppBuilder::new()
54        .theme(initial_canvas_theme.theme_at(initial_density))
55        .theme_mode(ThemeMode::Manual)
56        .initial_window(
57            WindowConfig::new()
58                .title(title)
59                .size(initial_size.0, initial_size.1)
60                .root(move |tree, _state| {
61                    // The window's own tree is the one place an app can set a
62                    // density outright, so `--density` is applied here; the
63                    // toolbar's live switch has to go through a theme plus a
64                    // rebuild instead (see `crate::toolbar`).
65                    tree.set_input_density(initial_density);
66                    let root = crate::app_state::PreviewerRoot::new(
67                        initial_widget.clone(),
68                        initial_variant.clone(),
69                    )
70                    .with_density(initial_density);
71                    tree.add(root)
72                }),
73        )
74        .run();
75}