Skip to content
FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    Your first application

    Start from the repository’s smallest complete applications. They give you a working platform entry point, theme, and font setup before you add your own features. The primary way to write a FerroUI interface is declarative Rust with ferroui-view; XAML compiled to Rust is the second, equal option, shown at the end of this page.

    Terminal window
    cargo run -p hello-world-hooks

    The window shows a greeting and a button that counts its clicks. The same window is written four more ways in the repository, so you can compare them side by side:

    Sample How the view is written
    hello-world-hooks A component that runs again, with its state in use_signal
    hello-world-builders The generated builders (stack_panel(), button()) and a signal
    hello-world-macros rsx! and a component that runs once, its text following a signal
    hello-world-component-host A component shown inside a XAML window
    hello-world XAML compiled to Rust, with an application class

    Read the sources in samples at the commit associated with these docs.

    Create a binary crate and add ferroui-view with its desktop feature at the same version as any other FerroUI dependency (installation). This main.rs is a complete application:

    use ferroui_view::prelude::*;
    #[component(rerender)]
    fn Counter() -> Element {
    let count = use_signal(|| 0);
    rsx! {
    StackPanel { spacing: 8.0, margin: 16.0,
    TextBlock { text: format!("Clicked {} times", count.get()) }
    Button { on_click: move |_| count.update(|c| *c += 1), "Click" }
    }
    }
    }
    fn main() {
    ferroui_view::launch(|| rsx! { Window { title: "Counter", width: 320.0, height: 160.0, Counter {} } });
    }

    Run it with cargo run and click the button. The pieces:

    • rsx! describes elements: StackPanel { .. } is a control, spacing: 8.0 sets a property, on_click attaches a handler, and "Click" is the button’s content.
    • #[component(rerender)] makes Counter a component that runs again when a signal it read changes. A reconciler then patches the existing controls; the button and the text block stay the same objects.
    • use_signal keeps the count between runs. count.get() reads it and subscribes the component; count.update changes it.
    • launch starts the desktop application with the Fluent theme and makes the Window element its main window. launch_themed takes another theme, as the hello world samples do with the WinUI 3 theme:
    fn main() {
    launch_themed(
    || ferroui_themes_winui::WinUITheme::new().as_style(),
    || window().title("Hello, World!").width(400.0).height(240.0).child(rsx! { Counter {} }).into(),
    |_| {},
    );
    }

    That form needs ferroui-themes-winui as a dependency at the same version.

    Every control has a builder function and a setter per property and event. rsx! expands to these calls, so the two forms mix freely:

    use ferroui_view::prelude::*;
    pub fn counter() -> Element {
    let count = signal(0);
    stack_panel()
    .spacing(8.0)
    .child(text_block().text(move || format!("Clicked {} times", count.get())))
    .child(button().content("Click").on_click(move |_| count.update(|c| *c += 1)))
    .into()
    }

    This function runs once. The text property is given a closure, so it follows the signal by itself: a click updates that one property, and nothing else runs. This is the fine-grained model of SolidJS and Leptos; the component above is the model of React. Builders, rsx! & signals compares them.

    A two-way value connects an editable property to a signal without a change handler:

    use ferroui_view::prelude::*;
    #[component]
    pub fn Greeting() -> Element {
    let name = signal(String::new());
    rsx! {
    StackPanel { spacing: 8.0, margin: 16.0,
    TextBox { placeholder_text: "Your name", text: name.two_way() }
    TextBlock { text: move || format!("Hello, {}!", name.get()) }
    }
    }
    }

    Typing writes into name; the text block follows it. Continue with components and hooks for state, effects, context, and lists.

    XAML is the other way to write the same view. The build compiles markup to Rust, and the result drives the same controls, themes, and bindings:

    <StackPanel xmlns="https://github.com/ferroui"
    Margin="24" Spacing="12">
    <TextBlock Text="Welcome to FerroUI" FontSize="24" />
    <TextBox PlaceholderText="Your name" />
    <Button Content="Continue" />
    </StackPanel>

    The XAML sample separates three responsibilities: program.rs configures platform detection and starts the desktop lifetime; the application class installs resources and a theme; the main window owns its content. Run it with cargo run -p hello-world and read samples/HelloWorld for the entry point, registration, theme, fonts, and build script that the fragment above omits.

    Set a view model as DataContext when the view needs application state. Controls inherit that context through their logical parent, unless you deliberately replace it on a child. Connect a view model and compile or load XAML. A XAML view can host a component and a component can host XAML; see components with XAML.

    Underneath both, controls are framework objects that can also be created and changed imperatively:

    use ferroui_controls::{StackPanel, TextBlock};
    use ferroui_base::Thickness;
    let heading = TextBlock::new();
    heading.set_text(Some("Welcome to FerroUI"));
    heading.set_font_size(24.0);
    let panel = StackPanel::new();
    panel.set_margin(Thickness::uniform(24.0));
    panel.set_spacing(12.0);
    panel.children().add(heading);

    A framework object is held in Ref<T>, a reference-counted handle with the object model’s inheritance and casting behavior. Call upcast() when a containing API expects a base control type. Use this form for infrastructure, custom controls, and integration code.

    A graphics dependency error usually indicates a missing platform toolchain, not an error in your view. A window with invisible controls usually needs a theme or a usable font. A misspelled property in rsx! is a compile error that points at the attribute. A binding that shows nothing requires a data context and correctly registered properties. Start from a known-working sample to isolate each problem.

    Use this small progression to keep the first application understandable:

    1. Run the unchanged sample and confirm that startup and shutdown work.
    2. Replace only the main view’s content with one of the examples above.
    3. Change a label and rebuild to confirm you are editing the code that runs.
    4. Keep the name in a signal (or, in XAML, a view-model property) and bind the text box.
    5. Give Continue a handler or command that reads the name.

    The interactive playground runs XAML in the browser. Run this small view, edit its layout, and download its complete desktop project from the example.

    Arrange a simple flowFerroUI · 0.5.0
    Try it for yourself

    Real controls, running in WebAssembly.
    The runtime downloads when you press Run.

    Shared runtime · 9.8 MB compressed · cached across examples
    Download project
    <StackPanel xmlns="https://github.com/ferroui" Orientation="Horizontal" Spacing="12">
    <Button Content="Back" />
    <Button Content="Continue" />
    <Button Content="Cancel" />
    </StackPanel>
    Ready to explore