docs/docs/index.md
GPUI Component is a Rust UI component library for building fantastic desktop applications using GPUI.
GPUI Component is a comprehensive UI component library for building fantastic desktop applications using GPUI. It provides 60+ cross-platform components with modern design, theming support, and high performance.
RenderOnce components, simple and user-friendlyTheme and ThemeColor, supporting multi-themexs, sm, md, and lgAdd gpui and gpui-component to your Cargo.toml:
[dependencies]
gpui = "{{ VERSION }}"
gpui-component = "{{ VERSION }}"
Then create a simple "Hello, World!" application with a button:
use gpui::*;
use gpui_component::{button::*, *};
pub struct HelloWorld;
impl Render for HelloWorld {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
div()
.v_flex()
.gap_2()
.size_full()
.items_center()
.justify_center()
.child("Hello, World!")
.child(
Button::new("ok")
.primary()
.label("Let's Go!")
.on_click(|_, _, _| println!("Clicked!")),
)
}
}
fn main() {
let app = Application::new();
app.run(move |cx| {
// This must be called before using any GPUI Component features.
gpui_component::init(cx);
cx.spawn(async move |cx| {
cx.open_window(WindowOptions::default(), |window, cx| {
let view = cx.new(|_| HelloWorld);
// This first level on the window, should be a Root.
cx.new(|cx| Root::new(view, window, cx))
})
.expect("Failed to open window");
})
.detach();
});
}
Apache-2.0