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 open_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 _accessibility;
61#[cfg(doc)]
62pub mod _ownership_and_data_flow;
63
64#[doc(hidden)]
66pub mod private {
67 pub use anyhow;
68 pub use inventory;
69 pub use schemars;
70 pub use serde;
71 pub use serde_json;
72}
73
74mod seal {
75 pub trait Sealed {}
78}
79
80pub use accesskit;
81pub use accesskit::Action as AccessibleAction;
82pub use accesskit::{Orientation, Role, Toggled};
83pub use action::*;
84pub use anyhow::Result;
85pub use app::*;
86pub(crate) use arena::*;
87pub use asset_cache::*;
88pub use assets::*;
89pub use color::*;
90pub use ctor::ctor;
91pub use element::*;
92pub use elements::*;
93pub use executor::*;
94pub use geometry::*;
95pub use global::*;
96pub use open_gpui_macros::{
97 AppContext, IntoElement, Render, VisualContext, bench, property_test, register_action, test,
98};
99
100#[macro_export]
107macro_rules! bench_group {
108 ($($tokens:tt)*) => {
109 criterion::criterion_group!($($tokens)*);
110 };
111}
112
113#[macro_export]
118macro_rules! bench_main {
119 ($($tokens:tt)*) => {
120 criterion::criterion_main!($($tokens)*);
121 };
122}
123pub use input::*;
124pub use inspector::*;
125pub use interactive::*;
126use key_dispatch::*;
127pub use keymap::*;
128pub use open_gpui_core_util::arc_cow::ArcCow;
129pub use open_gpui_http_client as http_client;
130pub use open_gpui_refineable::*;
131pub use open_gpui_shared_string::*;
132pub use path_builder::*;
133pub use platform::*;
134pub use profiler::*;
135#[cfg(any(target_os = "windows", target_os = "linux", target_family = "wasm"))]
136pub use queue::{PriorityQueueReceiver, PriorityQueueSender};
137pub use scene::*;
138pub use shared_uri::*;
139use std::{any::Any, future::Future};
140pub use style::*;
141pub use styled::*;
142pub use subscription::*;
143pub use svg_renderer::*;
144pub(crate) use tab_stop::*;
145use taffy::TaffyLayoutEngine;
146pub use taffy::{AvailableSpace, LayoutId};
147#[cfg(any(test, feature = "test-support"))]
148pub use test::*;
149pub use text_system::*;
150pub use util::{FutureExt, Timeout};
151pub use view::*;
152pub use window::*;
153
154pub use pollster::block_on;
155
156pub trait AppContext {
159 #[expect(
161 clippy::wrong_self_convention,
162 reason = "`App::new` is an ubiquitous function for creating entities"
163 )]
164 fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T>;
165
166 fn reserve_entity<T: 'static>(&mut self) -> Reservation<T>;
169
170 fn insert_entity<T: 'static>(
174 &mut self,
175 reservation: Reservation<T>,
176 build_entity: impl FnOnce(&mut Context<T>) -> T,
177 ) -> Entity<T>;
178
179 fn update_entity<T, R>(
181 &mut self,
182 handle: &Entity<T>,
183 update: impl FnOnce(&mut T, &mut Context<T>) -> R,
184 ) -> R
185 where
186 T: 'static;
187
188 fn as_mut<'a, T>(&'a mut self, handle: &Entity<T>) -> GpuiBorrow<'a, T>
190 where
191 T: 'static;
192
193 fn read_entity<T, R>(&self, handle: &Entity<T>, read: impl FnOnce(&T, &App) -> R) -> R
195 where
196 T: 'static;
197
198 fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
200 where
201 F: FnOnce(AnyView, &mut Window, &mut App) -> T;
202
203 fn with_window<R>(
208 &mut self,
209 entity_id: EntityId,
210 f: impl FnOnce(&mut Window, &mut App) -> R,
211 ) -> Option<R>;
212
213 fn read_window<T, R>(
215 &self,
216 window: &WindowHandle<T>,
217 read: impl FnOnce(Entity<T>, &App) -> R,
218 ) -> Result<R>
219 where
220 T: 'static;
221
222 fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Task<R>
224 where
225 R: Send + 'static;
226
227 fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> R
229 where
230 G: Global;
231}
232
233pub struct Reservation<T>(pub(crate) Slot<T>);
236
237impl<T: 'static> Reservation<T> {
238 pub fn entity_id(&self) -> EntityId {
240 self.0.entity_id()
241 }
242}
243
244pub trait VisualContext: AppContext {
247 type Result<T>;
249
250 fn window_handle(&self) -> AnyWindowHandle;
252
253 fn update_window_entity<T: 'static, R>(
255 &mut self,
256 entity: &Entity<T>,
257 update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
258 ) -> Self::Result<R>;
259
260 fn new_window_entity<T: 'static>(
262 &mut self,
263 build_entity: impl FnOnce(&mut Window, &mut Context<T>) -> T,
264 ) -> Self::Result<Entity<T>>;
265
266 fn replace_root_view<V>(
268 &mut self,
269 build_view: impl FnOnce(&mut Window, &mut Context<V>) -> V,
270 ) -> Self::Result<Entity<V>>
271 where
272 V: 'static + Render;
273
274 fn focus<V>(&mut self, entity: &Entity<V>) -> Self::Result<()>
276 where
277 V: Focusable;
278}
279
280pub trait EventEmitter<E: Any>: 'static {}
283
284pub trait BorrowAppContext {
287 fn set_global<T: Global>(&mut self, global: T);
289 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
291 where
292 G: Global;
293 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
295 where
296 G: Global + Default;
297}
298
299impl<C> BorrowAppContext for C
300where
301 C: std::borrow::BorrowMut<App>,
302{
303 fn set_global<G: Global>(&mut self, global: G) {
304 self.borrow_mut().set_global(global)
305 }
306
307 #[track_caller]
308 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
309 where
310 G: Global,
311 {
312 let mut global = self.borrow_mut().lease_global::<G>();
313 let result = f(&mut global, self);
314 self.borrow_mut().end_global_lease(global);
315 result
316 }
317
318 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
319 where
320 G: Global + Default,
321 {
322 self.borrow_mut().default_global::<G>();
323 self.update_global(f)
324 }
325}
326
327#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone)]
329pub struct GpuSpecs {
330 pub is_software_emulated: bool,
332 pub device_name: String,
334 pub driver_name: String,
336 pub driver_info: String,
338}