gpui_kit/lib.rs
1//! GPUI Kit: one dependency for building desktop applications with GPUI.
2//!
3//! GPUI itself is published as a family of `gpui-pre-*` crates that move
4//! together. This crate depends on the matching set for you, so an
5//! application lists `gpui-kit` alone. `use gpui_kit::*;` is GPUI, and each
6//! layer is reachable by name:
7//!
8//! | Path | Crate | Feature |
9//! | --------------- | ----------------- | ---------------- |
10//! | `gpui_kit::*` | `gpui` | always |
11//! | [`platform`] | `gpui_platform` | always |
12//! | [`base`] | `gpui-base` | always |
13//! | [`component`] | `gpui-component` | `component` (on) |
14//! | [`assets`] | `gpui-kit-assets` | `assets` (on) |
15//!
16//! [`application`] opens the platform and [`init`] initializes the enabled
17//! layers:
18//!
19//! ```no_run
20//! use gpui_kit::*;
21//!
22//! actions!(hello, [Quit]);
23//!
24//! struct Hello;
25//!
26//! impl Render for Hello {
27//! fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
28//! div().child("Hello, World!")
29//! }
30//! }
31//!
32//! fn main() {
33//! gpui_kit::application().run(|cx| {
34//! gpui_kit::init(cx);
35//! cx.spawn(async move |cx| {
36//! cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| Hello))
37//! .expect("failed to open window");
38//! })
39//! .detach();
40//! });
41//! }
42//! ```
43//!
44//! See [`component`] for the same program with the styled component library.
45
46/// Defines unit actions without requiring consumers to depend on GPUI under the
47/// crate name `gpui`.
48///
49/// GPUI's original macro spells its derive as `gpui::Action`, which does not
50/// resolve when GPUI is consumed solely through this facade.
51#[macro_export]
52macro_rules! actions {
53 ($namespace:path, [ $( $(#[$attr:meta])* $name:ident),* $(,)? ]) => {
54 $(
55 #[derive(
56 ::std::clone::Clone,
57 ::std::cmp::PartialEq,
58 ::std::default::Default,
59 ::std::fmt::Debug,
60 $crate::Action
61 )]
62 #[action(namespace = $namespace)]
63 $(#[$attr])*
64 pub struct $name;
65 )*
66 };
67 ([ $( $(#[$attr:meta])* $name:ident),* $(,)? ]) => {
68 $(
69 #[derive(
70 ::std::clone::Clone,
71 ::std::cmp::PartialEq,
72 ::std::default::Default,
73 ::std::fmt::Debug,
74 $crate::Action
75 )]
76 $(#[$attr])*
77 pub struct $name;
78 )*
79 };
80}
81
82// Public facade decision — 2026-09-08:
83// GPUI Kit is the application-facing entry point. Users should depend on and
84// import gpui-kit without needing to know which GPUI crates implement it.
85// Keep GPUI APIs available through the Kit root and preserve the published
86// #[gpui_kit::test] macro. Do not replace it with Rust's built-in #[test].
87// A future switch to official GPUI crates is an internal dependency migration,
88// not a reason to steer Kit users toward gpui:: paths or require import changes.
89// Keep the existing gpui namespace re-export hidden for source compatibility;
90// it is not the recommended application API.
91//
92// With test-support, the glob below includes GPUI's test macro. Test modules
93// should import their Kit types explicitly to avoid shadowing Rust's #[test].
94pub use ::gpui::*;
95
96#[doc(hidden)]
97pub use ::gpui;
98
99/// UI integration testing: render real components in headless windows, dispatch
100/// pointer and keyboard events, and assert state, focus, layout and callbacks.
101/// Run tests with `#[gpui_kit::test]`; use this module to interact with their UI.
102#[cfg(feature = "test-support")]
103pub mod test;
104
105pub use ::gpui_base as base;
106pub use ::gpui_platform as platform;
107#[cfg(target_family = "wasm")]
108pub use ::gpui_web as web;
109
110/// The styled component library.
111///
112/// ```no_run
113/// use gpui_kit::component::button::*;
114/// use gpui_kit::component::Root;
115/// use gpui_kit::*;
116///
117/// struct Hello;
118///
119/// impl Render for Hello {
120/// fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
121/// div().child(Button::new("ok").primary().label("Let's Go!"))
122/// }
123/// }
124///
125/// fn main() {
126/// gpui_kit::application().run(|cx| {
127/// gpui_kit::init(cx);
128/// cx.spawn(async move |cx| {
129/// cx.open_window(WindowOptions::default(), |window, cx| {
130/// let view = cx.new(|_| Hello);
131/// cx.new(|cx| Root::new(view, window, cx))
132/// })
133/// .expect("failed to open window");
134/// })
135/// .detach();
136/// });
137/// }
138/// ```
139#[cfg(feature = "component")]
140pub use ::gpui_component as component;
141#[cfg(feature = "assets")]
142pub use ::gpui_kit_assets as assets;
143
144pub use ::gpui_platform::application;
145
146/// Initializes every enabled layer. Call it once, before using anything else.
147///
148/// With the `component` feature (on by default) this is
149/// `gpui_component::init`, which also initializes `gpui-base`; otherwise it
150/// is `gpui_base::init`.
151pub fn init(cx: &mut App) {
152 #[cfg(feature = "component")]
153 gpui_component::init(cx);
154 #[cfg(not(feature = "component"))]
155 gpui_base::init(cx);
156}
157
158/// Fluent UI test observation, inert unless `test-support` is enabled.
159pub use gpui_base::TestSupportExt;