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#[doc(hidden)]
9pub static GPUI_MANIFEST_DIR: &'static str = env!("CARGO_MANIFEST_DIR");
10#[macro_use]
11mod action;
12mod app;
13
14mod arena;
15mod asset_cache;
16mod assets;
17mod bounds_tree;
18mod color;
19pub mod colors;
21mod element;
22mod elements;
23mod executor;
24mod platform_scheduler;
25pub(crate) use platform_scheduler::PlatformScheduler;
26mod geometry;
27mod global;
28mod input;
29mod inspector;
30mod interactive;
31mod key_dispatch;
32mod keymap;
33mod path_builder;
34mod platform;
35pub mod prelude;
36pub mod profiler;
38#[cfg(any(target_os = "windows", target_os = "linux", target_family = "wasm"))]
39#[expect(missing_docs)]
40pub mod queue;
41mod scene;
42mod shared_uri;
43mod style;
44mod styled;
45mod subscription;
46mod svg_renderer;
47mod tab_stop;
48mod taffy;
49#[cfg(any(test, feature = "test-support"))]
50pub mod test;
51mod text_system;
52mod util;
53mod view;
54mod window;
55
56#[cfg(any(test, feature = "test-support"))]
57pub use proptest;
58
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 action::*;
79pub use anyhow::Result;
80pub use app::*;
81pub(crate) use arena::*;
82pub use asset_cache::*;
83pub use assets::*;
84pub use color::*;
85pub use ctor::ctor;
86pub use element::*;
87pub use elements::*;
88pub use executor::*;
89pub use geometry::*;
90pub use global::*;
91pub use gpui_macros::{
92 AppContext, IntoElement, Render, VisualContext, property_test, register_action, test,
93};
94pub use gpui_shared_string::*;
95pub use gpui_util::arc_cow::ArcCow;
96pub use http_client;
97pub use input::*;
98pub use inspector::*;
99pub use interactive::*;
100use key_dispatch::*;
101pub use keymap::*;
102pub use path_builder::*;
103pub use platform::*;
104pub use profiler::*;
105#[cfg(any(target_os = "windows", target_os = "linux", target_family = "wasm"))]
106pub use queue::{PriorityQueueReceiver, PriorityQueueSender};
107pub use refineable::*;
108pub use scene::*;
109pub use shared_uri::*;
110use std::{any::Any, future::Future};
111pub use style::*;
112pub use styled::*;
113pub use subscription::*;
114pub use svg_renderer::*;
115pub(crate) use tab_stop::*;
116use taffy::TaffyLayoutEngine;
117pub use taffy::{AvailableSpace, LayoutId};
118#[cfg(any(test, feature = "test-support"))]
119pub use test::*;
120pub use text_system::*;
121pub use util::{FutureExt, Timeout};
122pub use view::*;
123pub use window::*;
124
125pub use pollster::block_on;
126
127pub trait AppContext {
130 #[expect(
132 clippy::wrong_self_convention,
133 reason = "`App::new` is an ubiquitous function for creating entities"
134 )]
135 fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T>;
136
137 fn reserve_entity<T: 'static>(&mut self) -> Reservation<T>;
140
141 fn insert_entity<T: 'static>(
145 &mut self,
146 reservation: Reservation<T>,
147 build_entity: impl FnOnce(&mut Context<T>) -> T,
148 ) -> Entity<T>;
149
150 fn update_entity<T, R>(
152 &mut self,
153 handle: &Entity<T>,
154 update: impl FnOnce(&mut T, &mut Context<T>) -> R,
155 ) -> R
156 where
157 T: 'static;
158
159 fn as_mut<'a, T>(&'a mut self, handle: &Entity<T>) -> GpuiBorrow<'a, T>
161 where
162 T: 'static;
163
164 fn read_entity<T, R>(&self, handle: &Entity<T>, read: impl FnOnce(&T, &App) -> R) -> R
166 where
167 T: 'static;
168
169 fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
171 where
172 F: FnOnce(AnyView, &mut Window, &mut App) -> T;
173
174 fn with_window<R>(
179 &mut self,
180 entity_id: EntityId,
181 f: impl FnOnce(&mut Window, &mut App) -> R,
182 ) -> Option<R>;
183
184 fn read_window<T, R>(
186 &self,
187 window: &WindowHandle<T>,
188 read: impl FnOnce(Entity<T>, &App) -> R,
189 ) -> Result<R>
190 where
191 T: 'static;
192
193 fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Task<R>
195 where
196 R: Send + 'static;
197
198 fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> R
200 where
201 G: Global;
202}
203
204pub struct Reservation<T>(pub(crate) Slot<T>);
207
208impl<T: 'static> Reservation<T> {
209 pub fn entity_id(&self) -> EntityId {
211 self.0.entity_id()
212 }
213}
214
215pub trait VisualContext: AppContext {
218 type Result<T>;
220
221 fn window_handle(&self) -> AnyWindowHandle;
223
224 fn update_window_entity<T: 'static, R>(
226 &mut self,
227 entity: &Entity<T>,
228 update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
229 ) -> Self::Result<R>;
230
231 fn new_window_entity<T: 'static>(
233 &mut self,
234 build_entity: impl FnOnce(&mut Window, &mut Context<T>) -> T,
235 ) -> Self::Result<Entity<T>>;
236
237 fn replace_root_view<V>(
239 &mut self,
240 build_view: impl FnOnce(&mut Window, &mut Context<V>) -> V,
241 ) -> Self::Result<Entity<V>>
242 where
243 V: 'static + Render;
244
245 fn focus<V>(&mut self, entity: &Entity<V>) -> Self::Result<()>
247 where
248 V: Focusable;
249}
250
251pub trait EventEmitter<E: Any>: 'static {}
254
255pub trait BorrowAppContext {
258 fn set_global<T: Global>(&mut self, global: T);
260 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
262 where
263 G: Global;
264 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
266 where
267 G: Global + Default;
268}
269
270impl<C> BorrowAppContext for C
271where
272 C: std::borrow::BorrowMut<App>,
273{
274 fn set_global<G: Global>(&mut self, global: G) {
275 self.borrow_mut().set_global(global)
276 }
277
278 #[track_caller]
279 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
280 where
281 G: Global,
282 {
283 let mut global = self.borrow_mut().lease_global::<G>();
284 let result = f(&mut global, self);
285 self.borrow_mut().end_global_lease(global);
286 result
287 }
288
289 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
290 where
291 G: Global + Default,
292 {
293 self.borrow_mut().default_global::<G>();
294 self.update_global(f)
295 }
296}
297
298#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone)]
300pub struct GpuSpecs {
301 pub is_software_emulated: bool,
303 pub device_name: String,
305 pub driver_name: String,
307 pub driver_info: String,
309}