Skip to content

gpui-component

Use native controls from gpui-component through GPUI Kit (gpui::component) so your application and its components always share one GPUI engine instance. Try the component binary from Runnable Demos to see Button, Input, and Popover working together.

Depend on gpui-kit aliased as gpui:

Cargo.toml
[dependencies]
gpui = { package = "gpui-kit", version = "=0.10.0" }
gpui-rsx = "0.13.0"

GPUI Kit exports styled controls via gpui::component, unstyled primitives via gpui::base, and icon assets via gpui::assets. Before opening windows, call gpui::init(cx) and mount views with gpui::open_window(...).

2. Constructing Controls: <Tag(...)> vs base={...}

Section titled “2. Constructing Controls: <Tag(...)> vs base={...}”

Pass Type::new(...) arguments directly in parentheses after the tag name:

use gpui::component::button::{Button, ButtonVariants as _};
use gpui::component::Sizable as _;
rsx! {
<Button("save")
label="Save"
small
primary
/>
}
// Expands to:
// Button::new("save").label("Save").small().primary()
  • Uppercase paths expand <Button("save") /> to Button::new("save") and <Tab() /> to Tab::new().
  • Lowercase paths call the function directly (<widget("a") /> → widget("a")).

Use the macro-only base attribute when you already have a builder expression or need component methods whose names collide with GPUI stateful attributes:

// Tab::aria_label is a component builder method, not GPUI's stateful aria_label
rsx! {
<Tab
base={Tab::new().label("Overview").aria_label("Overview tab")}
underline
/>
}

Many gpui-component styling and variant methods (such as .primary() or .small()) live on extension traits. Import them near your RSX view so generated chains type-check cleanly:

use gpui::component::button::{Button, ButtonVariants as _};
use gpui::component::Sizable as _;

If Rust reports mismatched GPUI types between your app and a component, check for duplicate gpui-pre crate instances first:

Terminal window
cargo check --manifest-path demo/Cargo.toml --bins --locked
cargo xtask check-gpui
cargo tree --manifest-path demo/Cargo.toml --locked -i gpui-pre

Commit your Cargo.lock so all contributors resolve the same unified Kit graph.