### Install xbuild for Android Development Source: https://github.com/shadow3aaa/tessera/blob/main/example/README.md Installs the xbuild toolchain, a prerequisite for building and running the example on Android devices. This command uses Cargo to install the package globally. ```bash cargo install xbuild ``` -------------------------------- ### Run Example on Windows/Linux Source: https://github.com/shadow3aaa/tessera/blob/main/example/README.md Demonstrates how to navigate to the example directory and run the Tessera UI framework example using Cargo on Windows and Linux systems. ```bash cd example cargo run ``` -------------------------------- ### Run Example on Windows/Linux Source: https://github.com/shadow3aaa/tessera/blob/main/README.md Instructions to navigate to the example directory and run the Tessera example application using Cargo. ```bash # Enter the example directory cd example # Run cargo run ``` -------------------------------- ### Run Example on Android Source: https://github.com/shadow3aaa/tessera/blob/main/README.md Steps to install the `xbuild` tool and run the Tessera example on an Android device, including device ID lookup. ```bash # Install xbuild cargo install xbuild # Find your device ID x devices # Assuming device ID is adb:823c4f8b and architecture is arm64 x run -p example --arch arm64 --device adb:823c4f8b ``` -------------------------------- ### Run Tessera Example on Android (Bash) Source: https://github.com/shadow3aaa/tessera/blob/main/docs/README_zh-CN.md Steps to deploy and run the Tessera example on Android devices. This process requires installing the `xbuild` tool, identifying the target device using `x devices`, and then executing the `x run` command with the appropriate architecture and device identifier. ```bash # 安装 xbuild cargo install xbuild # 运行示例 # 查找您的设备 ID x devices # 假设设备 ID 为 adb:823c4f8b,架构为 arm64 x run -p example --arch arm64 --device adb:823c4f8b ``` -------------------------------- ### Run Tessera Example on Desktop (Bash) Source: https://github.com/shadow3aaa/tessera/blob/main/docs/README_zh-CN.md Instructions for building and running the Tessera example project on desktop environments like Windows and Linux. This involves navigating to the example directory and executing the `cargo run` command. ```bash # 进入 example 目录 cd example # 运行 cargo run ``` -------------------------------- ### Run Example on Android Device Source: https://github.com/shadow3aaa/tessera/blob/main/example/README.md Executes the Tessera UI framework example on a connected Android device. It includes steps to identify the device ID and then run the example targeting a specific architecture. ```bash # get device id x devices # let's say the device id is `adb:823c4f8b` x run -p example --arch arm64 --device adb:823c4f8b ``` -------------------------------- ### Build Android APK Source: https://github.com/shadow3aaa/tessera/blob/main/example/README.md Optionally builds the Android application package (APK) for the Tessera UI framework example. This command specifies the platform, architecture, and output format. ```bash x build -p example --platform android --arch arm64 --format apk ``` -------------------------------- ### Install rust-script Source: https://github.com/shadow3aaa/tessera/blob/main/scripts/README.md Command to install the rust-script tool, which allows running Rust scripts directly from the command line. ```Bash cargo install rust-script ``` -------------------------------- ### Rust Counter Application Example Source: https://github.com/shadow3aaa/tessera/blob/main/README.md Demonstrates a simple counter application using Tessera components, including state management with `Arc` and UI elements like buttons and text. ```rust /// Main counter application component #[tessera] fn counter_app(app_state: Arc) { { let button_state_clone = app_state.button_state.clone(); // Renamed for clarity let click_count = app_state.click_count.load(atomic::Ordering::Relaxed); let app_state_clone = app_state.clone(); // Clone app_state for the button's on_click surface( SurfaceArgs { color: [1.0, 1.0, 1.0, 1.0], // White background padding: Dp(25.0), ..Default::default() }, None, move || { row_ui![ RowArgsBuilder::default() .main_axis_alignment(MainAxisAlignment::SpaceBetween) .cross_axis_alignment(CrossAxisAlignment::Center) .build() .unwrap(), move || { button( ButtonArgsBuilder::default() .on_click(Arc::new(move || { // Increment the click count app_state_clone // Use the cloned app_state .click_count .fetch_add(1, atomic::Ordering::Relaxed); })) .build() .unwrap(), button_state_clone, // Use the cloned button_state move || text("click me!"), ) }, move || { text( TextArgsBuilder::default() .text(format!("Count: {}", click_count)) .build() .unwrap(), ) } ]; }, ); } } ``` -------------------------------- ### Run Tessera Logo Project Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-logo/README.md Command to build and run the Tessera Logo project. Requires the Rust environment to be installed. Executes the project in the root directory of the 'tessera_logo' crate. ```bash cargo run -p tessera_logo ``` -------------------------------- ### Simple Counter Component Example Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/docs/README_zh-CN.md A practical example demonstrating a simple counter component using the `#[tessera]` macro. It shows how to manage state (using `Arc`) and trigger state updates via a button's `on_click` handler. ```rust use tessera_macros::tessera; use std::sync::{Arc, atomic::{AtomicI32, Ordering}}; #[tessera] fn counter_component(count: Arc) { let current_count = count.load(Ordering::Relaxed); // Using tessera_basic_components to build UI button( ButtonArgs { on_click: Arc::new(move || { count.fetch_add(1, Ordering::Relaxed); }), ..Default::default() }, button_state, move || text(format!("Count: {}\n", current_count)), ); } ``` -------------------------------- ### Run check-imports.rs script Source: https://github.com/shadow3aaa/tessera/blob/main/scripts/README.md Example command to execute the `check-imports.rs` script using `rust-script`, demonstrating how to pass arguments like `--help`. ```Bash rust-script scripts/check-imports.rs --help ``` -------------------------------- ### Tessera Custom Layout Component Example (Rust) Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/README.md An example showcasing a custom layout component in Tessera. It defines specific measurement logic using the `measure` function and includes child components like text. ```rust use tessera_macros::tessera; use tessera::{ComputedData, Constraints, Px}; #[tessera] fn custom_layout() { measure(Box::new(|_| { // Custom measurement logic use tessera::{ComputedData, Px}; Ok(ComputedData { width: Px(120), height: Px(80), }) })); // Child components text("Hello, World!"); } ``` -------------------------------- ### Tessera Counter Component Example (Rust) Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/README.md A practical example demonstrating a simple counter component using the #[tessera] macro. It utilizes atomic integers for state management and integrates with basic Tessera UI elements like buttons and text. ```rust use tessera_macros::tessera; use std::sync::{Arc, atomic::{AtomicI32, Ordering}}; #[tessera] fn counter_component(count: Arc) { let current_count = count.load(Ordering::Relaxed); // Use tessera_basic_components for UI button( ButtonArgs { on_click: Arc::new(move || { count.fetch_add(1, Ordering::Relaxed); }), ..Default::default() }, button_state, move || text(format!("Count: {}\n", current_count)), ); } ``` -------------------------------- ### Rust Tessera Counter App Example Source: https://github.com/shadow3aaa/tessera/blob/main/docs/README_zh-CN.md Demonstrates a simple counter application using Tessera's declarative component model and explicit state management. It showcases defining UI elements like buttons and text, handling user interaction with state updates, and utilizing layout components such as `row_ui!`. ```rust /// 主计数器应用组件 #[tessera] fn counter_app(app_state: Arc) { { let button_state_clone = app_state.button_state.clone(); // 为清晰起见重命名 let click_count = app_state.click_count.load(atomic::Ordering::Relaxed); let app_state_clone = app_state.clone(); // 为按钮的 on_click 克隆 app_state surface( SurfaceArgs { color: [1.0, 1.0, 1.0, 1.0], // 白色背景 padding: Dp(25.0), ..Default::default() }, None, move || { row_ui![ RowArgsBuilder::default() .main_axis_alignment(MainAxisAlignment::SpaceBetween) .cross_axis_alignment(CrossAxisAlignment::Center) .build() .unwrap(), move || { button( ButtonArgsBuilder::default() .on_click(Arc::new(move || { // 增加点击次数 app_state_clone // 使用克隆的 app_state .click_count .fetch_add(1, atomic::Ordering::Relaxed); })) .build() .unwrap(), button_state_clone, // 使用克隆的 button_state move || text("click me!"), ) }, move || { text( TextArgsBuilder::default() .text(format!("Count: {}", click_count)) .build() .unwrap(), ) } ]; }, ); } } ``` -------------------------------- ### Custom Layout Component Example Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/docs/README_zh-CN.md An example of a custom layout component that defines its measurement logic using the `measure` function provided by the `#[tessera]` macro. It also includes a child component (`text`). ```rust use tessera_macros::tessera; use tessera::{ComputedData, Constraints, Px}; #[tessera] fn custom_layout() { measure(Box::new(|_| { // Custom measurement logic use tessera::{ComputedData, Px}; Ok(ComputedData { width: Px(120), height: Px(80), }) })); // Child component text("Hello, World!"); } ``` -------------------------------- ### Component with Parameters using #[tessera] Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/docs/README_zh-CN.md Illustrates how to define Tessera UI components that accept parameters, such as `label` and `on_click` handlers, using the `#[tessera]` macro. The macro handles the integration of these components into the framework's component tree. ```rust use tessera_macros::tessera; use std::sync::Arc; #[tessera] fn button_component(label: String, on_click: Arc) { // Component implementation // The macro handles component tree integration } ``` -------------------------------- ### Run tests in tessera Source: https://github.com/shadow3aaa/tessera/blob/main/docs/CONTRIBUTING_zh-CN.md Before submitting changes, ensure all project tests pass. This command executes the test suite for the tessera project. ```bash cargo test ``` -------------------------------- ### Define Tessera Component with Parameters (Rust) Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/README.md Shows how to define a Tessera UI component that accepts parameters. The #[tessera] macro handles the integration of components with custom arguments, such as strings or closures, into the framework. ```rust use tessera_macros::tessera; use std::sync::Arc; #[tessera] fn button_component(label: String, on_click: Arc) { // Component implementation // The macro handles component tree integration } ``` -------------------------------- ### Run rust-script for import checks and formatting Source: https://github.com/shadow3aaa/tessera/blob/main/docs/CONTRIBUTING_zh-CN.md This command uses rust-script to check and fix import rules and also applies rustfmt formatting to the project. It's recommended to run this from the project root to ensure all files, including scripts, are formatted correctly. ```bash rust-script scripts/check-imports.rs . --fix ``` -------------------------------- ### Format Rust Code and Imports with rust-script Source: https://github.com/shadow3aaa/tessera/blob/main/CONTRIBUTING.md This snippet demonstrates commands for formatting Rust code and checking/fixing import rules. It includes using `cargo fmt` for general formatting and a specific `rust-script` command to enforce import order, sorting, and merging, ensuring compliance with project standards. ```bash cargo fmt rust-script scripts/check-imports.rs . --fix ``` -------------------------------- ### Define Basic Tessera Component (Rust) Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/README.md Demonstrates the fundamental usage of the #[tessera] macro to define a basic Tessera UI component. It highlights how the macro automatically integrates the function into the Tessera component tree and provides access to runtime functionalities. ```rust use tessera_macros::tessera; #[tessera] fn my_component() { // Your component logic here // The macro automatically provides access to: // - measure: for custom layout logic // - state_handler: for handling user interactions } ``` -------------------------------- ### Format code with rustfmt Source: https://github.com/shadow3aaa/tessera/blob/main/docs/CONTRIBUTING_zh-CN.md This command applies the default rustfmt formatting rules for the Rust edition 2024 to your code. It helps maintain consistent code style across the project. ```bash cargo fmt ``` -------------------------------- ### Basic Component Definition with #[tessera] Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/docs/README_zh-CN.md Demonstrates the fundamental usage of the `#[tessera]` attribute macro to convert a Rust function into a Tessera UI component. It shows the basic structure and the implicit access to runtime features like `measure` and `state_handler`. ```rust use tessera_macros::tessera; #[tessera] fn my_component() { // Your component logic here // The macro automatically provides access to: // - measure: for custom layout logic // - state_handler: for handling user interactions } ``` -------------------------------- ### Tessera Macro Transformation Concept (Rust) Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/README.md Provides a conceptual overview of how the #[tessera] macro transforms a Rust function. It outlines the steps involved, including component registration, runtime access injection, and safe execution of the original function body. ```rust fn my_component() { // Component tree registration TesseraRuntime::write().component_tree.add_node(ComponentNode { ... }); // Inject measure and state_handler functions let measure = |fun: Box| { /* ... */ }; let state_handler = |fun: Box| { /* ... */ }; // Execute original function body safely let result = { let closure = || { // Original component logic here }; closure() }; // Clean up component tree TesseraRuntime::write().component_tree.pop_node(); result } ``` -------------------------------- ### Conceptual Transformation by #[tessera] Macro Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/docs/README_zh-CN.md Provides a conceptual view of how the `#[tessera]` macro transforms a simple Rust function into a fully integrated Tessera component. It illustrates the steps involved, such as component registration, runtime function injection, and tree management. ```rust // Macro application before #[tessera] fn my_component() { // Component logic } // Macro application after (conceptual) fn my_component() { // Component tree registration TesseraRuntime::write().component_tree.add_node(ComponentNode { ... }); // Inject measure and state_handler functions let measure = |fun: Box| { /* ... */ }; let state_handler = |fun: Box| { /* ... */ }; // Safely execute the original function body let result = { let closure = || { // Original component logic here }; closure() }; // Clean up component tree TesseraRuntime::write().component_tree.pop_node(); result } ``` -------------------------------- ### Customizing Layout and Interaction with #[tessera] Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/docs/README_zh-CN.md Shows how to leverage the `measure` and `state_handler` functions injected by the `#[tessera]` macro within a component. This allows for custom layout logic and handling of user interactions, providing fine-grained control over component behavior. ```rust use tessera_macros::tessera; use tessera::{ComputedData, Constraints}; #[tessera] fn custom_component() { // Define custom layout behavior measure(Box::new(|_| { // Custom measurement logic use tessera::{ComputedData, Px}; Ok(ComputedData { width: Px(100), height: Px(50), }) })); // Handle user interactions state_handler(Box::new(|_| { // Handle click, key press, etc. events })); } ``` -------------------------------- ### Tessera Component with Measure and State Handler (Rust) Source: https://github.com/shadow3aaa/tessera/blob/main/tessera-ui-macros/README.md Illustrates the use of `measure` and `state_handler` functions within a Tessera component. These functions, injected by the #[tessera] macro, allow for custom layout calculations and event handling logic. ```rust use tessera_macros::tessera; use tessera::{ComputedData, Constraints}; #[tessera] fn custom_component() { // Define custom layout behavior measure(Box::new(|_| { // Custom measurement logic use tessera::{ComputedData, Px}; Ok(ComputedData { width: Px(100), height: Px(50), }) })); // Handle user interactions state_handler(Box::new(|_| { // Handle events like clicks, key presses, etc. })); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.