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]
130macro_rules! bench_group {
131 (name = $name:ident; config = $config:expr; targets = $($target:path),+ $(,)?) => {
132 criterion::criterion_group! {
133 name = $name;
134 config = ($config).with_measurement($crate::BenchMeasurement::from_env_or_exit());
135 targets = $($target),+
136 }
137 };
138 ($name:ident, $($target:path),+ $(,)?) => {
139 $crate::bench_group! {
140 name = $name;
141 config = criterion::Criterion::default();
142 targets = $($target),+
143 }
144 };
145}
146
147#[macro_export]
152macro_rules! bench_main {
153 ($($tokens:tt)*) => {
154 criterion::criterion_main!($($tokens)*);
155 };
156}
157pub use gpui_shared_string::*;
158pub use gpui_util::arc_cow::ArcCow;
159pub use http_client;
160pub use input::*;
161pub use inspector::*;
162pub use interactive::*;
163use key_dispatch::*;
164pub use keymap::*;
165pub use path_builder::*;
166pub use platform::*;
167pub use profiler::*;
168#[cfg(any(target_os = "windows", target_os = "linux", target_family = "wasm"))]
169pub use queue::{PriorityQueueReceiver, PriorityQueueSender};
170pub use refineable::*;
171pub use scene::*;
172pub use shared_uri::*;
173use std::{any::Any, future::Future};
174pub use style::*;
175pub use styled::*;
176pub use subscription::*;
177pub use svg_renderer::*;
178pub(crate) use tab_stop::*;
179use taffy::TaffyLayoutEngine;
180pub use taffy::{AvailableSpace, LayoutId};
181#[cfg(any(test, feature = "test-support"))]
182pub use test::*;
183pub use text_system::*;
184pub use util::{FutureExt, Timeout};
185pub use view::*;
186pub use window::*;
187
188#[cfg(not(target_family = "wasm"))]
189pub use pollster::block_on;
190
191pub trait AppContext {
194 #[expect(
196 clippy::wrong_self_convention,
197 reason = "`App::new` is an ubiquitous function for creating entities"
198 )]
199 fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T>;
200
201 fn reserve_entity<T: 'static>(&mut self) -> Reservation<T>;
204
205 fn insert_entity<T: 'static>(
209 &mut self,
210 reservation: Reservation<T>,
211 build_entity: impl FnOnce(&mut Context<T>) -> T,
212 ) -> Entity<T>;
213
214 fn update_entity<T, R>(
216 &mut self,
217 handle: &Entity<T>,
218 update: impl FnOnce(&mut T, &mut Context<T>) -> R,
219 ) -> R
220 where
221 T: 'static;
222
223 fn as_mut<'a, T>(&'a mut self, handle: &Entity<T>) -> GpuiBorrow<'a, T>
225 where
226 T: 'static;
227
228 fn read_entity<T, R>(&self, handle: &Entity<T>, read: impl FnOnce(&T, &App) -> R) -> R
230 where
231 T: 'static;
232
233 fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
235 where
236 F: FnOnce(AnyView, &mut Window, &mut App) -> T;
237
238 fn with_window<R>(
243 &mut self,
244 entity_id: EntityId,
245 f: impl FnOnce(&mut Window, &mut App) -> R,
246 ) -> Option<R>;
247
248 fn read_window<T, R>(
250 &self,
251 window: &WindowHandle<T>,
252 read: impl FnOnce(Entity<T>, &App) -> R,
253 ) -> Result<R>
254 where
255 T: 'static;
256
257 fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Task<R>
259 where
260 R: Send + 'static;
261
262 fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> R
264 where
265 G: Global;
266}
267
268pub struct Reservation<T>(pub(crate) Slot<T>);
271
272impl<T: 'static> Reservation<T> {
273 pub fn entity_id(&self) -> EntityId {
275 self.0.entity_id()
276 }
277}
278
279pub trait VisualContext: AppContext {
282 type Result<T>;
284
285 fn window_handle(&self) -> AnyWindowHandle;
287
288 fn update_window_entity<T: 'static, R>(
290 &mut self,
291 entity: &Entity<T>,
292 update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
293 ) -> Self::Result<R>;
294
295 fn new_window_entity<T: 'static>(
297 &mut self,
298 build_entity: impl FnOnce(&mut Window, &mut Context<T>) -> T,
299 ) -> Self::Result<Entity<T>>;
300
301 fn replace_root_view<V>(
303 &mut self,
304 build_view: impl FnOnce(&mut Window, &mut Context<V>) -> V,
305 ) -> Self::Result<Entity<V>>
306 where
307 V: 'static + Render;
308
309 fn focus<V>(&mut self, entity: &Entity<V>) -> Self::Result<()>
311 where
312 V: Focusable;
313}
314
315pub trait EventEmitter<E: Any>: 'static {}
318
319pub trait BorrowAppContext {
322 fn set_global<T: Global>(&mut self, global: T);
324 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
326 where
327 G: Global;
328 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
330 where
331 G: Global + Default;
332}
333
334impl<C> BorrowAppContext for C
335where
336 C: std::borrow::BorrowMut<App>,
337{
338 fn set_global<G: Global>(&mut self, global: G) {
339 self.borrow_mut().set_global(global)
340 }
341
342 #[track_caller]
343 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
344 where
345 G: Global,
346 {
347 let mut global = self.borrow_mut().lease_global::<G>();
348 let result = f(&mut global, self);
349 self.borrow_mut().end_global_lease(global);
350 result
351 }
352
353 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
354 where
355 G: Global + Default,
356 {
357 self.borrow_mut().default_global::<G>();
358 self.update_global(f)
359 }
360}
361
362#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone)]
364pub struct GpuSpecs {
365 pub is_software_emulated: bool,
367 pub device_name: String,
369 pub driver_name: String,
371 pub driver_info: String,
373}