1#![doc = include_str!("../README.md")]
2#![warn(missing_docs)]
3#![allow(clippy::type_complexity)] #![allow(clippy::collapsible_else_if)] #![allow(unused_mut)] extern crate self as gpui;
8#[macro_use]
9mod action;
10mod app;
11
12mod arena;
13mod asset_cache;
14mod assets;
15mod bounds_tree;
16mod color;
17pub mod colors;
19#[cfg(feature = "profiler")]
20mod debug_overlay;
21mod element;
22mod elements;
23mod executor;
24mod platform_scheduler;
25pub(crate) use platform_scheduler::PlatformScheduler;
26mod geometry;
27mod gestures;
28mod global;
29mod input;
30mod inspector;
31mod interactive;
32mod key_dispatch;
33mod keymap;
34mod path_builder;
35mod platform;
36pub mod prelude;
37pub mod profiler;
39#[cfg(any(
40 test,
41 target_os = "windows",
42 target_os = "linux",
43 target_family = "wasm",
44 feature = "test-support",
45 feature = "bench-support"
46))]
47#[expect(missing_docs)]
48pub mod queue;
49mod scene;
50mod shared_uri;
51mod spring;
52mod style;
53mod styled;
54mod subscription;
55mod svg_renderer;
56mod tab_stop;
57mod taffy;
58#[cfg(any(test, feature = "test-support"))]
59pub mod test;
60mod text_system;
61mod util;
62mod view;
63mod window;
64
65#[cfg(any(test, feature = "test-support"))]
66pub use proptest;
67
68#[cfg(doc)]
69pub mod _accessibility;
70#[cfg(doc)]
71pub mod _ownership_and_data_flow;
72
73#[doc(hidden)]
75pub mod private {
76 pub use anyhow;
77 pub use inventory;
78 pub use schemars;
79 pub use serde;
80 pub use serde_json;
81}
82
83mod seal {
84 pub trait Sealed {}
87}
88
89pub use accesskit;
90pub use accesskit::Action as AccessibleAction;
91pub use accesskit::{Orientation, Role, Toggled};
92pub use action::*;
93pub use anyhow::Result;
94pub use app::*;
95pub(crate) use arena::*;
96pub use asset_cache::*;
97pub use assets::*;
98pub use color::*;
99pub use ctor::ctor;
100#[cfg(feature = "profiler")]
101pub use debug_overlay::*;
102pub use element::*;
103pub use elements::*;
104pub use executor::*;
105pub use geometry::*;
106pub use gestures::*;
107pub use global::*;
108pub use gpui_macros::{
109 AppContext, IntoElement, Render, VisualContext, bench, property_test, register_action, test,
110};
111pub use spring::*;
112
113#[macro_export]
120macro_rules! bench_group {
121 ($($tokens:tt)*) => {
122 criterion::criterion_group!($($tokens)*);
123 };
124}
125
126#[macro_export]
131macro_rules! bench_main {
132 ($($tokens:tt)*) => {
133 criterion::criterion_main!($($tokens)*);
134 };
135}
136pub use gpui_shared_string::*;
137pub use gpui_util::arc_cow::ArcCow;
138pub use http_client;
139pub use input::*;
140pub use inspector::*;
141pub use interactive::*;
142use key_dispatch::*;
143pub use keymap::*;
144pub use path_builder::*;
145pub use platform::*;
146pub use profiler::*;
147#[cfg(any(target_os = "windows", target_os = "linux", target_family = "wasm"))]
148pub use queue::{PriorityQueueReceiver, PriorityQueueSender};
149pub use refineable::*;
150pub use scene::*;
151pub use shared_uri::*;
152use std::{any::Any, future::Future};
153pub use style::*;
154pub use styled::*;
155pub use subscription::*;
156pub use svg_renderer::*;
157pub(crate) use tab_stop::*;
158use taffy::TaffyLayoutEngine;
159pub use taffy::{AvailableSpace, LayoutId};
160#[cfg(any(test, feature = "test-support"))]
161pub use test::*;
162pub use text_system::*;
163pub use util::{FutureExt, Timeout};
164pub use view::*;
165pub use window::*;
166
167#[cfg(not(target_family = "wasm"))]
168pub use pollster::block_on;
169
170pub trait AppContext {
173 #[expect(
175 clippy::wrong_self_convention,
176 reason = "`App::new` is an ubiquitous function for creating entities"
177 )]
178 fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T>;
179
180 fn reserve_entity<T: 'static>(&mut self) -> Reservation<T>;
183
184 fn insert_entity<T: 'static>(
188 &mut self,
189 reservation: Reservation<T>,
190 build_entity: impl FnOnce(&mut Context<T>) -> T,
191 ) -> Entity<T>;
192
193 fn update_entity<T, R>(
195 &mut self,
196 handle: &Entity<T>,
197 update: impl FnOnce(&mut T, &mut Context<T>) -> R,
198 ) -> R
199 where
200 T: 'static;
201
202 fn as_mut<'a, T>(&'a mut self, handle: &Entity<T>) -> GpuiBorrow<'a, T>
204 where
205 T: 'static;
206
207 fn read_entity<T, R>(&self, handle: &Entity<T>, read: impl FnOnce(&T, &App) -> R) -> R
209 where
210 T: 'static;
211
212 fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
214 where
215 F: FnOnce(AnyView, &mut Window, &mut App) -> T;
216
217 fn with_window<R>(
222 &mut self,
223 entity_id: EntityId,
224 f: impl FnOnce(&mut Window, &mut App) -> R,
225 ) -> Option<R>;
226
227 fn read_window<T, R>(
229 &self,
230 window: &WindowHandle<T>,
231 read: impl FnOnce(Entity<T>, &App) -> R,
232 ) -> Result<R>
233 where
234 T: 'static;
235
236 fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Task<R>
238 where
239 R: Send + 'static;
240
241 fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> R
243 where
244 G: Global;
245}
246
247pub struct Reservation<T>(pub(crate) Slot<T>);
250
251impl<T: 'static> Reservation<T> {
252 pub fn entity_id(&self) -> EntityId {
254 self.0.entity_id()
255 }
256}
257
258pub trait VisualContext: AppContext {
261 type Result<T>;
263
264 fn window_handle(&self) -> AnyWindowHandle;
266
267 fn update_window_entity<T: 'static, R>(
269 &mut self,
270 entity: &Entity<T>,
271 update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
272 ) -> Self::Result<R>;
273
274 fn new_window_entity<T: 'static>(
276 &mut self,
277 build_entity: impl FnOnce(&mut Window, &mut Context<T>) -> T,
278 ) -> Self::Result<Entity<T>>;
279
280 fn replace_root_view<V>(
282 &mut self,
283 build_view: impl FnOnce(&mut Window, &mut Context<V>) -> V,
284 ) -> Self::Result<Entity<V>>
285 where
286 V: 'static + Render;
287
288 fn focus<V>(&mut self, entity: &Entity<V>) -> Self::Result<()>
290 where
291 V: Focusable;
292}
293
294pub trait EventEmitter<E: Any>: 'static {}
297
298pub trait BorrowAppContext {
301 fn set_global<T: Global>(&mut self, global: T);
303 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
305 where
306 G: Global;
307 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
309 where
310 G: Global + Default;
311}
312
313impl<C> BorrowAppContext for C
314where
315 C: std::borrow::BorrowMut<App>,
316{
317 fn set_global<G: Global>(&mut self, global: G) {
318 self.borrow_mut().set_global(global)
319 }
320
321 #[track_caller]
322 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
323 where
324 G: Global,
325 {
326 let mut global = self.borrow_mut().lease_global::<G>();
327 let result = f(&mut global, self);
328 self.borrow_mut().end_global_lease(global);
329 result
330 }
331
332 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
333 where
334 G: Global + Default,
335 {
336 self.borrow_mut().default_global::<G>();
337 self.update_global(f)
338 }
339}
340
341#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone)]
343pub struct GpuSpecs {
344 pub is_software_emulated: bool,
346 pub device_name: String,
348 pub driver_name: String,
350 pub driver_info: String,
352}