Installation
Set up a GPUI app and add your first component.
Create a project
$ cargo new my-app && cd my-appAdd GPUI
Cargo.toml [dependencies] gpui = { git = "https://github.com/zed-industries/zed", rev = "a36d4850f3c087bfef8a3552e2e15d72d97efdf4" } gpui_platform = { git = "https://github.com/zed-industries/zed", rev = "a36d4850f3c087bfef8a3552e2e15d72d97efdf4" }The crates.io release of GPUI lags behind, so hyuskui is tested against a pinned Zed commit. Zed builds with a specific Rust version; pin the same one:
rust-toolchain.toml [toolchain] channel = "1.100.0"Install the CLI
$ cargo install --git https://github.com/hyuskui/ui cargo-hyuskuiAdd the theme
$ cargo hyuskui initOr create
src/theme.rsby hand with this file. It holds every color and radius the components use.src/theme.rs //! Design tokens shared by every hyuskui component. //! //! Install once with `cargo hyuskui init`, then edit freely: the file is yours. // Not every app uses every token. #![allow(dead_code)] use gpui::{hsla, App, Global, Hsla, Pixels, px}; #[derive(Clone, Debug)] pub struct Theme { pub background: Hsla, pub foreground: Hsla, pub card: Hsla, pub card_foreground: Hsla, pub muted: Hsla, pub muted_foreground: Hsla, pub primary: Hsla, pub primary_foreground: Hsla, pub secondary: Hsla, pub secondary_foreground: Hsla, pub accent: Hsla, pub accent_foreground: Hsla, pub destructive: Hsla, pub destructive_foreground: Hsla, pub border: Hsla, pub input: Hsla, pub ring: Hsla, pub radius: Pixels, } impl Global for Theme {} /// HSL helper that takes degrees and percentages, like CSS. fn c(h: f32, s: f32, l: f32) -> Hsla { hsla(h / 360.0, s / 100.0, l / 100.0, 1.0) } impl Theme { pub fn light() -> Self { Self { background: c(0.0, 0.0, 100.0), foreground: c(240.0, 10.0, 4.0), card: c(0.0, 0.0, 100.0), card_foreground: c(240.0, 10.0, 4.0), muted: c(240.0, 5.0, 96.0), muted_foreground: c(240.0, 4.0, 46.0), primary: c(240.0, 6.0, 10.0), primary_foreground: c(0.0, 0.0, 98.0), secondary: c(240.0, 5.0, 96.0), secondary_foreground: c(240.0, 6.0, 10.0), accent: c(240.0, 5.0, 96.0), accent_foreground: c(240.0, 6.0, 10.0), destructive: c(0.0, 72.0, 51.0), destructive_foreground: c(0.0, 0.0, 98.0), border: c(240.0, 6.0, 90.0), input: c(240.0, 6.0, 90.0), ring: c(18.0, 88.0, 54.0), radius: px(8.0), } } pub fn dark() -> Self { Self { background: c(240.0, 10.0, 4.0), foreground: c(0.0, 0.0, 98.0), card: c(240.0, 8.0, 6.0), card_foreground: c(0.0, 0.0, 98.0), muted: c(240.0, 4.0, 16.0), muted_foreground: c(240.0, 5.0, 65.0), primary: c(0.0, 0.0, 98.0), primary_foreground: c(240.0, 6.0, 10.0), secondary: c(240.0, 4.0, 16.0), secondary_foreground: c(0.0, 0.0, 98.0), accent: c(240.0, 4.0, 16.0), accent_foreground: c(0.0, 0.0, 98.0), destructive: c(0.0, 63.0, 50.0), destructive_foreground: c(0.0, 0.0, 98.0), border: c(240.0, 4.0, 16.0), input: c(240.0, 4.0, 16.0), ring: c(18.0, 88.0, 54.0), radius: px(8.0), } } } /// `cx.theme()` from anywhere you hold an `&App`. pub trait ActiveTheme { fn theme(&self) -> &Theme; } impl ActiveTheme for App { fn theme(&self) -> &Theme { self.global::<Theme>() } } /// Call once at startup, before opening a window. pub fn init(cx: &mut App) { cx.set_global(Theme::light()); }Add components
$ cargo hyuskui add button cardEach component is copied to
src/ui/and registered insrc/ui/mod.rs. When copying by hand, register it yourself:// src/ui/mod.rs pub mod button; pub mod card;Use it
src/main.rs mod theme; mod ui; use gpui::{div, prelude::*, px, size, App, Bounds, Context, Window, WindowBounds, WindowOptions}; use theme::ActiveTheme; use ui::button::Button; struct HelloWorld; impl Render for HelloWorld { fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { let theme = cx.theme(); div() .size_full() .flex() .items_center() .justify_center() .bg(theme.background) .child(Button::new("hello", "Hello, hyuskui").on_click(|_, _, _| println!("clicked"))) } } fn main() { gpui_platform::application().run(|cx: &mut App| { theme::init(cx); let bounds = Bounds::centered(None, size(px(480.0), px(320.0)), cx); cx.open_window( WindowOptions { window_bounds: Some(WindowBounds::Windowed(bounds)), ..Default::default() }, |_, cx| cx.new(|_| HelloWorld), ) .unwrap(); }); }$ cargo run
Platform requirements
GPUI runs on macOS (Metal), Linux (Vulkan with X11 or Wayland) and Windows. On macOS you need Xcode and its command line tools. See the GPUI README for the latest system packages on Linux.
If a macOS build fails with metal shader compilation failed, Xcode is missing its Metal toolchain. Install it from Xcode's Components settings, or skip build-time shaders by enabling the runtime_shaders feature on gpui_platform.