### WaterUI Quick Start Example Source: https://github.com/water-rs/waterui/blob/dev/core/README.md A basic Rust example demonstrating the creation of a custom view, an application environment, and the root view using waterui-core. ```rust use waterui_core::{View, Environment, binding, Binding}; // Define a custom view fn counter(count: Binding) -> impl View { Dynamic::watch(count, |value| { format!("Count: {}", value) }) } // Create an application environment fn init() -> Environment { Environment::new() } // Define the root view fn main() -> impl View { let count = binding(0); counter(count) } ``` -------------------------------- ### Rust: Quick Start Example Source: https://github.com/water-rs/waterui/blob/dev/utils/color/README.md A concise example demonstrating the basic usage of the `waterui` crate, including creating colors in various spaces, parsing from hex strings, and applying common transformations like opacity, lightening, and desaturation. It also shows color mixing. ```rust use waterui::prelude::*; // Create colors in different color spaces let red = Color::srgb(255, 0, 0); let p3_green = Color::p3(0.0, 1.0, 0.0); let perceptual_blue = Color::oklch(0.6, 0.25, 264.0); // Parse from hex strings let orange = Color::srgb_hex("#FF9800"); // Apply transformations let semi_transparent = Color::srgb_hex("#2196F3").with_opacity(0.5); let lighter = Color::srgb(100, 100, 100).lighten(0.2); let desaturated = Color::oklch(0.7, 0.3, 45.0).desaturate(0.5); // Mix colors let blended = Color::srgb(0, 0, 255).mix(Color::srgb(255, 0, 0), 0.5); ``` -------------------------------- ### WaterUI FFI Initialization and Theme Installation Source: https://github.com/water-rs/waterui/blob/dev/CLAUDE.md Native backends initialize the WaterUI runtime and install theme elements through FFI calls. This includes initializing the environment, installing color schemes, custom colors, and fonts. Legacy theme installation is deprecated. ```c // Initialize runtime, returns Environment pointer waterui_init(); // Theme installation (recommended): // Install color scheme (light/dark) waterui_theme_install_color_scheme(); // Install slot-based colors waterui_theme_install_color(); // Install slot-based fonts waterui_theme_install_font(); // Legacy: deprecated theme installation // waterui_env_install_theme(); ``` -------------------------------- ### Rust: Create a Standard Titled Window Source: https://github.com/water-rs/waterui/blob/dev/examples/multi-window/README.md Demonstrates the creation of a basic titled window with an opaque background and resizable property using WaterUI in Rust. This is a fundamental example for initializing and displaying a window. ```rust Window::new("Window Title", content) .style(WindowStyle::Titled) .background(WindowBackground::Opaque) .resizable(true) .show(env); ``` -------------------------------- ### Run WaterUI Example on iOS and Android Source: https://github.com/water-rs/waterui/blob/dev/examples/picker/README.md Commands to run the WaterUI picker gallery example on iOS and Android simulators using the 'water' command-line tool. No specific dependencies are mentioned beyond the 'water' tool itself. ```bash # iOS Simulator water run --platform ios # Android Emulator water run --platform android ``` -------------------------------- ### Quick Start: WaterUI Application UI Elements Source: https://github.com/water-rs/waterui/blob/dev/components/controls/README.md Demonstrates the basic usage of various WaterUI controls including text fields, steppers, toggles, sliders, and buttons, all bound to reactive variables. This example showcases the declarative UI building style of WaterUI. ```rust use waterui::prelude::*; use waterui::reactive::binding; let name = binding(""); let age = binding(25); let enabled = binding(true); let volume = binding(0.5); vstack(( // Text input with label field("Name", &name), // Numeric stepper stepper(&age).label("Age").range(0..=120), // Boolean toggle toggle("Enabled", &enabled), // Range slider slider(0.0..=1.0, &volume).label("Volume"), // Submit button button("Submit").action(|| { tracing::debug!("Form submitted!"); }), )) ``` -------------------------------- ### Run WaterUI Drag and Drop Example Source: https://github.com/water-rs/waterui/blob/dev/examples/drag-drop/README.md Commands to run the WaterUI drag and drop example on different platforms (iOS, macOS, Android). No external dependencies are required beyond the WaterUI CLI. ```bash water run ios # iOS Simulator water run macos # macOS water run android # Android ``` -------------------------------- ### Create and Run a WaterUI Project on iOS/Android Source: https://github.com/water-rs/waterui/blob/dev/cli/README.md Demonstrates the quick start process for WaterUI projects. It includes creating a new project for multiple platforms and then running it on an iOS simulator. ```bash # Create a new project water create my-app --platform ios,android # Run on iOS Simulator with hot reload cd my-app water run --platform ios # Run on Android water run --platform android ``` -------------------------------- ### Running WaterUI Project with Platform Specification Source: https://github.com/water-rs/waterui/blob/dev/examples/icons/README.md This command-line example shows how to run the WaterUI project for specific platforms using the `water run` command. It illustrates how to target iOS or Android environments. ```bash water run --platform ios # or water run --platform android ``` -------------------------------- ### Plugin System in Rust Source: https://github.com/water-rs/waterui/blob/dev/core/README.md Illustrates the plugin system in waterui. It defines an `AnalyticsPlugin` struct that implements the `Plugin` trait. The `install` method adds the plugin to the environment. An example shows how to initialize and install the plugin. ```rust use waterui_core::{plugin::Plugin, Environment}; struct AnalyticsPlugin { app_id: String, } impl Plugin for AnalyticsPlugin { fn install(self, env: &mut Environment) { env.insert(self); } } let mut env = Environment::new(); AnalyticsPlugin { app_id: "my-app".to_string(), }.install(&mut env); ``` -------------------------------- ### WaterUI CLI Commands Example (Bash) Source: https://github.com/water-rs/waterui/blob/dev/README.md Provides examples of common commands for the `water` command-line interface. These commands facilitate project creation, running the application with hot-reloading, building the Rust library for specific platforms, checking the development environment, and listing available devices. ```bash # Create new project water create --name "My App" --backend apple --backend android # Create playground (auto-configured backends) water create --playground --name my-playground # Run with hot reload water run --platform ios --device "iPhone 15 Pro" water run --platform android # Build Rust library for specific target water build ios water build android # Check development environment water doctor # List available devices water devices ``` -------------------------------- ### Run Image Example on iOS Simulator and Android Source: https://github.com/water-rs/waterui/blob/dev/examples/image/README.md Provides command-line instructions to run the image example on different platforms. It uses the 'water run' command with platform and example flags for iOS Simulator and Android devices/emulators. ```bash # iOS Simulator water run --platform ios --example image # Android Device/Emulator water run --platform android --example image ``` -------------------------------- ### Run Map Example on iOS and macOS Source: https://github.com/water-rs/waterui/blob/dev/examples/map/README.md Commands to run the Map example application on iOS simulator and macOS using the water CLI tool. Ensure you are in the 'examples/map' directory before running. ```bash cd examples/map water ios run # Run on iOS simulator water macos run # Run on macOS ``` -------------------------------- ### Quick Start: Display Photo and Video Player Source: https://github.com/water-rs/waterui/blob/dev/components/media/README.md Demonstrates basic usage of waterui-media by displaying a remote photo and a video player with native controls in a WaterUI view. ```rust use waterui_media::{Photo, VideoPlayer, Url}; use waterui_core::prelude::*; fn main() -> impl View { VStack::new(( // Display a remote photo Photo::new(Url::new("https://example.com/image.jpg")), // Video player with native controls VideoPlayer::new(Url::new("https://example.com/video.mp4")) .show_controls(true), )) } ``` -------------------------------- ### Run WaterUI Filter Example on iOS and Android Source: https://github.com/water-rs/waterui/blob/dev/examples/filter/README.md Command-line instructions to run the WaterUI filter example on an iOS simulator or an Android device/emulator using the 'water run' command. ```bash # iOS Simulator water run --platform ios --example filter # Android Device/Emulator water run --platform android --example filter ``` -------------------------------- ### Create and Run a WaterUI Playground App Source: https://github.com/water-rs/waterui/blob/dev/README.md These bash commands guide you through creating and running a WaterUI playground application. The CLI handles native backend setup, and 'water run' launches the app with hot reload enabled, allowing instant updates on code changes. ```bash cargo install waterui-cli water create --playground --name my-app cd my-app water run ``` -------------------------------- ### Rust: Manage Window State with Handles Source: https://github.com/water-rs/waterui/blob/dev/examples/multi-window/README.md Demonstrates how to manage window state using reactive bindings and window handles in Rust with WaterUI. It covers showing a window, storing its handle, and later closing it programmatically. ```rust let handle = binding(None::); // Show window and save handle let window = Window::new("My Window", content); let new_handle = window.handle(); handle.set(Some(new_handle)); window.show(env); // Close window later if let Some(h) = handle.get() { h.close(); } ``` -------------------------------- ### Run WaterUI Application Source: https://github.com/water-rs/waterui/blob/dev/examples/locale/README.md Commands to run the WaterUI application on iOS or Android platforms. ```bash water run --platform ios # or water run --platform android ``` -------------------------------- ### WaterUI Drag and Drop Usage (Rust) Source: https://github.com/water-rs/waterui/blob/dev/examples/drag-drop/README.md Example code demonstrating how to make a view draggable with text data and how to set up a drop destination to handle received data in WaterUI. Requires the WaterUI framework. ```rust // Make a view draggable text!("Drag me") .draggable(DragData::text("Hello!")); // Create a drop destination text!("Drop here") .drop_destination(|Use(data): Use| { println!("Received: {}", data.as_str()); }); ``` -------------------------------- ### WaterUI Icon Integration with SF Symbols, Material Design, Font Awesome 7, and Native Icons in Rust Source: https://github.com/water-rs/waterui/blob/dev/examples/icons/README.md This Rust code snippet demonstrates how to import and use icons from different libraries within WaterUI. It includes examples for SF Symbols (sf), Material Design Icons (mdi), Font Awesome 7 (fa), and native cross-platform icons (icons). Ensure the respective `waterui-icons-*` crates are added as dependencies. ```rust use waterui_icons_sf_symbol as sf; use waterui_icons_material_icon as mdi; use waterui_icons_fontawesome7 as fa; use waterui_icons_native as icons; // SF Symbols (Apple platforms) sf::HOUSE sf::GEAR // Material Design Icons mdi::home() mdi::settings() // Font Awesome 7 fa::solid::house() fa::brands::github() // Cross-platform native icons icons::HOME icons::SETTINGS ``` -------------------------------- ### Install waterui-media Source: https://github.com/water-rs/waterui/blob/dev/components/media/README.md Add the waterui-media crate to your project's Cargo.toml file to include its media components. ```toml [dependencies] waterui-media = "0.1.0" ``` -------------------------------- ### Check WaterUI Environment Setup Source: https://context7.com/water-rs/waterui/llms.txt Verifies that the development environment is correctly set up for WaterUI development, including necessary tools and SDKs. This command is crucial for ensuring a smooth development workflow. ```bash water doctor ``` -------------------------------- ### Rust: Basic Text Styling Examples Source: https://github.com/water-rs/waterui/blob/dev/components/text/README.md Illustrates various ways to style text components using the waterui-text crate, including bolding, custom sizing, font selection, colors, and background highlights. ```rust use waterui_text::{text, font::{FontWeight, Body}}; use waterui_color::Color; // Simple text text("Plain text") // Bold text with custom size text("Large Title") .bold() .size(32.0) // Custom font and color text("Custom Style") .font(Body) .weight(FontWeight::SemiBold) .foreground(Color::red()) // Text with background text("Highlighted") .background_color(Color::yellow()) .foreground(Color::black()) ``` -------------------------------- ### Basic and Chained Filter Application in Rust Source: https://github.com/water-rs/waterui/blob/dev/examples/filter/README.md Demonstrates how to apply single filters or chain multiple filters sequentially to a view using Rust syntax within the WaterUI framework. Filters include blur, brightness, and opacity. ```rust // Single filter view.blur(5.0) view.brightness(0.2) view.opacity(0.8) // Chained filters view .blur(3.0) .saturation(1.5) .hue_rotation(90.0) ``` -------------------------------- ### Reactive Bindings Example: State Management Source: https://github.com/water-rs/waterui/blob/dev/components/controls/README.md Illustrates the core concept of reactive bindings in WaterUI. It shows how `Binding` allows for two-way data synchronization between UI elements and programmatically updated state, ensuring UI consistency. ```rust let count = binding(0); // UI updates when count changes programmatically count.set(5); // count updates when user interacts with stepper stepper(&count) ``` -------------------------------- ### Installation: Add waterui-form to Cargo.toml Source: https://github.com/water-rs/waterui/blob/dev/components/form/README.md Shows how to include the `waterui-form` crate as a dependency in your Rust project's `Cargo.toml` file. It provides the basic installation command and an example of how to enable the optional `serde` feature for serialization/deserialization support. ```toml [dependencies] waterui-form = "0.1.0" # Optional: enable serde support waterui-form = { version = "0.1.0", features = ["serde"] } ``` -------------------------------- ### WaterUI Core Entry Points Source: https://github.com/water-rs/waterui/blob/dev/ffi/README.md This section lists the primary API functions for initializing and managing the WaterUI runtime environment. `waterui_init()` sets up the runtime and returns an environment pointer, while `waterui_app(env)` creates the application. `waterui_env_new()` provides an alternative way to create an environment, and `waterui_clone_env(env)` allows for duplicating environments for use in child contexts. ```text - `waterui_init()` - Initialize runtime and return Environment - `waterui_app(env)` - Create application from user's app() function - `waterui_env_new()` - Create new Environment (alternative to init) - `waterui_clone_env(env)` - Clone Environment for child contexts ``` -------------------------------- ### Manage Loading States with Progress Bars and Spinners in Rust Source: https://github.com/water-rs/waterui/blob/dev/components/controls/README.md Demonstrates how to implement loading indicators in a WaterUI application. The example includes a progress bar that displays a float value, an indeterminate loading spinner that can be toggled on/off, and control buttons to simulate starting and stopping the loading process. Reactive bindings are used to control the visibility and progress values. ```rust use waterui::prelude::*; use waterui::reactive::binding; let progress = binding(0.0); let is_loading = binding(false); vstack(( // Progress bar progress(progress.clone()), // Indeterminate loading spinner loading().visible(is_loading.clone()), // Control buttons hstack(( button("Start").action_with(&is_loading, |loading| { loading.set(true); }), button("Stop").action_with(&is_loading, |loading| { loading.set(false); }), )), )) ``` -------------------------------- ### Create a New WaterUI Project using CLI Source: https://context7.com/water-rs/waterui/llms.txt This section provides command-line instructions for creating a new WaterUI project. It covers installing the WaterUI CLI, creating a project with specified backends (e.g., Apple, Android), and setting up a playground project. This is for setting up a project structure. ```bash # Install CLI car go install waterui-cli # Create project with specific backends water create --name "MyApp" --backend apple --backend android # Create playground (auto-configured backends) water create --playground --name my-playground cd my-playground ``` -------------------------------- ### WaterUI Application Entry Point Example (Rust) Source: https://github.com/water-rs/waterui/blob/dev/README.md Demonstrates the standard pattern for a WaterUI application's entry point in Rust. It includes initialization of the environment, defining the root view, and setting up the application with custom environment configurations. The `waterui_ffi::export!()` macro is crucial for native backend integration. ```rust use waterui::prelude::*; use waterui::app::App; // Initialize environment (called once at app startup) pub fn init() -> Environment { Environment::new() } // Root view (called on every render) pub fn main() -> impl View { text("Your app content here") } // Alternative: App with custom environment setup pub fn app(mut env: Environment) -> App { // Install plugins, themes, etc. env.install(Theme::new().color_scheme(ColorScheme::Dark)); App::new(main, env) } // Export FFI entry points for native backends waterui_ffi::export!(); ``` -------------------------------- ### WaterUI Application Entry Point Pattern Source: https://github.com/water-rs/waterui/blob/dev/CLAUDE.md Applications are initialized by creating an 'Environment' and then defining the root view returned by the 'main' function. The 'waterui_ffi::export!()' macro generates the necessary FFI entry points for native integration. ```rust pub fn init() -> Environment { Environment::new() } pub fn main() -> impl View { // Return your root view } waterui_ffi::export!(); // Generates FFI entry points ``` -------------------------------- ### Toolchain Dependency Checking and Installation Trait (Rust) Source: https://github.com/water-rs/waterui/blob/dev/cli/README.md Defines traits for managing development toolchains. `Toolchain` handles checking for dependencies and generating installation plans, while `Installation` defines the process for executing those plans. This system is designed to be extensible for different platforms like Apple and Android. ```Rust pub trait Toolchain: Send + Sync { type Installation: Installation; fn check(&self) -> impl Future>> + Send; } pub trait Installation: Send + Sync { type Error: Into + Send; fn install(&self) -> impl Future> + Send; } ``` -------------------------------- ### Install waterui-cli using Cargo Source: https://github.com/water-rs/waterui/blob/dev/cli/README.md Installs the waterui-cli from source within the WaterUI workspace using Cargo. This command ensures the CLI is available for use in your projects. ```bash cargo install --path cli ``` -------------------------------- ### URL Handling Examples Source: https://github.com/water-rs/waterui/blob/dev/components/media/README.md Illustrates various ways to define and parse URLs for media resources using waterui_url::Url, including compile-time web URLs and runtime parsing for local files and data URLs. ```rust use waterui_media::Url; // Compile-time web URLs const REMOTE: Url = Url::new("https://cdn.example.com/video.mp4"); // Runtime parsing let local: Url = "/path/to/video.mp4".parse().unwrap(); let data_url = Url::from_data("image/png", image_bytes); ``` -------------------------------- ### Rust Code Block Example Source: https://github.com/water-rs/waterui/blob/dev/examples/markdown/src/example.md Demonstrates a basic Rust program outputting a message. This is an example of how code blocks are rendered within WaterUI's Markdown support. ```rust fn main() { println!("Hello, WaterUI!"); } ``` -------------------------------- ### WaterUI Native Backend Initialization Sequence Source: https://github.com/water-rs/waterui/blob/dev/ffi/README.md This sequence outlines the mandatory steps for initializing a native WaterUI backend. It begins with `waterui_init()`, followed by optional theme installations, then `waterui_app(env)` to create the application. The final step details the render loop, including identifying view types and extracting native data or recursively processing composite views. ```text ┌─────────────────────────────────────────────────────────────────────┐ │ 1. waterui_init() │ │ - Initializes panic hooks and global executors │ │ - Returns an Environment pointer │ │ - MUST be called first before any other waterui_* functions │ ├─────────────────────────────────────────────────────────────────────┤ │ 2. Theme installation (recommended) │ │ - Install appearance: waterui_theme_install_color_scheme() │ │ - Install colors: waterui_theme_install_color() │ │ - Install fonts: waterui_theme_install_font() │ │ - Legacy: waterui_env_install_theme() is deprecated │ ├─────────────────────────────────────────────────────────────────────┤ │ 3. waterui_app(env) │ │ - Creates the application from user's app(env) function │ │ - Returns WuiApp with windows and environment │ │ - MUST be called AFTER waterui_init() and theme installation │ ├─────────────────────────────────────────────────────────────────────┤ │ 4. Render Loop (for each view) │ │ a. waterui_view_id(view) → Get the type ID │ │ b. Check if it's a "raw view" (Text, Button, etc.) │ │ - If raw: waterui_force_as_*(view) → Extract native data │ │ - If composite: waterui_view_body(view, env) → Get body view │ │ c. Render the native widget or recurse into body │ └─────────────────────────────────────────────────────────────────────┘ ``` -------------------------------- ### Generated FFI Entry Points for waterui-ffi Source: https://github.com/water-rs/waterui/blob/dev/ffi/README.md These are the C ABI-compatible functions automatically generated by the `waterui_ffi::export!()` macro. `waterui_init` initializes the WaterUI runtime and environment, returning a pointer to the environment. `waterui_app` takes the environment pointer, calls the user-defined `app` function to create the application's view tree, and returns it in an FFI-compatible format. ```rust #[no_mangle] pub unsafe extern "C" fn waterui_init() -> *mut WuiEnv { // Initialize runtime, logging, executors let env = waterui::Environment::new(); env.into_ffi() } #[no_mangle] pub unsafe extern "C" fn waterui_app(env: *mut WuiEnv) -> WuiApp { let env = env.into_rust(); let app = app(env); // Call your app() function app.into_ffi() } ``` -------------------------------- ### Rust Canvas Drawing with Gradient Example Source: https://github.com/water-rs/waterui/blob/dev/components/graphics/README.md An example of creating a Canvas drawing function that fills a circle with a linear gradient. It uses kurbo for the circle shape and peniko for defining the gradient and colors. ```rust use waterui::graphics::Canvas; use waterui::graphics::kurbo::Circle; use waterui::graphics::peniko::{Brush, Color, Gradient}; Canvas::new(|ctx| { let gradient = Gradient::new_linear((0.0, 0.0), (ctx.width as f64, ctx.height as f64)) .with_stops([ (0.0, Color::new([1.0, 0.2, 0.2, 1.0])), (1.0, Color::new([0.2, 0.2, 1.0, 1.0])), ]); ctx.fill_brush( Circle::new(ctx.center(), 100.0), &Brush::Gradient(gradient), ); }) ``` -------------------------------- ### Bash: Run WaterUI Applications on Different Platforms Source: https://github.com/water-rs/waterui/blob/dev/examples/multi-window/README.md Provides commands to run WaterUI applications on various platforms, including iOS simulators, Android emulators, and macOS native builds. This is essential for testing and deploying applications. ```bash # iOS Simulator water run --platform ios # Android Emulator water run --platform android # macOS (native) water run --platform macos ``` -------------------------------- ### Combine Multiple GPU Filters on Image Component Source: https://github.com/water-rs/waterui/blob/dev/examples/image/README.md Demonstrates chaining multiple GPU filters on an Image component created from pixel data. This example applies blur, saturation, and vignette filters sequentially to achieve a combined visual style. ```rust let pixels: Vec = generate_pattern(width, height); Image::new(pixels, 200, 150) .blur(2.0) .saturation(1.3) .vignette(0.6, 0.4) ``` -------------------------------- ### Rust: Create a Window with Custom Color Background Source: https://github.com/water-rs/waterui/blob/dev/examples/multi-window/README.md Shows how to create a window with a custom semi-transparent blue background (85% opacity) using WaterUI in Rust. This highlights the ability to define specific color properties for window backgrounds. ```rust let color = Color::srgb_f32(0.2, 0.4, 0.8).with_alpha(0.85); Window::new("Colored Window", content) .background(WindowBackground::Color(color)) .show(env); ``` -------------------------------- ### Rust Application Entry Point with FFI Export Source: https://github.com/water-rs/waterui/blob/dev/ffi/README.md This snippet demonstrates how to define a WaterUI application and export it using the `waterui_ffi::export!()` macro. This macro generates the necessary C ABI entry points (`waterui_init` and `waterui_app`) that native backends call to initialize and run the Rust application. The `app` function defines the application's UI, and `main` provides the root view. ```rust use waterui::prelude::*; use waterui::app::App; // Your application entry point pub fn app(env: Environment) -> App { App::new(main, env) } fn main() -> impl View { text("Hello, WaterUI!") } // This macro generates waterui_init() and waterui_app() FFI entry points waterui_ffi::export!(); ``` -------------------------------- ### Configure Tabbed Interface with Independent Stacks in WaterUI Source: https://github.com/water-rs/waterui/blob/dev/components/navigation/README.md Provides an example of creating a tabbed interface where each tab hosts an independent navigation stack. This is achieved using the `Tabs` and `Tab` components from `waterui_navigation`. The `selection` binding controls the active tab. This example requires `waterui` and `waterui_navigation`. ```rust use waterui::prelude::*; use waterui_navigation::tab::{Tab, Tabs, TabPosition}; fn main_tabs() -> impl View { let selection = binding(Id::from(0)); Tabs { selection: selection.clone(), position: TabPosition::Bottom, tabs: vec![ Tab::new( TaggedView::new(Id::from(0), text("Feed").anyview()), || NavigationView::new("Feed", feed_view()) ), Tab::new( TaggedView::new(Id::from(1), text("Search").anyview()), || NavigationView::new("Search", search_view()) ), Tab::new( TaggedView::new(Id::from(2), text("Profile").anyview()), || NavigationView::new("Profile", profile_view()) ), ], } } ``` -------------------------------- ### Rust: Create Basic WaterUI Application Source: https://context7.com/water-rs/waterui/llms.txt Demonstrates the entry point pattern for a basic WaterUI application using FFI export. It defines a main function that returns a View and exports FFI entry points for native backends. ```rust use waterui::prelude::*; use waterui::app::App; #[hot_reload] fn main() -> impl View { vstack(( text("Hello, WaterUI!").size(24.0).bold(), text("Build native UIs with Rust"), )) .spacing(12.0) .padding() } pub fn app(env: Environment) -> App { App::new(main, env) } // Export FFI entry points for native backends waterui_ffi::export!(); ``` -------------------------------- ### Create and Run a WaterUI Playground Source: https://github.com/water-rs/waterui/blob/dev/cli/README.md Shows how to create a WaterUI playground for quick experimentation. Playgrounds are automatically managed for backends and can be run on iOS. ```bash water create --playground --name my-experiment cd my-experiment water run --platform ios ``` -------------------------------- ### Syntax Highlighting Example Source: https://github.com/water-rs/waterui/blob/dev/components/text/README.md Demonstrates how to use the `highlight_text` function for asynchronous syntax highlighting of code snippets. ```APIDOC ## Syntax Highlighting Example ### Description This example shows how to use the `highlight_text` function to asynchronously highlight a code snippet with syntax support. ### Method N/A (This is a usage example, not a direct API endpoint call) ### Endpoint N/A ### Parameters None ### Request Example ```rust use waterui_text::highlight::{DefaultHighlighter, Language, highlight_text}; use waterui_core::Str; // Create highlighter let highlighter = DefaultHighlighter::new(); // Highlight code asynchronously let code = Str::from("fn main() { println!(\"Hello\"); }"); let highlighted = highlight_text(Language::Rust, code, highlighter).await; ``` ### Response #### Success Response (200) N/A (This is a code example, not an API response) #### Response Example N/A ``` -------------------------------- ### Install waterui-core Crate Source: https://github.com/water-rs/waterui/blob/dev/core/README.md This snippet shows how to add the waterui-core crate as a dependency to your Rust project's Cargo.toml file. ```toml [dependencies] waterui-core = "0.1.0" ``` -------------------------------- ### Rust: Implementing Device Trait for New Device Types Source: https://github.com/water-rs/waterui/blob/dev/cli/CLAUDE.md Demonstrates how to add a new device type by creating a struct and implementing the Device trait. The launch method handles starting the device process, and the run method can delegate to an inner device. This enables seamless integration of new hardware or emulators. ```rust pub struct AndroidEmulator { avd_name: String, device: OnceLock // Set after launch } impl Device for AndroidEmulator { async fn launch(&self) -> Result<()> { // Start emulator process // Wait for it to boot (poll adb devices) // Store resulting AndroidDevice in self.device } async fn run(&self, artifact, options) -> Result { // Delegate to the inner AndroidDevice self.device.get().unwrap().run(artifact, options).await } } ``` -------------------------------- ### Native Integration API Source: https://github.com/water-rs/waterui/blob/dev/examples/locale/README.md Demonstrates how native backends can inject the system locale into WaterUI using Foreign Function Interface (FFI). ```APIDOC ## Native Integration API ### Description This API allows native backends to set the system locale for WaterUI applications using FFI. ### Method FFI Calls ### Endpoint N/A (FFI calls) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c // Using the predefined enum waterui_env_install_locale(env, WuiLocale_ZhCn); // Or using a BCP 47 string waterui_env_install_locale_string(env, "zh-Hans-CN"); ``` ### Response #### Success Response N/A (FFI calls do not typically return values in this context) #### Response Example N/A ``` -------------------------------- ### Install waterui-text Dependency Source: https://github.com/water-rs/waterui/blob/dev/components/text/README.md Instructions for adding the waterui-text crate to your project's Cargo.toml file, or using the main WaterUI crate which re-exports text components. ```toml [dependencies] waterui-text = "0.1.0" ``` ```toml [dependencies] waterui = "0.2" ``` -------------------------------- ### Rust: Create a Window with Material Blur Background Source: https://github.com/water-rs/waterui/blob/dev/examples/multi-window/README.md Illustrates how to create a window with a frosted glass effect using a 'Regular' material blur background in Rust with WaterUI. This showcases the use of dynamic background effects for aesthetic purposes. ```rust Window::new("Frosted Glass", content) .style(WindowStyle::Titled) .background(WindowBackground::Material(Material::Regular)) .show(env); ``` -------------------------------- ### Swift Code Block Example Source: https://github.com/water-rs/waterui/blob/dev/examples/markdown/src/example.md Shows a simple SwiftUI view structure in Swift. This illustrates the rendering of Swift code blocks within WaterUI's Markdown. ```swift import SwiftUI struct ContentView: View { var body: some View { Text("Hello, World!") } } ``` -------------------------------- ### Basic App Navigation Setup with WaterUI Source: https://github.com/water-rs/waterui/blob/dev/components/navigation/README.md Sets up a basic navigation structure for a WaterUI application using NavigationStack and NavigationView. This is the entry point for defining the initial view hierarchy. ```rust use waterui::prelude::*; use waterui_navigation::{NavigationView, NavigationStack}; pub fn main() -> impl View { NavigationStack::new( NavigationView::new("Home", vstack(( text("Welcome to the app"), // Navigation content here )) ) ) } ``` -------------------------------- ### Compile-time and Runtime URL Parsing in Rust Source: https://github.com/water-rs/waterui/blob/dev/utils/url/README.md Demonstrates creating URLs at compile time with validation using `Url::new()` and parsing URLs at runtime using `.parse().unwrap()`. It shows how to extract components like host, path, and query from a parsed URL. ```rust use waterui_url::Url; // Compile-time URL creation with validation const API_ENDPOINT: Url = Url::new("https://api.example.com/v1/users"); const LOCAL_ASSET: Url = Url::new("/assets/logo.png"); fn main() { // Runtime parsing let url: Url = "https://example.com/api?key=value".parse().unwrap(); println!("Host: {:?}", url.host()); // Some("example.com") println!("Path: {}", url.path()); // "/api" println!("Query: {:?}", url.query()); // Some("key=value") } ``` -------------------------------- ### Rust Binding (Read/Write Reactive State) Example Source: https://github.com/water-rs/waterui/blob/dev/ffi/README.md Demonstrates how to create and manage reactive integer state in Rust using the `Binding` type. It shows the generated FFI functions for reading, setting, and watching these bindings, which can be used by native code. ```rust // Rust side let counter = Binding::int(42); // FFI functions generated by ffi_binding! macro: // - waterui_read_binding_i32(binding) -> i32 // - waterui_set_binding_i32(binding, value) // - waterui_watch_binding_i32(binding, watcher) -> guard // - waterui_drop_binding_i32(binding) ```