Skip to content
PorabuildHeroGPUI component library
v0.14.0 · Apache-2.0

Quick Start

Create a Rust binary, add HeroGPUI, and put a button on a themed window.

You need a Rust toolchain that supports Rust 1.98. GPUI itself is not a dependency you add: herogpui depends on the published gpui-pre crates (0.3.5) and re-exports them, so use herogpui::*; is GPUI. The unrelated crates.io gpui 0.2.2 crate will not compile against this library.

1. Create the app

Shell
cargo new hello-herogpui --bin
cd hello-herogpui

2. Add the crate

One dependency, and only one. Paste this into Cargo.toml. If you cloned HeroGPUI next to the app, you can swap the herogpui line for herogpui = { path = "../HeroGPUI/crates/herogpui" }.

Cargo.toml
[dependencies]
herogpui = "0.14"

3. Open a window

Replace src/main.rs. herogpui::init must run before the first window, and app_focus_root turns on Tab and focus rings.

src/main.rs
use herogpui::*;

struct MyRoot;

impl Render for MyRoot {
    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
        app_focus_root(
            div()
                .size_full()
                .flex()
                .items_center()
                .justify_center()
                .bg(cx.colors().background)
                .text_color(cx.colors().foreground)
                .child(Button::new("hello").label("Click me")),
            window,
            cx,
        )
    }
}

fn main() {
    application()
        .with_assets(HeroGpuiAssets)
        .run(|cx: &mut App| {
            herogpui::init(cx);
            let bounds = Bounds::centered(None, size(px(480.), px(320.)), cx);
            cx.open_window(
                WindowOptions {
                    window_bounds: Some(WindowBounds::Windowed(bounds)),
                    ..Default::default()
                },
                |_, cx| cx.new(|_| MyRoot),
            )
            .unwrap();
        });
}

4. Run it

Shell
cargo run

You should get a small window with a primary button. From here, open the Button page or the desktop gallery.

What the other guide is for

Installation covers assets, custom themes, platform packages, and the gallery CLI. Use it after this window works.