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//! ```rust,ignore
33//! use tessera_ui::{Renderer, Color, Dp};
34//! use tessera_ui_basic_components::*;
35//! use tessera_ui_macros::tessera;
36//!
37//! #[tessera]
38//! fn my_app() {
39//! surface(
40//! SurfaceArgs {
41//! color: Color::WHITE,
42//! padding: Dp(20.0),
43//! ..Default::default()
44//! },
45//! None,
46//! || text("Hello, Tessera!"),
47//! );
48//! }
49//! ```
50//!
51//! ### 🟡 **Intermediate Users** - Custom Layout and Interaction
52//!
53//! For developers who want to create custom components and handle complex layouts:
54//!
55//! **Essential functions and types:**
56//! - [`measure_node`] - Measure child component sizes with constraints
57//! - [`place_node`] - Position child components in the layout
58//! - [`StateHandlerFn`] - Handle user interactions and state changes
59//! - [`Constraint`], [`DimensionValue`] - Layout constraint system
60//! - [`ComputedData`] - Return computed size and layout information
61//!
62//! **Key concepts:**
63//! - Understanding the measurement and placement phase
64//! - Creating custom layout algorithms
65//! - Managing component state through explicit state handlers
66//! - Working with the constraint-based layout system
67//!
68//! ```rust,ignore
69//! use tessera_ui::{measure_node, place_node, ComputedData, Constraint, PxPosition};
70//! use tessera_ui_macros::tessera;
71//!
72//! #[tessera]
73//! fn custom_layout() {
74//! measure(|input| {
75//! let mut total_width = 0;
76//! for (i, &child_id) in input.children_ids.iter().enumerate() {
77//! let child_size = measure_node(child_id, input.parent_constraint, input.metadatas)?;
78//! place_node(child_id, PxPosition::new(total_width.into(), 0.into()), input.metadatas);
79//! total_width += child_size.width.to_i32();
80//! }
81//! Ok(ComputedData::from_size((total_width.into(), input.parent_constraint.height.min_value())))
82//! });
83//!
84//! state_handler(|input| {
85//! // Handle user interactions here
86//! });
87//! }
88//! ```
89//!
90//! ### 🔴 **Advanced Users** - Custom Rendering Pipelines
91//!
92//! For developers building custom visual effects and rendering pipelines:
93//!
94//! **Advanced rendering modules:**
95//! - [`renderer::drawer`] - Custom drawable pipelines and draw commands
96//! - [`renderer::compute`] - GPU compute pipelines for advanced effects
97//! - [`DrawCommand`], [`ComputeCommand`] - Low-level rendering commands
98//! - [`DrawablePipeline`], [`ComputablePipeline`] - Pipeline trait implementations
99//! - [`PipelineRegistry`], [`ComputePipelineRegistry`] - Pipeline management
100//!
101//! **Key concepts:**
102//! - Creating custom WGPU shaders and pipelines
103//! - Managing GPU resources and compute operations
104//! - Understanding the rendering command system
105//! - Implementing advanced visual effects like lighting, shadows, and particles
106//!
107//! ```rust,ignore
108//! use tessera_ui::renderer::{DrawCommand, DrawablePipeline};
109//! use wgpu::{Device, Queue, RenderPass};
110//!
111//! struct MyCustomPipeline {
112//! // Your pipeline state
113//! }
114//!
115//! impl DrawablePipeline for MyCustomPipeline {
116//! fn draw<'a>(&'a self, render_pass: &mut RenderPass<'a>) {
117//! // Custom rendering logic
118//! }
119//! }
120//! ```
121//!
122//! ## Core Modules
123//!
124//! ### Essential Types and Functions
125//! - [`Renderer`] - Main application renderer and lifecycle manager
126//! - [`measure_node`], [`place_node`] - Core layout functions
127//! - [`Constraint`], [`DimensionValue`] - Layout constraint system
128//! - [`Dp`], [`Px`] - Measurement units (device-independent and pixel units)
129//! - [`Color`] - Color representation and utilities
130//!
131//! ### Component System
132//! - [`ComponentTree`] - Component tree management
133//! - [`ComponentNode`] - Individual component node representation
134//! - [`ComputedData`] - Layout computation results
135//! - [`StateHandlerFn`] - State management and event handling
136//!
137//! ### Event Handling
138//! - [`CursorEvent`] - Mouse and touch input events
139//! - [`Focus`] - Focus management system
140//! - [`PressKeyEventType`] - Keyboard input handling
141//!
142//! ### Rendering System
143//! - [`renderer::drawer`] - Drawing pipeline system
144//! - [`renderer::compute`] - Compute pipeline system
145//! - [`DrawCommand`], [`ComputeCommand`] - Rendering commands
146//!
147//! ## Examples
148//!
149//! Check out the `example` crate in the workspace for comprehensive examples demonstrating:
150//! - Basic component usage
151//! - Custom layouts and interactions
152//! - Advanced shader effects
153//! - Cross-platform deployment (Windows, Linux, macOS, Android)
154//!
155//! ## Performance Considerations
156//!
157//! Tessera is designed for high performance through:
158//! - Parallel measurement computation using Rayon
159//! - Efficient GPU utilization through custom shaders
160//! - Minimal allocations in hot paths
161//! - Optimized component tree traversal
162
163pub mod clipboard;
164pub mod color;
165mod component_tree;
166mod cursor;
167pub mod dp;
168pub mod focus_state;
169mod ime_state;
170mod keyboard_state;
171pub mod px;
172pub mod renderer;
173pub mod runtime;
174mod thread_utils;
175pub mod tokio_runtime;
176
177pub use indextree::{Arena, NodeId};
178pub use wgpu;
179pub use winit;
180
181pub use crate::{
182 clipboard::Clipboard,
183 color::Color,
184 component_tree::{
185 ComponentNode, ComponentNodeMetaData, ComponentNodeMetaDatas, ComponentNodeTree,
186 ComponentTree, ComputedData, Constraint, DimensionValue, ImeRequest, MeasureFn,
187 MeasurementError, StateHandlerFn, StateHandlerInput, measure_node, measure_nodes,
188 place_node,
189 },
190 cursor::{CursorEvent, CursorEventContent, PressKeyEventType, ScrollEventConent},
191 dp::Dp,
192 focus_state::Focus,
193 px::{Px, PxPosition, PxSize},
194 renderer::{
195 Command, Renderer,
196 compute::{
197 self, ComputablePipeline, ComputeCommand, ComputePipelineRegistry, ComputeResource,
198 ComputeResourceManager, ComputeResourceRef,
199 },
200 drawer::{
201 self, BarrierRequirement, DrawCommand, DrawablePipeline, PipelineRegistry, command,
202 },
203 },
204 runtime::TesseraRuntime,
205};
206
207use ime_state::ImeState;