FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    ferroui_view

    module · ferroui-view · v0.5.0

    module ferroui_view
    

    ferroui-view

    A declarative way to write FerroUI user interfaces in Rust, without XAML: elements built with chained setters (button().content("Add").on_click(..)) or with the rsx! macro, state held in signals that the properties of controls follow, and children that follow state.

    The pieces (docs/declarative-ui.md has the design):

    • Element: a description of controls, their property values, handlers and children. It is data, compared by value, so that the reconciler can compare two trees and patch controls; mounting makes the controls (Element::mount).
    • Builders: a function per control class (button(), stack_panel()) and a trait per class with a setter per property and a handler per routed event, generated from the sources (scripts/generate_view_builders.py).
    • Reactivity: Signal, Memo, effect, owned by an Owner. A setter given a signal or a closure makes the property follow it.
    • Children that follow state: for_each (keyed), show, dynamic.
    • Components that run again: rerender and #[component(rerender)], with their state in hooks (use_signal, use_effect, ...); the reconciler compares what they return with what they returned before and patches the controls.
    • Patterns of larger applications: futures run by a component (use_future, suspense, sleep), error boundaries (error_boundary()), and navigation between views (router(), route, use_router).
    • With the feature desktop: launch runs an application whose main window is an element.
    use ferroui_view::prelude::*;
    
    fn counter() -> Element {
        let count = signal(0);
        stack_panel()
            .spacing(8.0)
            .child(text_block().text(move || format!("Count: {}", count.get())))
            .child(button().content("Increment").on_click(move |_| count.update(|c| *c += 1)))
            .into()
    }
    

    View source

    Contents

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.