Skip to main content

tessera_components/
lib.rs

1//! Basic components for the Tessera UI framework.
2//!
3//! Built-in labels follow the language registered with the application entry.
4//!
5//! # Usage
6//!
7//! First, add the package (recommended) or render module provided by this crate
8//! at application entry.
9//!
10//! ```no_run
11//! use tessera_components::theme::{MaterialTheme, material_theme};
12//!
13//! #[tessera_ui::tessera]
14//! fn app() {
15//!     material_theme()
16//!         .theme(|| MaterialTheme::default())
17//!         .child(|| {
18//!             // Your app code here
19//!         });
20//! }
21//!
22//! use tessera_ui::EntryPoint;
23//!
24//! #[tessera_ui::entry]
25//! pub fn run() -> EntryPoint {
26//!     EntryPoint::new(app).package(tessera_components::ComponentsPackage)
27//! }
28//!
29//! fn main() {
30//!     let _ = run().run_desktop();
31//! }
32//! ```
33//!
34//! Then you can use the components in your UI.
35//!
36//! # Example
37//!
38//! ```
39//! # use tessera_ui::tessera;
40//! # #[tessera]
41//! # fn component() {
42//! use tessera_components::{button::button, text::text, text_input::text_input};
43//! # use tessera_components::theme::{MaterialTheme, material_theme};
44//! # material_theme()
45//! #     .theme(|| MaterialTheme::default())
46//! #     .child(|| {
47//!
48//! // Button example
49//! button().filled().on_click(|| {}).child(|| {
50//!     text("Click me");
51//! });
52//!
53//! // Text editor example
54//! text_input();
55//! #     });
56//! # }
57//! # tessera_ui::testing::layout_test(component).run();
58//! ```
59#![deny(
60    missing_docs,
61    clippy::unwrap_used,
62    rustdoc::broken_intra_doc_links,
63    rustdoc::invalid_rust_codeblocks,
64    rustdoc::invalid_html_tags
65)]
66// Resolving `Send`/`Sync` for the GPU handles stored by pipeline types recurses
67// deep enough inside `wgpu` to hit the solver's recursion limit. Raise the limit
68// so auto traits resolve without falling back to the depth guard.
69#![recursion_limit = "512"]
70
71mod animation;
72pub mod app_bar;
73pub mod badge;
74pub mod bottom_sheet;
75pub mod boxed;
76pub mod button;
77pub mod button_groups;
78pub mod card;
79pub mod carousel;
80pub mod checkbox;
81mod checkmark;
82pub mod chip;
83pub mod column;
84pub mod date_picker;
85pub mod dialog;
86pub mod divider;
87pub mod extended_floating_action_button;
88pub mod floating_action_button;
89pub mod floating_action_button_menu;
90pub mod flow_column;
91pub mod flow_row;
92pub mod fluid_glass;
93pub mod fluid_switch;
94pub mod fonts;
95pub mod glass_button;
96pub mod glass_progress;
97pub mod glass_slider;
98pub mod glass_switch;
99pub mod icon;
100pub mod icon_button;
101pub mod image;
102pub mod image_vector;
103pub mod interaction_state;
104mod layout_flex;
105pub mod lazy_grid;
106pub mod lazy_list;
107mod lazy_shared;
108pub mod lazy_staggered_grid;
109pub mod list_item;
110pub mod loading_indicator;
111pub mod material_icons;
112pub mod menus;
113mod modal_focus;
114pub mod modifier;
115pub mod navigation_bar;
116pub mod navigation_drawer;
117#[cfg(all(test, not(target_family = "wasm")))]
118mod navigation_focus_tests;
119pub mod navigation_rail;
120mod nested_scroll;
121mod overlay_semantics;
122mod padding_utils;
123pub mod pager;
124pub mod painter;
125pub mod pipelines;
126pub mod pos_misc;
127pub mod progress;
128pub mod pull_refresh;
129pub mod radio_button;
130pub mod res;
131pub mod ripple_state;
132pub mod row;
133pub mod scaffold;
134pub mod scrollable;
135pub mod search;
136pub mod segmented_buttons;
137pub mod shadow;
138pub mod side_sheet;
139pub mod slider;
140pub mod snackbar;
141pub mod spacer;
142pub mod split_buttons;
143pub mod surface;
144pub mod switch;
145pub mod tabs;
146pub mod text;
147mod text_edit_core;
148pub mod text_field;
149pub mod text_input;
150pub mod text_table;
151pub mod theme;
152pub mod time_picker;
153pub mod toolbar;
154pub mod tooltip;
155pub mod wavy_progress;
156
157#[cfg(test)]
158mod test_utils;
159
160use tessera_platform::PlatformPackage;
161use tessera_ui::{EntryRegistry, PipelineContext, RenderModule, TesseraPackage};
162
163pub use tessera_foundation::{alignment, shape_def};
164
165pub use pipelines::shape::command::RippleProps;
166pub use ripple_state::RippleState;
167
168/// Render module for registering all Tessera component pipelines.
169#[derive(Default, Clone, PartialEq, Copy)]
170struct TesseraComponents;
171
172impl RenderModule for TesseraComponents {
173    fn register_pipelines(&self, context: &mut PipelineContext<'_>) {
174        pipelines::register_pipelines(context);
175    }
176}
177
178/// Package that registers the components module and required platform services.
179#[derive(Clone, PartialEq, Default, Copy)]
180pub struct ComponentsPackage;
181
182impl ComponentsPackage {
183    /// Creates a package that registers components and required platform
184    /// plugins.
185    pub fn new() -> Self {
186        Self
187    }
188}
189
190impl TesseraPackage for ComponentsPackage {
191    fn register(self, registry: &mut EntryRegistry) {
192        pipelines::text::pipeline::preload_system_fonts();
193        registry.register_package(PlatformPackage);
194        registry.add_module(TesseraComponents);
195    }
196}
197
198#[cfg(test)]
199mod overlay_motion_tests;
200
201#[cfg(test)]
202mod sheet_drag_tests;
203
204#[cfg(all(test, not(target_family = "wasm")))]
205mod scaled_controls_tests;
206
207#[cfg(all(test, not(target_family = "wasm")))]
208mod overlay_precision_tests;