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;
15#[cfg(feature = "bench-support")]
18#[doc(hidden)]
19pub mod bench_metrics;
20mod bounds_tree;
21mod color;
22pub mod colors;
24#[cfg(feature = "profiler")]
25mod debug_overlay;
26mod element;
27mod elements;
28mod executor;
29mod platform_scheduler;
30pub(crate) use platform_scheduler::PlatformScheduler;
31mod geometry;
32mod gestures;
33mod global;
34#[cfg(gpui_hot_reload)]
35mod hot_reload;
36mod image_texture;
37mod input;
38mod inspector;
39mod interactive;
40mod key_dispatch;
41mod keymap;
42mod path_builder;
43mod platform;
44pub mod prelude;
45pub mod profiler;
47#[cfg(any(
48 test,
49 target_os = "windows",
50 target_os = "linux",
51 target_family = "wasm",
52 feature = "test-support",
53 feature = "bench-support"
54))]
55#[expect(missing_docs)]
56pub mod queue;
57#[cfg(any(test, feature = "bench-support"))]
59pub mod randomized_element_tree;
60mod scene;
61#[cfg(any(test, feature = "test-support", feature = "bench-support"))]
62mod seeds;
63mod shared_uri;
64mod spring;
65mod style;
66mod styled;
67mod subscription;
68mod svg_renderer;
69mod tab_stop;
70mod taffy;
71#[cfg(any(test, feature = "test-support"))]
72pub mod test;
73mod text_system;
74mod util;
75mod view;
76mod window;
77
78#[cfg(any(test, feature = "test-support"))]
79pub use proptest;
80#[cfg(any(test, feature = "test-support", feature = "bench-support"))]
81pub use seeds::calculate_seeds;
82
83#[cfg(doc)]
84pub mod _accessibility;
85#[cfg(doc)]
86pub mod _ownership_and_data_flow;
87
88#[doc(hidden)]
90pub mod private {
91 pub use anyhow;
92 pub use inventory;
93 pub use rand;
94 pub use schemars;
95 pub use serde;
96 pub use serde_json;
97}
98
99mod seal {
100 pub trait Sealed {}
103}
104
105pub use accesskit;
106pub use accesskit::Action as AccessibleAction;
107pub use accesskit::{Orientation, Role, Toggled};
108pub use action::*;
109pub use anyhow::Result;
110pub use app::*;
111pub(crate) use arena::*;
112pub use asset_cache::*;
113pub use assets::*;
114pub use color::*;
115pub use ctor::ctor;
116#[cfg(feature = "profiler")]
117pub use debug_overlay::*;
118pub use element::*;
119pub use elements::*;
120pub use executor::*;
121pub use geometry::*;
122pub use gestures::*;
123pub use global::*;
124pub use gpui_macros::{
125 AppContext, IntoElement, Render, VisualContext, bench, property_test, register_action, test,
126};
127pub use spring::*;
128
129#[macro_export]
146macro_rules! bench_group {
147 (name = $name:ident; config = $config:expr; targets = $($target:path),+ $(,)?) => {
148 criterion::criterion_group! {
149 name = $name;
150 config = ($config).with_measurement($crate::BenchMeasurement::from_env_or_exit());
151 targets = $($target),+
152 }
153 };
154 ($name:ident, $($target:path),+ $(,)?) => {
155 $crate::bench_group! {
156 name = $name;
157 config = criterion::Criterion::default();
158 targets = $($target),+
159 }
160 };
161}
162
163#[macro_export]
179macro_rules! bench_main {
180 (allocator = none; $($groups:tt)*) => {
181 criterion::criterion_main!($($groups)*);
182 };
183 (allocator = $allocator:path; $($groups:tt)*) => {
184 #[global_allocator]
185 static GPUI_BENCH_ALLOCATOR: $crate::CountingAllocator<$allocator> =
186 $crate::CountingAllocator::new($allocator);
187
188 criterion::criterion_main!($($groups)*);
189 };
190 ($($groups:tt)*) => {
191 $crate::bench_main!(allocator = ::std::alloc::System; $($groups)*);
192 };
193}
194pub use gpui_shared_string::*;
195pub use gpui_util::arc_cow::ArcCow;
196pub use http_client;
197pub use image_texture::*;
198pub use input::*;
199pub use inspector::*;
200pub use interactive::*;
201use key_dispatch::*;
202pub use keymap::*;
203pub use path_builder::*;
204pub use platform::*;
205pub use profiler::*;
206#[cfg(any(target_os = "windows", target_os = "linux", target_family = "wasm"))]
207pub use queue::{PriorityQueueReceiver, PriorityQueueSender};
208pub use refineable::*;
209pub use scene::*;
210pub use shared_uri::*;
211use std::{any::Any, future::Future};
212pub use style::*;
213pub use styled::*;
214pub use subscription::*;
215#[cfg(all(
217 feature = "hot-reload",
218 any(
219 target_os = "macos",
220 target_os = "linux",
221 target_os = "windows",
222 target_os = "ios"
223 )
224))]
225pub use subsecond;
226pub use svg_renderer::*;
227pub(crate) use tab_stop::*;
228use taffy::TaffyLayoutEngine;
229pub use taffy::{AvailableSpace, LayoutId};
230#[cfg(any(test, feature = "test-support"))]
231pub use test::*;
232pub use text_system::*;
233pub use util::{FutureExt, Timeout};
234pub use view::*;
235pub use window::*;
236
237#[cfg(not(target_family = "wasm"))]
238pub use pollster::block_on;
239
240pub trait AppContext {
243 #[expect(
245 clippy::wrong_self_convention,
246 reason = "`App::new` is an ubiquitous function for creating entities"
247 )]
248 fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T>;
249
250 fn reserve_entity<T: 'static>(&mut self) -> Reservation<T>;
253
254 fn insert_entity<T: 'static>(
258 &mut self,
259 reservation: Reservation<T>,
260 build_entity: impl FnOnce(&mut Context<T>) -> T,
261 ) -> Entity<T>;
262
263 fn update_entity<T, R>(
265 &mut self,
266 handle: &Entity<T>,
267 update: impl FnOnce(&mut T, &mut Context<T>) -> R,
268 ) -> R
269 where
270 T: 'static;
271
272 fn as_mut<'a, T>(&'a mut self, handle: &Entity<T>) -> GpuiBorrow<'a, T>
274 where
275 T: 'static;
276
277 fn read_entity<T, R>(&self, handle: &Entity<T>, read: impl FnOnce(&T, &App) -> R) -> R
279 where
280 T: 'static;
281
282 fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
284 where
285 F: FnOnce(AnyView, &mut Window, &mut App) -> T;
286
287 fn with_window<R>(
292 &mut self,
293 entity_id: EntityId,
294 f: impl FnOnce(&mut Window, &mut App) -> R,
295 ) -> Option<R>;
296
297 fn read_window<T, R>(
299 &self,
300 window: &WindowHandle<T>,
301 read: impl FnOnce(Entity<T>, &App) -> R,
302 ) -> Result<R>
303 where
304 T: 'static;
305
306 fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Task<R>
308 where
309 R: Send + 'static;
310
311 fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> R
313 where
314 G: Global;
315}
316
317pub struct Reservation<T>(pub(crate) Slot<T>);
320
321impl<T: 'static> Reservation<T> {
322 pub fn entity_id(&self) -> EntityId {
324 self.0.entity_id()
325 }
326}
327
328pub trait VisualContext: AppContext {
331 type Result<T>;
333
334 fn window_handle(&self) -> AnyWindowHandle;
336
337 fn update_window_entity<T: 'static, R>(
339 &mut self,
340 entity: &Entity<T>,
341 update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
342 ) -> Self::Result<R>;
343
344 fn new_window_entity<T: 'static>(
346 &mut self,
347 build_entity: impl FnOnce(&mut Window, &mut Context<T>) -> T,
348 ) -> Self::Result<Entity<T>>;
349
350 fn replace_root_view<V>(
352 &mut self,
353 build_view: impl FnOnce(&mut Window, &mut Context<V>) -> V,
354 ) -> Self::Result<Entity<V>>
355 where
356 V: 'static + Render;
357
358 fn focus<V>(&mut self, entity: &Entity<V>) -> Self::Result<()>
360 where
361 V: Focusable;
362}
363
364pub trait EventEmitter<E: Any>: 'static {}
367
368pub trait BorrowAppContext {
371 fn set_global<T: Global>(&mut self, global: T);
373 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
375 where
376 G: Global;
377 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
379 where
380 G: Global + Default;
381}
382
383impl<C> BorrowAppContext for C
384where
385 C: std::borrow::BorrowMut<App>,
386{
387 fn set_global<G: Global>(&mut self, global: G) {
388 self.borrow_mut().set_global(global)
389 }
390
391 #[track_caller]
392 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
393 where
394 G: Global,
395 {
396 let mut global = self.borrow_mut().lease_global::<G>();
397 let result = f(&mut global, self);
398 self.borrow_mut().end_global_lease(global);
399 result
400 }
401
402 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
403 where
404 G: Global + Default,
405 {
406 self.borrow_mut().default_global::<G>();
407 self.update_global(f)
408 }
409}
410
411#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone)]
413pub struct GpuSpecs {
414 pub is_software_emulated: bool,
416 pub device_name: String,
418 pub driver_name: String,
420 pub driver_info: String,
422}
423
424mod backdrop;
425mod backdrop_cache;
426pub use backdrop::*;
427pub use backdrop_cache::*;
428
429mod layer_effect;
430pub use layer_effect::*;