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.
Run a complete example
Section titled “Run a complete example”cargo run -p hello-world-hooksThe 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.
Write the application in Rust
Section titled “Write the application in Rust”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.0sets a property,on_clickattaches a handler, and"Click"is the button’s content.#[component(rerender)]makesCountera 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_signalkeeps the count between runs.count.get()reads it and subscribes the component;count.updatechanges it.launchstarts the desktop application with the Fluent theme and makes theWindowelement its main window.launch_themedtakes 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.
The same view with the builders
Section titled “The same view with the builders”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.
Add a field
Section titled “Add a field”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.
Write the view in XAML instead
Section titled “Write the view in XAML instead”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.
Create controls directly in Rust
Section titled “Create controls directly in Rust”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.
Troubleshoot the first run
Section titled “Troubleshoot the first run”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.
Connect the pieces
Section titled “Connect the pieces”Use this small progression to keep the first application understandable:
- Run the unchanged sample and confirm that startup and shutdown work.
- Replace only the main view’s content with one of the examples above.
- Change a label and rebuild to confirm you are editing the code that runs.
- Keep the name in a signal (or, in XAML, a view-model property) and bind the text box.
- Give Continue a handler or command that reads the name.
Try the controls
Section titled “Try the controls”The interactive playground runs XAML in the browser. Run this small view, edit its layout, and download its complete desktop project from the example.
Real controls, running in WebAssembly.
The runtime downloads when you press Run.
<StackPanel xmlns="https://github.com/ferroui" Orientation="Horizontal" Spacing="12"> <Button Content="Back" /> <Button Content="Continue" /> <Button Content="Cancel" /></StackPanel>use ferroui::prelude::*;use ferroui::base::metadata::from_markup_value;use ferroui::markup_xaml_loader::FerroRuntimeXamlLoader;
#[repr(C)]pub struct App { base: Application,}
ferro_class!(App: Application);ferro_impl_classes!(App: FerroObjectImpl);
impl NewApplication for App { fn new_application() -> Ref<Self> { instantiate(Self { base: Application::construct() }) }}
impl ApplicationImpl for App { fn initialize(this: &Self) { Self::parent_initialize(this); ferroui::controls::register_types(); FerroRuntimeXamlLoader::register(); this.styles().add(FluentTheme::new().as_style()); }
fn on_framework_initialization_completed(this: &Self) { let lifetime = this.application_lifetime(); if let Some(desktop) = lifetime.as_ref().and_then(|l| l.as_classic_desktop_style_application_lifetime()) { let value = FerroRuntimeXamlLoader::load(include_str!("View.xaml"), None, None, None, false) .expect("Example XAML should load"); let view = from_markup_value::<Ref<Control>>(&Some(value)).expect("Example root must be a control"); let window = Window::new(); window.set_title(Some("FerroUI documentation example".to_owned())); window.set_width(560.0); window.set_height(420.0); window.set_padding(Thickness::uniform(24.0)); window.set_content(Some(Control::boxed(view))); desktop.set_main_window(Some(window)); } Self::parent_on_framework_initialization_completed(this); }}
fn main() -> std::process::ExitCode { let args: Vec<String> = std::env::args().skip(1).collect(); let result = AppBuilder::configure::<App>().use_platform_detect().start_with_classic_desktop_lifetime(&args); std::process::ExitCode::from(result as u8)}Public APIs and controls
Section titled “Public APIs and controls”rsx,component, andElement— declarative composition.signalanduse_signal— state.AppBuilderandApplication— the application model behindlaunchand the XAML sample.- StackPanel, TextBlock, TextBox, and Button — the view.