1#![doc = include_str!("../README.md")]
2#![deny(missing_docs)]
3#![allow(clippy::type_complexity)] #![allow(clippy::collapsible_else_if)] #![allow(unused_mut)] extern crate self as gpui;
8
9#[doc(hidden)]
11pub const GPUI_MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
12
13#[macro_use]
14mod action;
15mod app;
16
17mod arena;
18mod asset_cache;
19mod assets;
20mod bounds_tree;
21mod color;
22pub mod colors;
24mod element;
25mod elements;
26mod executor;
27mod geometry;
28mod global;
29mod input;
30mod inspector;
31mod interactive;
32mod key_dispatch;
33mod keymap;
34mod path_builder;
35mod platform;
36pub mod prelude;
37#[doc(hidden)]
38pub mod profiler;
39mod resource_profile;
40mod scene;
41mod shared_string;
42mod shared_uri;
43mod spring;
44mod style;
45mod styled;
46mod subscription;
47mod svg_renderer;
48mod tab_stop;
49mod taffy;
50#[cfg(any(test, feature = "test-support"))]
51pub mod test;
52mod text_system;
53mod util;
54mod view;
55mod window;
56
57#[cfg(doc)]
58pub mod _accessibility;
59#[cfg(doc)]
60pub mod _ownership_and_data_flow;
61
62#[doc(hidden)]
64pub mod private {
65 pub use anyhow;
66 pub use inventory;
67 pub use schemars;
68 pub use serde;
69 pub use serde_json;
70}
71
72mod seal {
73 pub trait Sealed {}
76}
77
78pub use accesskit;
79pub use accesskit::Action as AccessibleAction;
80pub use accesskit::{Orientation, Role, Toggled};
81pub use action::*;
82pub use anyhow::Result;
83pub use app::*;
84pub(crate) use arena::*;
85pub use asset_cache::*;
86pub use assets::*;
87pub use color::*;
88pub use ctor::ctor;
89pub use element::*;
90pub use elements::*;
91pub use executor::*;
92pub use geometry::*;
93pub use global::*;
94pub use gpui_macros::{AppContext, IntoElement, Render, VisualContext, register_action, test};
95pub use http_client;
96pub use input::*;
97pub use inspector::*;
98pub use interactive::*;
99use key_dispatch::*;
100pub use keymap::*;
101pub use path_builder::*;
102pub use platform::*;
103pub use refineable::*;
104pub use resource_profile::*;
105pub use scene::*;
106pub use shared_string::*;
107pub use shared_uri::*;
108pub use smol::Timer;
109pub use spring::*;
110pub use style::*;
111pub use styled::*;
112pub use subscription::*;
113use svg_renderer::*;
114pub(crate) use tab_stop::*;
115pub use taffy::{AvailableSpace, LayoutId};
116#[cfg(any(test, feature = "test-support"))]
117pub use test::*;
118pub use text_system::*;
119#[cfg(any(test, feature = "test-support"))]
120pub use util::smol_timeout;
121pub use util::{FutureExt, Timeout, arc_cow::ArcCow};
122pub use view::*;
123pub use window::*;
124
125use std::{any::Any, borrow::BorrowMut, future::Future};
126use taffy::TaffyLayoutEngine;
127
128pub trait AppContext {
131 type Result<T>;
134
135 #[expect(
137 clippy::wrong_self_convention,
138 reason = "`App::new` is an ubiquitous function for creating entities"
139 )]
140 fn new<T: 'static>(
141 &mut self,
142 build_entity: impl FnOnce(&mut Context<T>) -> T,
143 ) -> Self::Result<Entity<T>>;
144
145 fn reserve_entity<T: 'static>(&mut self) -> Self::Result<Reservation<T>>;
148
149 fn insert_entity<T: 'static>(
153 &mut self,
154 reservation: Reservation<T>,
155 build_entity: impl FnOnce(&mut Context<T>) -> T,
156 ) -> Self::Result<Entity<T>>;
157
158 fn update_entity<T, R>(
160 &mut self,
161 handle: &Entity<T>,
162 update: impl FnOnce(&mut T, &mut Context<T>) -> R,
163 ) -> Self::Result<R>
164 where
165 T: 'static;
166
167 fn as_mut<'a, T>(&'a mut self, handle: &Entity<T>) -> Self::Result<GpuiBorrow<'a, T>>
169 where
170 T: 'static;
171
172 fn read_entity<T, R>(
174 &self,
175 handle: &Entity<T>,
176 read: impl FnOnce(&T, &App) -> R,
177 ) -> Self::Result<R>
178 where
179 T: 'static;
180
181 fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
183 where
184 F: FnOnce(AnyView, &mut Window, &mut App) -> T;
185
186 fn read_window<T, R>(
188 &self,
189 window: &WindowHandle<T>,
190 read: impl FnOnce(Entity<T>, &App) -> R,
191 ) -> Result<R>
192 where
193 T: 'static;
194
195 fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Task<R>
197 where
198 R: Send + 'static;
199
200 fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> Self::Result<R>
202 where
203 G: Global;
204}
205
206pub struct Reservation<T>(pub(crate) Slot<T>);
209
210impl<T: 'static> Reservation<T> {
211 pub fn entity_id(&self) -> EntityId {
213 self.0.entity_id()
214 }
215}
216
217pub trait VisualContext: AppContext {
220 fn window_handle(&self) -> AnyWindowHandle;
222
223 fn update_window_entity<T: 'static, R>(
225 &mut self,
226 entity: &Entity<T>,
227 update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
228 ) -> Self::Result<R>;
229
230 fn new_window_entity<T: 'static>(
232 &mut self,
233 build_entity: impl FnOnce(&mut Window, &mut Context<T>) -> T,
234 ) -> Self::Result<Entity<T>>;
235
236 fn replace_root_view<V>(
238 &mut self,
239 build_view: impl FnOnce(&mut Window, &mut Context<V>) -> V,
240 ) -> Self::Result<Entity<V>>
241 where
242 V: 'static + Render;
243
244 fn focus<V>(&mut self, entity: &Entity<V>) -> Self::Result<()>
246 where
247 V: Focusable;
248}
249
250pub trait EventEmitter<E: Any>: 'static {}
253
254pub trait BorrowAppContext {
257 fn set_global<T: Global>(&mut self, global: T);
259 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
261 where
262 G: Global;
263 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
265 where
266 G: Global + Default;
267}
268
269impl<C> BorrowAppContext for C
270where
271 C: BorrowMut<App>,
272{
273 fn set_global<G: Global>(&mut self, global: G) {
274 self.borrow_mut().set_global(global)
275 }
276
277 #[track_caller]
278 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
279 where
280 G: Global,
281 {
282 let mut global = self.borrow_mut().lease_global::<G>();
283 let result = f(&mut global, self);
284 self.borrow_mut().end_global_lease(global);
285 result
286 }
287
288 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
289 where
290 G: Global + Default,
291 {
292 self.borrow_mut().default_global::<G>();
293 self.update_global(f)
294 }
295}
296
297pub trait Flatten<T> {
299 fn flatten(self) -> Result<T>;
301}
302
303impl<T> Flatten<T> for Result<Result<T>> {
304 fn flatten(self) -> Result<T> {
305 self?
306 }
307}
308
309impl<T> Flatten<T> for Result<T> {
310 fn flatten(self) -> Result<T> {
311 self
312 }
313}
314
315#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone)]
317pub struct GpuSpecs {
318 pub is_software_emulated: bool,
320 pub device_name: String,
322 pub driver_name: String,
324 pub driver_info: String,
326}