tessera_ui/
lib.rs

1//! # Tessera UI Framework
2//!
3//! Tessera is a declarative, immediate-mode UI framework for Rust that emphasizes performance,
4//! flexibility, and extensibility through a functional approach and pluggable shader system.
5//!
6//! ## Architecture Overview
7//!
8//! Tessera's architecture is built around several core concepts:
9//!
10//! - **Declarative Components**: UI components are defined as functions with the `#[tessera]` macro
11//! - **Immediate Mode**: The UI is rebuilt every frame, ensuring consistency and simplicity
12//! - **Pluggable Shaders**: Custom WGPU shaders are first-class citizens for advanced visual effects
13//! - **Parallel Processing**: Core operations like measurement utilize parallel computation
14//! - **Explicit State Management**: Components are stateless with explicit state passing
15//!
16//! ## Getting Started by Developer Level
17//!
18//! ### 🟢 **Beginner Users** - Building Basic Applications
19//!
20//! If you're new to Tessera and want to build applications using existing components:
21//!
22//! **Start with these modules:**
23//! - [`renderer`] - Core renderer and application lifecycle management
24//! - [`Dp`], [`Px`] - Basic measurement units for layouts
25//! - [`Color`] - Color system for styling components
26//!
27//! **Key concepts to understand:**
28//! - How to set up a [`Renderer`] and run your application
29//! - Using `tessera_basic_components` for common UI elements
30//! - Basic layout with `row`, `column`, and `surface` components
31//!
32//! ### 🟡 **Intermediate Users** - Custom Layout and Interaction
33//!
34//! For developers who want to create custom components and handle complex layouts:
35//!
36//! **Essential functions and types:**
37//! - [`measure_node`] - Measure child component sizes with constraints
38//! - [`place_node`] - Position child components in the layout
39//! - [`InputHandlerFn`] - Handle user interactions and state changes
40//! - [`Constraint`], [`DimensionValue`] - Layout constraint system
41//! - [`ComputedData`] - Return computed size and layout information
42//!
43//! **Key concepts:**
44//! - Understanding the measurement and placement phase
45//! - Creating custom layout algorithms
46//! - Managing component state through explicit input handlers
47//! - Working with the constraint-based layout system
48//!
49//! ```
50//! use tessera_ui::{measure_node, place_node, ComputedData, Constraint, PxPosition, tessera};
51//!
52//! #[tessera]
53//! fn custom_layout(child: impl FnOnce()) {
54//!     child();
55//!
56//!     measure(Box::new(|input| {
57//!         // Custom measurement logic here
58//! #        Ok(ComputedData::ZERO) // Make doc tests happy
59//!     }));
60//!
61//!     input_handler(Box::new(|input| {
62//!         // Handle user interactions here
63//!     }));
64//! }
65//! ```
66//!
67//! ### 🔴 **Advanced Users** - Custom Rendering Pipelines
68//!
69//! For developers building custom visual effects and rendering pipelines:
70//!
71//! **Advanced rendering modules:**
72//!
73//! - [`renderer::drawer`] - Custom drawable pipelines and draw commands
74//! - [`renderer::compute`] - GPU compute pipelines for advanced effects
75//! - [`DrawCommand`], [`ComputeCommand`] - Low-level rendering commands
76//! - [`DrawablePipeline`], [`ComputablePipeline`] - Pipeline trait implementations
77//! - [`PipelineRegistry`], [`ComputePipelineRegistry`] - Pipeline management
78//!
79//! **Key concepts:**
80//!
81//! - Creating custom WGPU shaders and pipelines
82//! - Managing GPU resources and compute operations
83//! - Understanding the rendering command system
84//! - Implementing advanced visual effects like lighting, shadows, and particles
85//!
86//! ## Core Modules
87//!
88//! ### Essential Types and Functions
89//!
90//! - [`Renderer`] - Main application renderer and lifecycle manager
91//! - [`measure_node`], [`place_node`] - Core layout functions
92//! - [`Constraint`], [`DimensionValue`] - Layout constraint system
93//! - [`Dp`], [`Px`] - Measurement units (device-independent and pixel units)
94//! - [`Color`] - Color representation and utilities
95//!
96//! ### Component System
97//!
98//! - [`ComponentTree`] - Component tree management
99//! - [`ComponentNode`] - Individual component node representation
100//! - [`ComputedData`] - Layout computation results
101//! - [`InputHandlerFn`] - State management and event handling
102//!
103//! ### Event Handling
104//!
105//! - [`CursorEvent`] - Mouse and touch input events
106//! - [`Focus`] - Focus management system
107//! - [`PressKeyEventType`] - Keyboard input handling
108//!
109//! ### Rendering System
110//!
111//! - [`renderer::drawer`] - Drawing pipeline system
112//! - [`renderer::compute`] - Compute pipeline system
113//! - [`DrawCommand`], [`ComputeCommand`] - Rendering commands
114//!
115//! ## Examples
116//!
117//! Check out the `example` crate in the workspace for comprehensive examples demonstrating:
118//! - Basic component usage
119//! - Custom layouts and interactions
120//! - Advanced shader effects
121//! - Cross-platform deployment (Windows, Linux, macOS, Android)
122//!
123//! ## Performance Considerations
124//!
125//! Tessera is designed for high performance through:
126//! - Parallel measurement computation using Rayon
127//! - Efficient GPU utilization through custom shaders
128//! - Minimal allocations in hot paths
129//! - Optimized component tree traversal
130
131pub mod clipboard;
132pub mod color;
133mod component_tree;
134mod cursor;
135pub mod dp;
136pub mod dyn_eq;
137pub mod dyn_eq_compute;
138pub mod focus_state;
139mod ime_state;
140mod keyboard_state;
141pub mod px;
142pub mod renderer;
143pub mod runtime;
144mod thread_utils;
145
146#[cfg(feature = "shard")]
147pub mod router;
148
149pub use indextree::{Arena, NodeId};
150pub use tessera_ui_macros::tessera;
151pub use wgpu;
152pub use winit;
153
154pub use crate::{
155    clipboard::Clipboard,
156    color::Color,
157    component_tree::{
158        ComponentNode, ComponentNodeMetaData, ComponentNodeMetaDatas, ComponentNodeTree,
159        ComponentTree, ComputedData, Constraint, DimensionValue, ImeRequest, InputHandlerFn,
160        InputHandlerInput, MeasureFn, MeasureInput, MeasurementError, measure_node, measure_nodes,
161        place_node,
162    },
163    cursor::{CursorEvent, CursorEventContent, PressKeyEventType, ScrollEventConent},
164    dp::Dp,
165    focus_state::Focus,
166    px::{Px, PxPosition, PxRect, PxSize},
167    renderer::{
168        BarrierRequirement, Command, Renderer,
169        compute::{
170            self, ComputablePipeline, ComputeCommand, ComputePipelineRegistry, ComputeResource,
171            ComputeResourceManager, ComputeResourceRef,
172        },
173        drawer::{self, DrawCommand, DrawablePipeline, PipelineRegistry, command},
174    },
175    runtime::TesseraRuntime,
176};
177
178use ime_state::ImeState;
179
180#[cfg(feature = "shard")]
181pub use tessera_ui_macros::shard;
182#[cfg(feature = "shard")]
183pub use tessera_ui_shard;