WaterUI

repository·dev·Indexed 19 days ago

https://github.com/water-rs/waterui

A native-first, fine-grained reactive UI framework for Rust (v0.2.1). It enables semantic application descriptions realized via native platform primitives (UIKit, Android View, GTK4) or shared renderers like Hydrolysis and Dew. Features include a dedicated CLI for project scaffolding and device management, a GPU-driven particle system, and an embedded-first CPU rendering backend (Dew) utilizing sparse rasterization for microcontrollers.

Tokens
150.2K
Snippets
555
Records
806
Agent score
66%

What's inside waterui

  1. Overview of waterui-dew rendering backend

    dev

    Dew is an embedded-first CPU rendering backend for WaterUI designed for microcontrollers. It provides anti-aliased vector UI without requiring a GPU or a full-resolution framebuffer.

    Key technical characteristics:

    • Sparse Rasterization: Uses vello_cpu to perform sparse-strip rasterization.
    • Memory Discipline: Uses WaterUI's fine-grained reactivity to identify changed views and dirty screen regions. Only dirty regions are re-rasterized in small slices (bands) no taller than band_height rows.
    • Band-based Streaming: Rasterized bands are streamed to the panel (e.g., via SPI/QSPI), which avoids the bandwidth limitations of full-frame transfers.
    • Input Handling: DewRuntime routes retained pointer input to interactive controls like buttons, toggles, sliders, and steppers without rebuilding the view bodies.
  2. Overview of waterui-assets

    dev

    The waterui-assets crate provides the runtime primitives for managing assets within WaterUI applications. It handles typed asset values for various use cases, including small data files, large memory-mapped files, and remote downloads. While build-time discovery is handled by companion tooling, waterui-assets is used at runtime to interact with these assets.

    Key capabilities include:

    • Small Data: Loading small binary resources into memory.
    • Large Files: Memory-mapping large files (e.g., 3D models or media blobs) for efficient access.
    • Classification: Categorizing assets by their file extension using AssetKind.
    • Remote Assets: Helpers for downloading remote assets with atomic writes to ensure cache integrity.
  3. Overview of waterui-video semantic components

    dev
    The waterui-video crate provides semantic video abstractions for WaterUI. It manages the logic and state of video playback—including playback state, sources, playlists, tracks, events, policies, and accessibility—without being tied to a specific decoder or GPU renderer. This separation allows for efficient tree-shaking in applications that only require native platform bridges (like Apple's AVPlayer) without pulling in heavy rendering dependencies.
  4. Picker Components in WaterUI

    dev

    The Picker Gallery demonstrates several specialized selection components available in WaterUI. These components use reactive bindings for their values and render platform-native UI.

    DatePicker

    Supports various temporal selection modes:

    • Date-only selection
    • Time-only selection (hour and minute)
    • Combined date and time selection
    • Date range constraints

    ColorPicker

    Supports color selection with the following capabilities:

    • Standard RGB color selection
    • Alpha channel support
    • HDR color support (available on iOS 14+)

    FilePicker

    Supports file system interactions:

    • Single file selection
    • Multiple file selection
    • File import mode
  5. WaterUI Internationalization (i18n) Features

    dev

    WaterUI provides built-in support for internationalization, including:

    • Locale-aware date formatting: Dates automatically follow regional conventions.
    • CLDR plural rules: Support for complex pluralization rules (e.g., handling the one/few/many distinctions in Russian).
    • Unit formatting: Localized unit symbols (e.g., m vs メートル vs ).
    • Number formatting: Regional number separators and decimal conventions.

    Supported Locales

    CodeLanguage
    enEnglish
    zh-CNChinese (Simplified)
    jaJapanese
    koKorean
    deGerman
    frFrench
    esSpanish
    ruRussian
  6. Use waterui-locale for localization support

    dev
    The waterui-locale crate provides the foundation for localization in WaterUI applications. It handles locale identifiers, CLDR plural category selection, translation catalogs, and regional formatting for dates, lists, lengths, masses, and temperatures. It is designed to integrate with WaterUI environments to resolve content from either an explicit locale context or runtime regional settings.
  7. Use `waterui-image` for GPU-backed image views

    dev

    The waterui-image crate provides GPU-backed image views and shared image decoding helpers for WaterUI applications. It is the centralized location for image handling, replacing the previous implementation in waterui-media.

    Key capabilities include:

    • GPU-backed views: Efficient rendering of images using the GPU.
    • Smart decoding: Automatic selection between platform-native decoding paths and software decoding paths.
    • Container bridging: Support for HEIF and AVIF containers via software decoders.
  8. Use the waterui-particle GPU particle system

    dev

    The waterui-particle package provides a high-performance GPU-driven particle system designed for WaterUI. It utilizes Compute Shaders for GPU-first simulation, making it suitable for complex effects like rain, fire, or glow.

    Key capabilities include:

    • Simulation: GPU-first via Compute Shaders.
    • Visuals: HDR color support (Linear sRGB), motion blur (ideal for rain), and additive blending (ideal for fire/glow).
    • Interactivity: Pure-GPU bounds and multi-circle obstacle collision, featuring configurable bounce and surface friction controls.
    • API Style: Uses an ergonomic flat modifier-chain API for configuration.
  9. Use Reactive Primitives for fine-grained updates

    dev

    WaterUI uses the nami library for reactivity. Instead of rebuilding the entire view tree, signal-aware inputs allow the framework to update only the specific leaf nodes that change.

    Key reactive types:

    • Binding<T>: Mutable reactive state.
    • Computed<T>: Derived reactive values.
    • Signal<T>: Read-only reactive values.
    • SignalExt: Extension methods for reactive types.
    use waterui::prelude::*;
    
    // Create reactive state
    let count: Binding<i32> = binding(0);
    
    // Signal-aware inputs update the exact text leaf.
    let counter_view = text!("Count: {count}");
    
    // Updating the binding automatically updates the view
    count.set(5);
  10. Use logical pixels for design-accurate layouts

    dev

    All layout values in waterui-layout use logical pixels (points/dp). This matches design tools like Figma, Sketch, and Adobe XD, ensuring pixel-perfect implementation across platforms:

    • spacing(8.0) corresponds to 8pt in design tools.
    • width(100.0) corresponds to 100pt/dp.

    Native backends handle the density-aware conversion to physical pixels (e.g., converting dp to pixels on Android via displayMetrics.density).