Coming from egui, Iced or Slint
If you’ve built a GUI in Rust before, most of Ferrokit will feel familiar. Two things are different, and the rest follows from them:
- The views are AppKit’s. A
buttonis anNSButtonand atableis anNSTableView. Ferrokit doesn’t draw widgets, and nothing renders a frame on the GPU. That’s why it’s Mac only, and why VoiceOver, text input, Dark Mode and the system’s tables work without extra code. - Views are built once, then updated in place. egui runs your UI code
every frame and Iced calls
viewafter every message. Ferrokit runs your view code once, when the window opens. The parts that change are closures over signals, and when a signal changes, only the views that read it update.
The same ideas, side by side
| egui | Iced | Slint | Ferrokit | |
|---|---|---|---|---|
| State | fields of your app struct, read each frame | the state struct update changes | propertys in the .slint file | Signal<T>: a Copy handle, read with get(), changed with set/update |
| Events | if ui.button(..).clicked() | a Message enum, matched in update | callbacks (clicked => { .. }) | closures: button("Add", move || ..) |
| Describing the UI | code that runs every frame | view(&self) -> Element, rebuilt after each message | .slint markup | functions returning impl View, run once |
| What changes on screen | everything, every frame | the diff of the new view | bound properties | each view reading a changed signal, and nothing else |
| Layout | ui.horizontal, ui.vertical | row!, column! | HorizontalLayout, VerticalLayout | hstack, vstack, grid, spacer, .padding(..), .frame(..) |
| Lists | a for loop | column(items.iter().map(..)) | for item in items | for_each(items, row), keyed by Identifiable |
| Tables | egui_extras::TableBuilder | table (0.14) | StandardTableView | table(&model): an NSTableView, a million rows |
| Background work | your own threads | Task::perform | spawn_local, threads | spawn, background(..).await in spawn_local, Resource::new |
| Windows | eframe::run_native | iced::application | one component per window | App::new(..).window(Window::new(..)), open(..) |
| Look | Visuals | themes | styles and properties | the system’s, plus .font(..), .color(..), .background(..), .corner_radius(..) |
| Tests | egui_kittest | iced_test | the testing backend | self-checks that drive the real controls (ferrokit::testing) |
One app, four ways
A counter: a label and a button. In egui, the UI is code that runs every
frame, and the button’s result is a bool you test:
struct Counter { count: i32 }
impl eframe::App for Counter {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label(format!("Clicked {} times", self.count));
if ui.button("Click me").clicked() {
self.count += 1;
}
});
}
}
In Iced, a click sends a message, update changes the state, and view
builds the whole tree again:
#[derive(Default)]
struct Counter { count: i32 }
#[derive(Debug, Clone)]
enum Message { Clicked }
impl Counter {
fn update(&mut self, message: Message) {
match message {
Message::Clicked => self.count += 1,
}
}
fn view(&self) -> Element<'_, Message> {
column![
text(format!("Clicked {} times", self.count)),
button("Click me").on_press(Message::Clicked),
]
.padding(20)
.into()
}
}
In Slint, the UI is markup with properties, and Rust code drives it from outside:
export component Counter inherits Window {
in-out property <int> count: 0;
VerticalLayout {
Text { text: "Clicked \{count} times"; }
Button { text: "Click me"; clicked => { count += 1; } }
}
}
In Ferrokit, the state is a signal. The label is given a closure, so it follows the signal, and the button is given the action to run:
use ferrokit::*;
fn main() {
let count = Signal::new(0);
App::new("Counter")
.window(Window::new("Counter").size(320.0, 140.0).view(
vstack((
text(move || format!("Clicked {} times", count.get())),
button("Click me", move || count.update(|n| *n += 1)),
))
.padding(20.0),
))
.run();
}
There’s no Message enum and no update function. A click runs its
closure, the closure changes count, and the one NSTextField that reads
count gets new text. The stack, the button and the window are never
touched again.
A bigger example: a to-do list
Here’s a list you can add to and clear items from, with a count. Where Iced
would have Message::DraftChanged, Message::Add and Message::Remove(id),
here each control gets a signal or a closure:
use ferrokit::*;
#[derive(Clone)]
struct Todo {
id: u32,
title: String,
}
impl Identifiable for Todo {
type Id = u32;
fn id(&self) -> u32 {
self.id
}
}
fn main() {
let todos = Signal::new(Vec::<Todo>::new());
let draft = Signal::new(String::new());
let next_id = Signal::new(1);
// A closure that captures only signals is `Copy`: use it twice.
let add = move || {
let title = draft.get_untracked().trim().to_string();
if title.is_empty() {
return;
}
let id = next_id.get_untracked();
next_id.set(id + 1);
todos.update(|v| v.push(Todo { id, title }));
draft.set(String::new());
};
let list = for_each(move || todos.get(), move |todo: Todo| {
let id = todo.id;
hstack((
text(todo.title),
spacer(),
button("Done", move || todos.update(|v| v.retain(|t| t.id != id))),
))
});
App::new("Todos")
.window(Window::new("Todos").size(360.0, 400.0).view(
vstack((
hstack((
text_field(&draft).placeholder("New to-do").on_submit(add),
button("Add", add).disabled(move || draft.with(|d| d.trim().is_empty())),
)),
scroll(vstack((list,))),
text(move || format!("{} left", todos.with(Vec::len))),
))
.padding(16.0),
))
.run();
}
What to notice, coming from the other toolkits:
text_field(&draft)is bound both ways. Typing changesdraft, anddraft.set(..)changes the field. There’s noon_inputmessage to handle.for_eachkeeps rows by identity. Adding a to-do builds one row, and removing one drops one. The others, theirNSViews included, stay as they are, so a row’s focus or scroll position isn’t lost.get()tracks andget_untracked()doesn’t. Inside a view’s closure (text(move || ..),.disabled(move || ..)),get()subscribes the view to the signal. In an action you just want the value, so useget_untracked().button("Add", add).disabled(..)takes a closure, so the button enables and disables itself asdraftchanges.
Habits to unlearn
- A value isn’t a binding.
text(format!("{}", count.get()))reads the count once, when the window opens, and never changes. Givetexta closure:text(move || format!("{}", count.get())). The same goes for every modifier that takesimpl IntoValue: a plain value is fixed, and a closure follows its signals. - Don’t rebuild views to change them. In Iced the whole tree is rebuilt
after each message; here, building a new view means a new AppKit view.
That’s slow, and it loses focus and selection. Put the changing part in a
closure, or in
dynamic(..)when a whole subtree has to change. - No per-frame loop. Nothing runs unless a signal changes or an event
arrives. For a clock or a live feed,
on_framecalls you once per display frame, and a background thread canspawnits results back. - Main thread only. AppKit is single-threaded, and so are signals and
views. Heavy work goes to
spawnorbackground(..), which hand the result back to the main thread. - Most styling is already done. Controls look and behave as macOS
draws them, in light and Dark Mode, at every text size. Reach for
.font,.color,.backgroundand.corner_radiuswhen you want your own look, not to make a button look like a button.
Where to go next
- State: signals, memos, effects, and async work, in depth.
- Views and layout: stacks, grids, lists and identity.
- Tables, outlines and editors:
what replaces
TableBuilderandStandardTableView. - Testing and shipping: self-checks and getting the app to people.