Expand description
Lemon — reactive native desktop UI in Rust.
§Getting started
Most apps only need run, WindowConfig, Cx, and the layout widgets
(Column, Row, Text, Button, …). Import them via prelude:
use lemon::prelude::*;
fn app(cx: &Cx) -> Element {
let count = cx.use_signal(0i32);
let label = count.clone();
let inc = count.clone();
Column::new()
.children(children![
Text::new(move || label.get().to_string()),
Button::new("+").on_click(move || inc.update(|n| *n += 1)),
])
.into_element()
}
fn main() {
run(WindowConfig::default().title("Counter"), app);
}§How an update flows
- Your root function (
app) returns anelement::Elementtree built with builders. Cx::use_signaland dynamicText::newclosures subscribe to reactive state.- When state changes, the runtime diffs the previous tree against the new one and emits patches.
- The platform layer applies patches to a retained tree, runs layout (Taffy), then paints (Vello).
§Keys and lists
Give stable .key(id) values to siblings that are inserted, removed, or reordered
(see the keys example). Without keys, children are reconciled by index only.
§Components
Component::new wraps a sub-view with its own Cx hooks. It currently takes a function
pointer (fn(&Cx) -> Element), not a capturing closure. For list rows with per-item state,
prefer keyed Row / Column children instead of capturing Components.
§Migrating from Box_
The generic flex container builder was renamed to View (and [Element::View]) because
Box clashes with std::boxed::Box in Rust. Update imports and matches:
| Before | After |
|---|---|
Box_::new() | View::new() |
Element::Box_(…) | Element::View(…) |
use …::{Box_, …} | use …::{View, …} |
Box_ remains available as a deprecated type alias for one release cycle. Roadmap issues
and older examples may still mention Box_; treat that name as View.
§Lower-level API
Runtime, RetainedTree, layout_pass, and paint_pass are public for tests and
custom hosts; normal apps should use run and never touch those directly.
Re-exports§
pub use asset::ImageHandle;pub use element::builders::Button;pub use element::builders::Column;pub use element::builders::Component;pub use element::builders::Row;pub use element::builders::Text;pub use element::builders::View;pub use element::builders::View as Box_;pub use element::events::Cursor;pub use element::events::KeyEvent;pub use element::events::KeyState;pub use element::events::LemonKey;pub use element::events::Modifiers;pub use element::events::NamedKey;pub use element::style::Color;pub use element::style::Overflow;pub use element::style::StyleProps;pub use layout::layout_pass;pub use layout::layout_pass_if_dirty;pub use layout::LayoutMap;pub use layout::LayoutRect;pub use layout::Viewport;pub use paint::paint_pass;pub use paint::PaintStats;pub use platform::run;pub use platform::AppState;pub use platform::WindowConfig;pub use retained::RetainedTree;pub use runtime::cx::Cx;pub use runtime::signal::Signal;pub use runtime::Runtime;pub use debug::Category as DebugCategory;
Modules§
- asset
- debug
- Opt-in verbose tracing for debugging Lemon’s reactive pipeline.
- diff
- element
- layout
- paint
- platform
- Platform layer: winit window, wgpu surface, Vello renderer, and frame loop.
- prelude
- Commonly used types for Lemon applications.
- retained
- runtime
Macros§
- children
- Builds a
Vec<Element>from heterogeneous widget builders. - lemon_
trace - Log with
format!args whencatis enabled.