### Renderer::resumed Method Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/struct.Renderer Explains the `resumed` method within the `ApplicationHandler` implementation for `Renderer`. This method is invoked when the application starts or is resumed, responsible for window creation, WGPU context initialization, pipeline registration, and initial state setup. ```APIDOC resumed(&mut self, event_loop: &ActiveEventLoop) Called when the application is resumed or started. This method is responsible for: * Creating the application window with appropriate attributes * Initializing the WGPU context and surface * Registering rendering pipelines * Setting up the initial application state On desktop platforms, this is typically called once at startup. On mobile platforms (especially Android), this may be called multiple times as the app is suspended and resumed. Window Configuration: The window is created with: * Title: “Tessera” * Transparency: Enabled (allows for transparent backgrounds) * Default size and position (platform-dependent) Pipeline Registration: After WGPU initialization, the `register_pipelines_fn` is called to set up all rendering pipelines. This typically includes basic component pipelines and any custom shaders your application requires. ``` -------------------------------- ### Example Constraint Initialization Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.Constraint Demonstrates initializing a Constraint to a default 'NONE' state and asserting its initial width and height properties. ```rust let flexible = Constraint::NONE; assert_eq!(flexible.width, DimensionValue::Wrap { min: None, max: None }); assert_eq!(flexible.height, DimensionValue::Wrap { min: None, max: None }); ``` -------------------------------- ### Tessera UI Focus Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus Demonstrates the basic lifecycle and usage of the Focus struct. It shows how to create a focus instance, request focus for a component, and check if it currently holds focus. Focus is automatically released when the instance is dropped. ```rust use tessera_ui::Focus; // Create a focus instance for a component let button_focus = Focus::new(); // Request focus for this component button_focus.request_focus(); // Check if this component currently has focus if button_focus.is_focused() { println!("Button is focused!"); } // Focus is automatically cleared when the instance is dropped drop(button_focus); ``` -------------------------------- ### Constraint Usage Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.Constraint Illustrates how to create Constraint instances for different layout scenarios, such as fixed size, flexible filling, and wrapping. ```Rust // A button with fixed size let button_constraint = Constraint::new( DimensionValue::Fixed(Px(120)), DimensionValue::Fixed(Px(40)) ); // A flexible container that fills width but wraps height let container_constraint = Constraint::new( DimensionValue::Fill { min: Some(Px(200)), max: None }, DimensionValue::Wrap { min: None, max: None } ); // A text component with bounded wrapping let text_constraint = Constraint::new( DimensionValue::Wrap { min: Some(Px(100)), max: Some(Px(400)) }, DimensionValue::Wrap { min: None, max: None } ); ``` -------------------------------- ### Renderer API Documentation Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/struct.Renderer API documentation for the Renderer struct, including its methods and lifecycle. Focuses on the 'run' method for starting the application. ```APIDOC Renderer __init__(entry_point: F, register_pipelines_fn: R) entry_point: The entry point function type that defines your UI. Must implement Fn(). register_pipelines_fn: The pipeline registration function type. Must implement Fn(&mut WgpuApp) + Clone + 'static. run(entry_point: F, register_pipelines_fn: R) -> Result<(), EventLoopError> Runs the Tessera application with default configuration on desktop platforms. This is the most convenient way to start a Tessera application on Windows, Linux, or macOS. It uses the default TesseraConfig settings (4x MSAA). Parameters: entry_point: The entry point function (F). register_pipelines_fn: The function to register WGPU pipelines (R). Returns: A Result indicating success or an EventLoopError. ``` -------------------------------- ### Px::new() Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.Px Shows the creation of Px instances with positive, negative, and zero values. ```rust use tessera_ui::px::Px; let positive = Px::new(100); let negative = Px::new(-50); let zero = Px::new(0); ``` -------------------------------- ### TesseraConfig Usage Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/struct.TesseraConfig Demonstrates how to create and configure TesseraConfig instances, including using the default settings or specifying custom sample counts for MSAA. ```rust use tessera_ui::renderer::TesseraConfig; // Default configuration (4x MSAA) let config = TesseraConfig::default(); // Custom configuration with 8x MSAA let config = TesseraConfig { sample_count: 8, }; // Disable MSAA for better performance let config = TesseraConfig { sample_count: 1, }; ``` -------------------------------- ### Basic Renderer Run Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/index Demonstrates the fundamental way to start the Tessera UI renderer. It requires an entry point function for the UI and a callback for registering rendering pipelines. ```rust use tessera_ui::Renderer; // Define your UI entry point fn my_app() { // Your UI components go here } // Run the application Renderer::run( my_app, // Entry point function |_app| { // Register rendering pipelines // tessera_ui_basic_components::pipelines::register_pipelines(app); } ).unwrap(); ``` -------------------------------- ### PxPosition Usage Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.PxPosition Demonstrates creating, offsetting, and performing arithmetic operations on PxPosition objects using Rust. ```rust use tessera_ui::px::{Px, PxPosition}; // Create a position let position = PxPosition::new(Px::new(100), Px::new(200)); // Offset the position let offset_position = position.offset(Px::new(10), Px::new(-5)); // Calculate distance between positions let other_position = PxPosition::new(Px::new(103), Px::new(196)); let distance = position.distance_to(other_position); // Arithmetic operations let sum = position + other_position; let diff = position - other_position; ``` -------------------------------- ### Px::raw() Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.Px Demonstrates how to get the raw i32 value from a Px instance. ```rust use tessera_ui::px::Px; let px = Px::new(42); assert_eq!(px.raw(), 42); ``` -------------------------------- ### Simple Counter Application Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/index Demonstrates a basic counter application using Tessera UI with atomic state management. It shows how to initialize the application state and run the renderer. ```rust use std::sync::{Arc, atomic::{AtomicU32, Ordering}}; use tessera_ui::{Renderer, Color, Dp}; use tessera_ui_macros::tessera; struct AppState { count: AtomicU32, } #[tessera] // You need to mark every component function with `#[tessera_macros::tessera]` fn counter_app(state: Arc) { let _count = state.count.load(Ordering::Relaxed); // Your UI components would go here // This is a simplified example without actual UI components } fn main() -> Result<(), Box> { let state = Arc::new(AppState { count: AtomicU32::new(0), }); Renderer::run( move || counter_app(state.clone()), |_app| { // Register your rendering pipelines here // tessera_ui_basic_components::pipelines::register_pipelines(app); } )?; Ok(()) } ``` -------------------------------- ### CursorEventContent Example Usage Source: https://shadow3aaa.github.io/tessera/tessera_ui/enum.CursorEventContent Demonstrates how to handle different CursorEventContent variants using a match statement. This example shows processing press, release, and scroll events. ```rust use tessera_ui::cursor::{CursorEventContent, PressKeyEventType, ScrollEventConent}; // Handle different event types match event_content { CursorEventContent::Pressed(PressKeyEventType::Left) => { println!("Left button pressed"); } CursorEventContent::Released(PressKeyEventType::Right) => { println!("Right button released"); } CursorEventContent::Scroll(scroll) => { println!("Scrolled by ({}, {})", scroll.delta_x, scroll.delta_y); } } ``` -------------------------------- ### Dp Usage Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/dp/struct.Dp Demonstrates common UI measurements using the Dp struct and how to convert Dp values to pixels for rendering. ```rust use tessera_ui::Dp; // Common UI measurements in dp let small_padding = Dp(8.0); let medium_padding = Dp(16.0); let button_height = Dp(48.0); let large_spacing = Dp(32.0); // Convert to pixels for rendering let pixels = button_height.to_pixels_f32(); // Result depends on the current scale factor ``` -------------------------------- ### Px::from_f32() Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.Px Illustrates creating a Px from an f32, showing truncation of decimal parts. ```rust use tessera_ui::px::Px; let px = Px::from_f32(42.7); assert_eq!(px.raw(), 42); ``` -------------------------------- ### Run Tessera UI Application Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/struct.Renderer Demonstrates the basic usage of `Renderer::run` to start the Tessera UI application. It requires an entry point function for building the UI and a function to register rendering pipelines. ```Rust use tessera_ui::Renderer; fn my_ui() { // Your UI components go here } fn main() -> Result<(), Box> { Renderer::run( my_ui, |_app| { // Register your rendering pipelines here // tessera_ui_basic_components::pipelines::register_pipelines(app); } )?; Ok(()) } ``` -------------------------------- ### Px Usage Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.Px Demonstrates how to create and use Px values, including arithmetic operations, saturating arithmetic, and absolute value calculation. ```Rust use tessera_ui::px::Px; // Create pixel values let px1 = Px::new(100); let px2 = Px::new(-50); // Negative values supported // Arithmetic operations let sum = px1 + px2; // Px(50) let doubled = px1 * 2; // Px(200) // Saturating arithmetic prevents overflow let max_px = Px::new(i32::MAX); let safe_add = max_px.saturating_add(Px::new(1)); // Still Px(i32::MAX) // Convert to absolute value for rendering let abs_value = Px::new(-10).abs(); // 0 (negative becomes 0) ``` -------------------------------- ### Append Node Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.NodeId Demonstrates appending new child nodes to an existing node using the `append` method. The example shows the resulting tree structure and verifies the order of descendants. ```Rust let mut arena = Arena::new(); let n1 = arena.new_node("1"); let n1_1 = arena.new_node("1_1"); n1.append(n1_1, &mut arena); let n1_2 = arena.new_node("1_2"); n1.append(n1_2, &mut arena); let n1_3 = arena.new_node("1_3"); n1.append(n1_3, &mut arena); // arena // `-- 1 // |-- 1_1 // |-- 1_2 // `-- 1_3 let mut iter = n1.descendants(&arena); assert_eq!(iter.next(), Some(n1)); assert_eq!(iter.next(), Some(n1_1)); assert_eq!(iter.next(), Some(n1_2)); assert_eq!(iter.next(), Some(n1_3)); assert_eq!(iter.next(), None); ``` -------------------------------- ### PipelineRegistry Usage Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/drawer/struct.PipelineRegistry Demonstrates the typical usage pattern for PipelineRegistry: creating a new registry and registering multiple pipelines during application initialization. ```rust use tessera_ui::renderer::drawer::PipelineRegistry; // Create registry and register pipelines let mut registry = PipelineRegistry::new(); // registry.register(my_shape_pipeline); // registry.register(my_text_pipeline); // registry.register(my_image_pipeline); // Registry is now ready for use by the renderer ``` -------------------------------- ### Rust Any Trait Methods Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus Documentation for the core `Any` trait in Rust, which provides runtime type information. Includes methods for obtaining a `TypeId`. ```APIDOC trait Any // Implementation for Any trait impl Any for T where T: 'static + ?Sized // Gets the TypeId of self. // Returns: TypeId fn type_id(&self) -> TypeId ``` -------------------------------- ### WGSL Compute Shader Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/compute/pipeline/index An example of a compute shader written in WGSL (WebGPU Shading Language) used for GPU compute operations within the Tessera UI framework. These shaders define the logic executed on the GPU for tasks like image processing. ```WGSL // Example WGSL compute shader structure // This is a placeholder as the actual shader code is not provided in the text. // A real shader would define entry points, workgroup sizes, and shader logic. @compute @workgroup_size(8, 8, 1) fn main() { // Compute shader logic goes here } ``` -------------------------------- ### Rust Pretty Print Debugging Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.NodeId Demonstrates using `debug_pretty_print` for a tree structure and asserts its output against expected debug and display formats. ```rust // arena // `-- "root" // |-- "0" // | |-- "0\n0" // | `-- "0\n1" // |-- "1" // `-- "2" // `-- "2\n0" // `-- "2\n0\n0" let printable = root.debug_pretty_print(&arena); let expected_debug = r#""root" |-- "0" | |-- "0\n0" | `-- "0\n1" |-- "1" `-- "2" `-- "2\n0" `-- "2\n0\n0""#; assert_eq!(format!("{:?}", printable), expected_debug); let expected_display = r#"root |-- 0 | |-- 0 | | 0 | `-- 0 | 1 |-- 1 `-- 2 `-- 2 0 `-- 2 0 0"#; assert_eq!(printable.to_string(), expected_display); ``` -------------------------------- ### Color Usage Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/color/struct.Color Demonstrates how to create and use Color instances, including using predefined constants like RED and WHITE, and creating custom colors with specific RGBA values. ```rust use tessera_ui::Color; // Using predefined colors let red = Color::RED; let white = Color::WHITE; let transparent = Color::TRANSPARENT; // Creating custom colors let purple = Color::new(0.5, 0.0, 0.5, 1.0); let semi_transparent_blue = Color::new(0.0, 0.0, 1.0, 0.5); ``` -------------------------------- ### Px::from_dp() Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.Px Illustrates converting density-independent pixels (Dp) to physical pixels (Px). ```rust use tessera_ui::px::Px; use tessera_ui::dp::Dp; let dp_value = Dp::new(16.0); let px_value = Px::from_dp(dp_value); ``` -------------------------------- ### CursorEvent Usage Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.CursorEvent Demonstrates how to create and handle a CursorEvent, matching on its content to process different interaction types like presses, releases, or scrolls. ```rust use tessera_ui::cursor::{CursorEvent, CursorEventContent, PressKeyEventType}; use std::time::Instant; let event = CursorEvent { timestamp: Instant::now(), content: CursorEventContent::Pressed(PressKeyEventType::Left), }; match event.content { CursorEventContent::Pressed(button) => println!("Button pressed: {:?}", button), CursorEventContent::Released(button) => println!("Button released: {:?}", button), CursorEventContent::Scroll(scroll) => { println!("Scroll: dx={}, dy={}", scroll.delta_x, scroll.delta_y); } } ``` -------------------------------- ### Custom Rendering Pipeline Setup Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/index Illustrates how to set up a custom rendering pipeline for the Tessera UI application. This involves defining a function to register custom pipelines with the WgpuApp. ```rust use tessera_ui::{Renderer, renderer::WgpuApp}; fn register_custom_pipelines(app: &mut WgpuApp) { // Register basic components first // tessera_ui_basic_components::pipelines::register_pipelines(app); // Add your custom pipelines // app.drawer.register_pipeline("my_custom_shader", my_pipeline); } fn main() -> Result<(), Box> { Renderer::run( || { /* your UI */ }, register_custom_pipelines )?; Ok(()) } ``` -------------------------------- ### Rust WGPU Draw Function Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/drawer/trait.DrawablePipeline Example Rust function demonstrating how to draw using WGPU, including updating uniforms, setting pipelines, and issuing draw calls. ```Rust fn draw(&mut self, gpu: &wgpu::Device, gpu_queue: &wgpu::Queue, config: &wgpu::SurfaceConfiguration, render_pass: &mut wgpu::RenderPass<'_>, command: &MyCommand, size: PxSize, start_pos: PxPosition, scene_texture_view: &wgpu::TextureView) { // Update uniforms with command-specific data let uniforms = MyUniforms { color: command.color, position: [start_pos.x as f32, start_pos.y as f32], size: [size.width as f32, size.height as f32], }; gpu_queue.write_buffer(&self.uniform_buffer, 0, bytemuck::cast_slice(&[uniforms])); // Set pipeline and resources render_pass.set_pipeline(&self.render_pipeline); render_pass.set_bind_group(0, &self.bind_group, &[]); // Draw a quad (two triangles) render_pass.draw(0..6, 0..1); } ``` -------------------------------- ### Px::to_dp() Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.Px Demonstrates converting physical pixels (Px) back to density-independent pixels (Dp). ```rust use tessera_ui::px::Px; let px_value = Px::new(32); let dp_value = px_value.to_dp(); ``` -------------------------------- ### Px::saturating_from_f32() Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.Px Shows creating a Px from an f32, with values clamped to i32::MIN and i32::MAX on overflow. ```rust use tessera_ui::px::Px; let normal = Px::saturating_from_f32(42.7); assert_eq!(normal.raw(), 42); let max_val = Px::saturating_from_f32(f32::MAX); assert_eq!(max_val.raw(), i32::MAX); let min_val = Px::saturating_from_f32(f32::MIN); assert_eq!(min_val.raw(), i32::MIN); ``` -------------------------------- ### Rust: Px Module Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/index Demonstrates creating and manipulating physical pixel coordinates (Px), positions (PxPosition), and sizes (PxSize) in the tessera_ui framework. Includes arithmetic operations and conversion to/from density-independent pixels (Dp). ```rust use tessera_ui::px::{Px, PxPosition, PxSize}; use tessera_ui::dp::Dp; // Create pixel values let x = Px::new(100); let y = Px::new(200); // Create a position let position = PxPosition::new(x, y); // Create a size let size = PxSize::new(Px::new(300), Px::new(400)); // Arithmetic operations let offset_position = position.offset(Px::new(10), Px::new(-5)); // Convert between Dp and Px let dp_value = Dp::new(16.0); let px_value = Px::from_dp(dp_value); ``` -------------------------------- ### Command Enum Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/command/enum.Command Demonstrates how to create instances of the Command enum for both draw and compute operations. This includes boxing trait objects for specific command types. ```rust // Creating a draw command let draw_cmd = Command::Draw(Box::new(ShapeCommand::Rect { /* ... */ })); // Creating a compute command let compute_cmd = Command::Compute(Box::new(BlurCommand { /* ... */ })); ``` -------------------------------- ### Tessera UI Arena API Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.Arena Provides comprehensive documentation for the Arena struct's methods, including node creation, retrieval by index or ID, modification, counting, and iteration. It covers method signatures, parameter descriptions, return values, potential panics, and usage examples. ```APIDOC pub fn get_node_id_at(&self, index: NonZero) -> Option Retrieves the NodeId corresponding to the Node at index in the Arena, if it exists. Note: Uses 1-based indexing. Parameters: index: NonZero - The 1-based index of the node. Returns: Option - The NodeId if found, None otherwise. Examples: let mut arena = Arena::new(); let foo = arena.new_node("foo"); let node = arena.get(foo).unwrap(); let index: NonZeroUsize = foo.into(); let new_foo = arena.get_node_id_at(index).unwrap(); assert_eq!(foo, new_foo); foo.remove(&mut arena); let new_foo = arena.get_node_id_at(index); assert!(new_foo.is_none(), "must be none if the node at the index doesn't exist"); ``` ```APIDOC pub fn new_node(&mut self, data: T) -> NodeId Creates a new node from its associated data. Panics: Panics if the arena already has usize::max_value() nodes. Parameters: data: T - The data for the new node. Returns: NodeId - The ID of the newly created node. Examples: let mut arena = Arena::new(); let foo = arena.new_node("foo"); assert_eq!(*arena[foo].get(), "foo"); ``` ```APIDOC pub fn count(&self) -> usize Counts the number of nodes in arena and returns it. Parameters: None Returns: usize - The number of nodes in the arena. Examples: let mut arena = Arena::new(); let foo = arena.new_node("foo"); let _bar = arena.new_node("bar"); assert_eq!(arena.count(), 2); foo.remove(&mut arena); assert_eq!(arena.count(), 2); ``` ```APIDOC pub fn is_empty(&self) -> bool Returns true if arena has no nodes, false otherwise. Parameters: None Returns: bool - True if the arena is empty, false otherwise. Examples: let mut arena = Arena::new(); assert!(arena.is_empty()); let foo = arena.new_node("foo"); assert!(!arena.is_empty()); foo.remove(&mut arena); assert!(!arena.is_empty()); ``` ```APIDOC pub fn get(&self, id: NodeId) -> Option<&Node> Returns a reference to the node with the given id if in the arena. Returns None if not available. Note: Does not check whether the given node ID is created by the arena. Parameters: id: NodeId - The ID of the node to retrieve. Returns: Option<&Node> - A reference to the node if found, None otherwise. Examples: let mut arena = Arena::new(); let foo = arena.new_node("foo"); assert_eq!(arena.get(foo).map(|node| *node.get()), Some("foo")); let mut another_arena = Arena::new(); let _ = another_arena.new_node("Another arena"); assert_eq!(another_arena.get(foo).map(|node| *node.get()), Some("foo")); assert!(another_arena.get(bar).is_none()); ``` ```APIDOC pub fn get_mut(&mut self, id: NodeId) -> Option<&mut Node> Returns a mutable reference to the node with the given id if in the arena. Returns None if not available. Parameters: id: NodeId - The ID of the node to retrieve. Returns: Option<&mut Node> - A mutable reference to the node if found, None otherwise. Examples: let mut arena = Arena::new(); let foo = arena.new_node("foo"); assert_eq!(arena.get(foo).map(|node| *node.get()), Some("foo")); *arena.get_mut(foo).expect("The `foo` node exists").get_mut() = "FOO!"; assert_eq!(arena.get(foo).map(|node| *node.get()), Some("FOO!")); ``` ```APIDOC pub fn iter(&self) -> Iter<'_, Node> Returns an iterator of all nodes in the arena in storage-order. Note: This iterator returns also removed elements, which can be tested with the is_removed() method on the node. Parameters: None Returns: Iter<'_, Node> - An iterator over the nodes in the arena. Examples: let mut arena = Arena::new(); let _foo = arena.new_node("foo"); let _bar = arena.new_node("bar"); let mut iter = arena.iter(); assert_eq!(iter.next().map(|node| *node.get()), Some("foo")); assert_eq!(iter.next().map(|node| *node.get()), Some("bar")); assert_eq!(iter.next().map(|node| *node.get()), None); let mut arena = Arena::new(); let _foo = arena.new_node("foo"); let bar = arena.new_node("bar"); bar.remove(&mut arena); let mut iter = arena.iter(); assert_eq!(iter.next().map(|node| (*node.get(), node.is_removed())), Some(("foo", false))); assert_eq!(iter.next().map_or(false, |node| node.is_removed()), true); assert_eq!(iter.next().map(|node| (*node.get(), node.is_removed())), None); ``` -------------------------------- ### ComputablePipeline Example Implementation (Rust) Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/compute/pipeline/trait.ComputablePipeline Illustrates a common pattern for implementing the ComputablePipeline trait. It covers creating uniform buffers, setting up bind groups, and dispatching workgroups within a compute pass. ```rust impl ComputablePipeline for MyPipeline { fn dispatch(&mut self, device, queue, config, compute_pass, command, resource_manager, input_view, output_view) { // 1. Create or retrieve uniform buffer let uniforms = create_uniforms_from_command(command); let uniform_buffer = device.create_buffer_init(...); // 2. Create bind group with textures and uniforms let bind_group = device.create_bind_group(...); // 3. Set pipeline and dispatch compute_pass.set_pipeline(&self.compute_pipeline); compute_pass.set_bind_group(0, &bind_group, &[]); compute_pass.dispatch_workgroups(workgroup_x, workgroup_y, 1); } } ``` -------------------------------- ### PxSize Usage Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.PxSize Demonstrates common usage patterns for the PxSize struct, including creating a new size, converting it to a float array for graphics APIs, and creating it from an array. ```rust use tessera_ui::px::{Px, PxSize}; // Create a size let size = PxSize::new(Px::new(300), Px::new(200)); // Convert to array formats for graphics APIs let f32_array = size.to_f32_arr2(); assert_eq!(f32_array, [300.0, 200.0]); // Create from array let from_array = PxSize::from([Px::new(400), Px::new(300)]); ``` -------------------------------- ### Rust Pretty Print with Ok/Err Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.NodeId Shows `debug_pretty_print` usage with `Result` types (Ok/Err) and asserts output for both standard and alternate debug formatting. ```rust // arena // `-- Ok(42) // `-- Err("err") let printable = root.debug_pretty_print(&arena); let expected_debug = r#"Ok(42) `-- Err("err")"#; assert_eq!(format!("{:?}", printable), expected_debug); let expected_debug_alternate = r#"Ok( 42, ) `-- Err( "err", )"#; assert_eq!(format!("{:#?}", printable), expected_debug_alternate); ``` -------------------------------- ### Focus Struct API Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus API documentation for the Focus struct in tessera_ui. It covers the methods for creating, managing, and querying focus state. These methods are essential for implementing focus-aware components within the tessera_ui framework. ```APIDOC Focus: A focus handle that represents a focusable component. Each `Focus` instance has a unique identifier and can be used to manage focus state for a specific component. The focus system ensures that only one component can have focus at a time across the entire application. Methods: new() -> Self Creates a new focus instance with a unique identifier. Each focus instance is assigned a unique UUID that distinguishes it from all other focus instances in the application. This ensures that focus operations are applied to the correct component. Examples: use tessera_ui::Focus; let focus1 = Focus::new(); let focus2 = Focus::new(); focus1.request_focus(); assert!(focus1.is_focused()); assert!(!focus2.is_focused()); focus2.request_focus(); assert!(!focus1.is_focused()); assert!(focus2.is_focused()); is_focused(&self) -> bool Checks if this focus instance currently has focus. Returns `true` if this specific focus instance is the currently active focus in the global focus state, `false` otherwise. Thread Safety: This method is thread-safe and can be called from any thread. It acquires a read lock on the global focus state. Examples: use tessera_ui::Focus; let focus = Focus::new(); assert!(!focus.is_focused()); focus.request_focus(); assert!(focus.is_focused()); request_focus(&self) Requests focus for this component. This method sets the global focus state to this focus instance, potentially removing focus from any previously focused component. Only one component can have focus at a time. ``` -------------------------------- ### Trait Implementations for `Focus` Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus Lists the various trait implementations for the `Focus` struct, including `Default` and `Drop`. These implementations define standard behaviors like default instantiation and automatic cleanup. ```rust impl Default for Focus { fn default() -> Self { // Creates a new focus instance with a unique identifier. // This is equivalent to calling Focus::new(). Focus::new() } } impl Drop for Focus { fn drop(&mut self) { // Automatically clears focus when the Focus instance is dropped. // This ensures that focus is properly cleaned up when a component // is destroyed or goes out of scope. // If this focus instance currently has focus, it will be cleared // from the global focus state. } } ``` -------------------------------- ### Basic Application with Tessera UI Framework (Rust) Source: https://shadow3aaa.github.io/tessera/tessera_ui/index Demonstrates setting up a basic Tessera application using core components like Renderer, Color, and Dp for layout. It shows how to render a simple text element within a surface. ```Rust use tessera_ui::{Renderer, Color, Dp}; use tessera_ui_basic_components::*; use tessera_ui_macros::tessera; #[tessera] fn my_app() { surface( SurfaceArgs { color: Color::WHITE, padding: Dp(20.0), ..Default::default() }, None, || text("Hello, Tessera!"), ); } ``` -------------------------------- ### Basic Focus Management with `tessera_ui::Focus` Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus Demonstrates the fundamental usage of the `Focus` struct, including creating new instances, requesting focus, and checking the current focus state. It highlights how requesting focus for one instance relinquishes it from another. This functionality is thread-safe. ```rust use tessera_ui::Focus; let focus1 = Focus::new(); let focus2 = Focus::new(); focus1.request_focus(); assert!(focus1.is_focused()); assert!(!focus2.is_focused()); // Requesting focus for focus2 removes it from focus1 focus2.request_focus(); assert!(!focus1.is_focused()); assert!(focus2.is_focused()); ``` -------------------------------- ### Rust Borrow and BorrowMut Trait Methods Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus Documentation for the `Borrow` and `BorrowMut` traits, which enable immutable and mutable borrowing of owned values, respectively. These are fundamental for Rust's ownership and borrowing system. ```APIDOC trait Borrow // Implementation for Borrow trait impl Borrow for T where T: ?Sized // Immutably borrows from an owned value. // Returns: &T fn borrow(&self) -> &T trait BorrowMut // Implementation for BorrowMut trait impl BorrowMut for T where T: ?Sized // Mutably borrows from an owned value. // Returns: &mut T fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### Detach Node Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.NodeId Illustrates how to detach a node from its parent and siblings using the `detach` method. The example shows the state of the arena and verifies that the detached node no longer has parent or sibling references. ```Rust // arena // `-- (implicit) // `-- 1 // |-- 1_1 // | `-- 1_1_1 // |-- 1_2 * // `-- 1_3 n1_2.detach(&mut arena); // arena // |-- (implicit) // | `-- 1 // | |-- 1_1 // | | `-- 1_1_1 // | `-- 1_3 // `-- (implicit) // `-- 1_2 * assert!(arena[n1_2].parent().is_none()); assert!(arena[n1_2].previous_sibling().is_none()); assert!(arena[n1_2].next_sibling().is_none()); let mut iter = n1.descendants(&arena); assert_eq!(iter.next(), Some(n1)); assert_eq!(iter.next(), Some(n1_1)); assert_eq!(iter.next(), Some(n1_1_1)); assert_eq!(iter.next(), Some(n1_3)); assert_eq!(iter.next(), None); ``` -------------------------------- ### DimensionValue Usage Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/enum.DimensionValue Illustrates how to use the DimensionValue enum variants. Fixed sets an exact pixel size, Wrap sizes to content with optional constraints, and examples show creating these values with or without bounds. ```rust let button_width = DimensionValue::Fixed(Px(120)); let text_width = DimensionValue::Wrap { min: None, max: None }; let min_text_width = DimensionValue::Wrap { min: Some(Px(100)), max: None }; let bounded_text = DimensionValue::Wrap { min: Some(Px(50)), max: Some(Px(300)) }; ``` -------------------------------- ### Rust AsAny Trait Methods Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus Documentation for the `AsAny` trait, which allows converting a reference to a concrete type into a reference to `dyn Any`. This is useful for dynamic dispatch and downcasting. ```APIDOC trait AsAny // Implementation for AsAny trait impl AsAny for T where T: Any // Returns a reference to the concrete type as &dyn Any. // Returns: &(dyn Any + 'static) fn as_any(&self) -> &(dyn Any + 'static) ``` -------------------------------- ### Rust Downcast Trait Methods Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus Documentation for the `Downcast` trait and its associated methods, enabling the conversion of trait objects (`Box`, `Rc`, `&Trait`) to `dyn Any` and subsequent downcasting to concrete types. ```APIDOC trait Downcast // Implementation for Downcast trait impl Downcast for T where T: Any // Convert Box to Box. // Returns: Box fn into_any(self: Box) -> Box // Convert Rc to Rc. // Returns: Rc fn into_any_rc(self: Rc) -> Rc // Convert &Trait to &Any. // Returns: &(dyn Any + 'static) fn as_any(&self) -> &(dyn Any + 'static) // Convert &mut Trait to &mut Any. // Returns: &mut (dyn Any + 'static) fn as_any_mut(&mut self) -> &mut (dyn Any + 'static) ``` -------------------------------- ### Desktop Platform Renderer Run Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/index Illustrates running the renderer on desktop platforms (Windows, Linux, macOS). It requires marking the entry point function with the `#[tessera]` macro. ```rust use tessera_ui::Renderer; use tessera_ui_macros::tessera; #[tessera] // You need to mark every component function with `#[tessera_macros::tessera]` fn entry_point() {} fn register_pipelines(_: &mut tessera_ui::renderer::WgpuApp) {} Renderer::run(entry_point, register_pipelines)?; ``` -------------------------------- ### Px::to_f32() Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.Px Demonstrates converting a Px value to an f32. ```rust use tessera_ui::px::Px; let px = Px::new(42); assert_eq!(px.to_f32(), 42.0); ``` -------------------------------- ### Renderer API Documentation Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/index Details the primary methods for running the Tessera UI renderer, including basic execution and execution with custom configuration. ```APIDOC Renderer::run(entry_point: F, register_pipelines: G) -> Result<(), Box> - Starts the Tessera UI application with a given entry point and pipeline registration callback. - entry_point: A function that defines the application's UI structure. - register_pipelines: A closure that registers rendering pipelines with the application. - Returns: A Result indicating success or an error during application startup. Renderer::run_with_config(entry_point: F, register_pipelines: G, config: TesseraConfig) -> Result<(), Box> - Starts the Tessera UI application with a given entry point, pipeline registration callback, and custom configuration. - entry_point: A function that defines the application's UI structure. - register_pipelines: A closure that registers rendering pipelines with the application. - config: A `TesseraConfig` struct to customize renderer behavior (e.g., `sample_count`). - Returns: A Result indicating success or an error during application startup. Renderer::run(entry_point: F, register_pipelines: G, android_app: AndroidApp) -> Result<(), Box> - Starts the Tessera UI application on Android, passing the `AndroidApp` context. - entry_point: A function that defines the application's UI structure. - register_pipelines: A closure that registers rendering pipelines with the application. - android_app: The `winit::platform::android::activity::AndroidApp` context. - Returns: A Result indicating success or an error during application startup. ``` -------------------------------- ### Create New ComputePipelineRegistry Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/compute/pipeline/struct.ComputePipelineRegistry Demonstrates how to create a new, empty ComputePipelineRegistry. This is the first step in setting up the registry for managing compute operations. ```rust use tessera_ui::renderer::compute::ComputePipelineRegistry; // Create registry and register pipelines let mut registry = ComputePipelineRegistry::new(); registry.register(blur_pipeline); registry.register(contrast_pipeline); registry.register(brightness_pipeline); // Registry is now ready for use by the renderer ``` -------------------------------- ### APIDOC: Rust Pointable Trait Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus Documentation for the `Pointable` trait, which provides methods for managing raw pointers, including alignment, initialization, dereferencing (mutable and immutable), and dropping objects. It defines an associated type `Init` for initializers and a constant `ALIGN` for pointer alignment. ```APIDOC impl Pointable for T Associated Constant: ALIGN: usize The alignment of pointer. Associated Type: type Init = T The type for initializers. Methods: unsafe fn init(init: ::Init) -> usize Initializes a with the given initializer. Read more unsafe fn deref<'a>(ptr: usize) -> &'a T Dereferences the given pointer. Read more unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T Mutably dereferences the given pointer. Read more unsafe fn drop(ptr: usize) Drops the object pointed to by the given pointer. Read more ``` -------------------------------- ### Renderer::run_with_config API Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/struct.Renderer Provides the signature and details for `Renderer::run_with_config`, which allows launching the Tessera application with custom rendering configurations. It accepts an entry point, a pipeline registration function, and a `TesseraConfig` object. ```APIDOC Renderer::run_with_config( entry_point: F, register_pipelines_fn: R, config: TesseraConfig, ) -> Result<(), EventLoopError> Runs the Tessera application with custom configuration on desktop platforms. This method allows you to customize the renderer behavior through TesseraConfig. Use this when you need to adjust settings like MSAA sample count or other rendering parameters. Parameters: - entry_point: A function that defines your UI - register_pipelines_fn: A function that registers rendering pipelines - config: Custom configuration for the renderer Returns: Returns Ok(()) when the application exits normally, or an EventLoopError if the event loop fails to start. ``` -------------------------------- ### Get Node Children (Rust) Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.NodeId Returns an iterator of IDs for the direct children of the current node within the arena. ```rust pub fn children(self, arena: &[Arena]) -> Children<'_, T> ``` -------------------------------- ### Px::abs() Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.Px Shows how the abs() method returns the absolute value, clamping negative inputs to 0. ```rust use tessera_ui::px::Px; assert_eq!(Px::new(10).abs(), 10); assert_eq!(Px::new(-5).abs(), 0); assert_eq!(Px::new(0).abs(), 0); ``` -------------------------------- ### ComputePipelineRegistry Methods Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/compute/pipeline/struct.ComputePipelineRegistry API documentation for methods associated with ComputePipelineRegistry. Includes the constructor 'new' and the 'register' method for adding pipelines. ```APIDOC ComputePipelineRegistry: new() -> Self Creates a new empty compute pipeline registry. Example: use tessera_ui::renderer::compute::ComputePipelineRegistry; let registry = ComputePipelineRegistry::new(); register

(pipeline: P) Registers a compute pipeline. The pipeline type `P` must implement the necessary traits for dispatch. Parameters: pipeline: The compute pipeline to register. Note: All registered pipelines are called for each command until one handles it. Order matters for performance. ``` -------------------------------- ### Rust: Identity Conversion with From Source: https://shadow3aaa.github.io/tessera/tessera_ui/focus_state/struct.Focus Implements the `From` trait for `T`, providing an identity conversion. This method simply returns the argument unchanged. ```rust impl From for T fn from(t: T) -> T Returns the argument unchanged. ``` -------------------------------- ### DimensionValue Fill Examples Source: https://shadow3aaa.github.io/tessera/tessera_ui/enum.DimensionValue Illustrates how to use the `Fill` variant of `DimensionValue` to define flexible sizing with optional minimum and maximum bounds. ```rust let flexible_width = DimensionValue::Fill { min: None, max: None }; ``` ```rust let min_fill_width = DimensionValue::Fill { min: Some(Px(200)), max: None }; ``` ```rust let capped_fill = DimensionValue::Fill { min: Some(Px(100)), max: Some(Px(800)) }; ``` -------------------------------- ### Rust TryFrom and TryInto Conversions Source: https://shadow3aaa.github.io/tessera/tessera_ui/struct.NodeId Documentation for Rust's TryFrom and TryInto traits, which provide fallible conversions between types. Includes method signatures for performing conversions and defining error types. ```APIDOC trait TryFrom { type Error; fn try_from(value: U) -> Result; } trait TryInto { type Error; fn try_into(self) -> Result; } // Example of associated type for TryInto // type Error = >::Error; ``` -------------------------------- ### Dp Arithmetic Operations Example Source: https://shadow3aaa.github.io/tessera/tessera_ui/dp/struct.Dp Illustrates how to perform arithmetic operations on Dp values by accessing the inner f64 value. ```rust use tessera_ui::Dp; let base_size = Dp(16.0); let double_size = Dp(base_size.0 * 2.0); let half_size = Dp(base_size.0 / 2.0); ``` -------------------------------- ### Get Runtime - tessera_ui tokio_runtime Source: https://shadow3aaa.github.io/tessera/tessera_ui/tokio_runtime/fn.get Retrieves a static reference to the Tokio runtime instance. This function is part of the tokio_runtime module within the tessera_ui library. ```rust pub fn get() -> &'static Runtime ``` -------------------------------- ### Run Tessera UI with Custom Configuration Source: https://shadow3aaa.github.io/tessera/tessera_ui/renderer/struct.Renderer Illustrates how to use `Renderer::run_with_config` by providing a custom `TesseraConfig` to modify renderer settings, such as enabling 8x MSAA for improved visual quality. ```Rust use tessera_ui::{Renderer, renderer::TesseraConfig}; let config = TesseraConfig { sample_count: 8, // 8x MSAA for higher quality }; Renderer::run_with_config( || { /* my_ui */ }, |_app| { /* register_pipelines */ }, config )?; ``` -------------------------------- ### PxPosition AsAny Trait Implementation Source: https://shadow3aaa.github.io/tessera/tessera_ui/px/struct.PxPosition Shows the implementation of the `AsAny` trait for PxPosition, which provides a method to get a reference to the underlying `Any` trait object. ```rust impl AsAny for T where T: Any, fn as_any(&self) ```