Skip to content

egui-reactor

Write Rust GUI apps like React!

rust
use egui_reactor::prelude::*;
use egui_reactor_elements::prelude::*;

#[component]
pub fn App(cx: &mut Cx) {
    let mut count = use_state(cx, || 0i32);

    rsx! {
        <View direction="column" align="center" justify="center" gap={12} grow={1.0}>
            <Text size={32.0} strong>{format!("{}", *count)}</Text>
            <View direction="row" gap={8}>
                <Button on_click={|| *count -= 1}>"-"</Button>
                <Button on_click={|| *count = 0}>"reset"</Button>
                <Button on_click={|| *count += 1}>"+"</Button>
            </View>
        </View>
    }
}

Components and hooks

A JSX-like rsx! macro, function components with #[component], and hooks such as use_state, use_effect and use_future — event handlers simply borrow local state with &mut, with no .clone() ceremony.

Flexbox and Grid, first class

<View> is a node in a small layout engine of our own, written over taffy: direction, gap, grow, wrap and grid areas are attributes, not manual measurement.

Native and web

One run(Options, ..) call opens a window natively and takes over a <canvas> in the browser. Every example on this site is running the wasm build.

Released under the MIT or Apache-2.0 license.