2023-11-07 16:00:30 +00:00
|
|
|
#[macro_use]
|
2023-10-19 17:26:52 +00:00
|
|
|
mod action;
|
2023-09-19 19:19:22 +00:00
|
|
|
mod app;
|
2023-10-04 03:23:32 +00:00
|
|
|
mod assets;
|
2023-09-19 19:19:22 +00:00
|
|
|
mod color;
|
|
|
|
mod element;
|
|
|
|
mod elements;
|
2023-09-20 02:55:13 +00:00
|
|
|
mod executor;
|
2023-10-19 21:54:17 +00:00
|
|
|
mod focusable;
|
2023-09-19 19:19:22 +00:00
|
|
|
mod geometry;
|
2023-10-04 13:03:21 +00:00
|
|
|
mod image_cache;
|
2023-11-09 04:06:00 +00:00
|
|
|
mod input;
|
2023-10-17 19:37:09 +00:00
|
|
|
mod interactive;
|
2023-10-19 17:09:11 +00:00
|
|
|
mod keymap;
|
2023-09-19 19:19:22 +00:00
|
|
|
mod platform;
|
|
|
|
mod scene;
|
|
|
|
mod style;
|
2023-09-20 03:55:49 +00:00
|
|
|
mod styled;
|
2023-10-11 10:45:09 +00:00
|
|
|
mod subscription;
|
2023-10-04 08:51:47 +00:00
|
|
|
mod svg_renderer;
|
2023-09-19 19:19:22 +00:00
|
|
|
mod taffy;
|
2023-10-25 18:54:05 +00:00
|
|
|
#[cfg(any(test, feature = "test-support"))]
|
|
|
|
mod test;
|
2023-09-20 18:03:37 +00:00
|
|
|
mod text_system;
|
2023-09-20 02:55:13 +00:00
|
|
|
mod util;
|
2023-09-21 19:46:31 +00:00
|
|
|
mod view;
|
2023-09-19 19:19:22 +00:00
|
|
|
mod window;
|
|
|
|
|
2023-10-31 00:43:07 +00:00
|
|
|
mod private {
|
|
|
|
/// A mechanism for restricting implementations of a trait to only those in GPUI.
|
|
|
|
/// See: https://predr.ag/blog/definitive-guide-to-sealed-traits-in-rust/
|
|
|
|
pub trait Sealed {}
|
|
|
|
}
|
|
|
|
|
2023-10-19 17:26:52 +00:00
|
|
|
pub use action::*;
|
2023-09-21 18:18:09 +00:00
|
|
|
pub use anyhow::Result;
|
2023-09-19 19:19:22 +00:00
|
|
|
pub use app::*;
|
2023-10-04 03:23:32 +00:00
|
|
|
pub use assets::*;
|
2023-09-19 19:19:22 +00:00
|
|
|
pub use color::*;
|
2023-11-08 03:23:02 +00:00
|
|
|
pub use ctor::ctor;
|
2023-09-19 19:19:22 +00:00
|
|
|
pub use element::*;
|
|
|
|
pub use elements::*;
|
2023-09-20 02:55:13 +00:00
|
|
|
pub use executor::*;
|
2023-10-19 21:54:17 +00:00
|
|
|
pub use focusable::*;
|
2023-09-19 19:19:22 +00:00
|
|
|
pub use geometry::*;
|
2023-10-21 14:01:47 +00:00
|
|
|
pub use gpui2_macros::*;
|
2023-10-05 02:35:20 +00:00
|
|
|
pub use image_cache::*;
|
2023-11-09 04:06:00 +00:00
|
|
|
pub use input::*;
|
2023-10-17 19:37:09 +00:00
|
|
|
pub use interactive::*;
|
2023-10-19 17:09:11 +00:00
|
|
|
pub use keymap::*;
|
2023-09-19 19:19:22 +00:00
|
|
|
pub use platform::*;
|
2023-10-31 00:43:07 +00:00
|
|
|
use private::Sealed;
|
2023-09-20 03:55:49 +00:00
|
|
|
pub use refineable::*;
|
2023-09-19 19:19:22 +00:00
|
|
|
pub use scene::*;
|
2023-09-20 20:32:55 +00:00
|
|
|
pub use serde;
|
|
|
|
pub use serde_json;
|
2023-09-20 03:55:49 +00:00
|
|
|
pub use smallvec;
|
2023-09-20 02:55:13 +00:00
|
|
|
pub use smol::Timer;
|
2023-09-19 19:19:22 +00:00
|
|
|
pub use style::*;
|
2023-09-20 03:55:49 +00:00
|
|
|
pub use styled::*;
|
2023-10-11 10:45:09 +00:00
|
|
|
pub use subscription::*;
|
2023-10-04 19:43:21 +00:00
|
|
|
pub use svg_renderer::*;
|
2023-09-21 02:28:32 +00:00
|
|
|
pub use taffy::{AvailableSpace, LayoutId};
|
2023-10-25 18:54:05 +00:00
|
|
|
#[cfg(any(test, feature = "test-support"))]
|
|
|
|
pub use test::*;
|
2023-09-20 18:03:37 +00:00
|
|
|
pub use text_system::*;
|
2023-09-19 19:19:22 +00:00
|
|
|
pub use util::arc_cow::ArcCow;
|
2023-09-21 19:46:31 +00:00
|
|
|
pub use view::*;
|
2023-09-19 19:19:22 +00:00
|
|
|
pub use window::*;
|
|
|
|
|
2023-10-17 04:08:53 +00:00
|
|
|
use derive_more::{Deref, DerefMut};
|
2023-10-10 17:48:32 +00:00
|
|
|
use std::{
|
2023-10-11 23:18:33 +00:00
|
|
|
any::{Any, TypeId},
|
2023-10-24 08:01:19 +00:00
|
|
|
borrow::{Borrow, BorrowMut},
|
2023-10-10 17:48:32 +00:00
|
|
|
};
|
|
|
|
use taffy::TaffyLayoutEngine;
|
|
|
|
|
2023-11-01 18:31:23 +00:00
|
|
|
type AnyBox = Box<dyn Any>;
|
2023-10-11 04:14:47 +00:00
|
|
|
|
2023-09-19 19:19:22 +00:00
|
|
|
pub trait Context {
|
2023-09-26 17:29:44 +00:00
|
|
|
type Result<T>;
|
2023-09-19 19:19:22 +00:00
|
|
|
|
2023-11-01 18:31:23 +00:00
|
|
|
fn build_model<T: 'static>(
|
2023-09-19 19:19:22 +00:00
|
|
|
&mut self,
|
2023-11-02 08:41:49 +00:00
|
|
|
build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T,
|
2023-11-01 18:31:23 +00:00
|
|
|
) -> Self::Result<Model<T>>;
|
2023-09-19 19:19:22 +00:00
|
|
|
|
2023-11-02 08:41:49 +00:00
|
|
|
fn update_model<T, R>(
|
2023-09-19 19:19:22 +00:00
|
|
|
&mut self,
|
2023-10-30 18:44:01 +00:00
|
|
|
handle: &Model<T>,
|
2023-11-02 08:41:49 +00:00
|
|
|
update: impl FnOnce(&mut T, &mut ModelContext<'_, T>) -> R,
|
|
|
|
) -> Self::Result<R>
|
|
|
|
where
|
|
|
|
T: 'static;
|
|
|
|
|
2023-11-04 01:01:06 +00:00
|
|
|
fn read_model<T, R>(
|
|
|
|
&self,
|
|
|
|
handle: &Model<T>,
|
|
|
|
read: impl FnOnce(&T, &AppContext) -> R,
|
|
|
|
) -> Self::Result<R>
|
|
|
|
where
|
|
|
|
T: 'static;
|
|
|
|
|
2023-11-02 08:41:49 +00:00
|
|
|
fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
|
|
|
|
where
|
|
|
|
F: FnOnce(AnyView, &mut WindowContext<'_>) -> T;
|
2023-11-09 06:11:19 +00:00
|
|
|
|
|
|
|
fn read_window<R>(
|
|
|
|
&self,
|
|
|
|
window: &AnyWindowHandle,
|
|
|
|
read: impl FnOnce(AnyView, &AppContext) -> R,
|
|
|
|
) -> Result<R>;
|
2023-09-26 17:29:44 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 17:41:42 +00:00
|
|
|
pub trait VisualContext: Context {
|
2023-10-30 22:19:40 +00:00
|
|
|
fn build_view<V>(
|
2023-10-26 17:41:42 +00:00
|
|
|
&mut self,
|
2023-11-02 08:41:49 +00:00
|
|
|
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
2023-10-26 17:41:42 +00:00
|
|
|
) -> Self::Result<View<V>>
|
|
|
|
where
|
2023-11-08 23:23:05 +00:00
|
|
|
V: 'static + Render;
|
2023-10-26 17:41:42 +00:00
|
|
|
|
|
|
|
fn update_view<V: 'static, R>(
|
|
|
|
&mut self,
|
|
|
|
view: &View<V>,
|
2023-11-02 08:41:49 +00:00
|
|
|
update: impl FnOnce(&mut V, &mut ViewContext<'_, V>) -> R,
|
2023-10-26 17:41:42 +00:00
|
|
|
) -> Self::Result<R>;
|
2023-11-02 08:41:49 +00:00
|
|
|
|
|
|
|
fn replace_root_view<V>(
|
|
|
|
&mut self,
|
|
|
|
build_view: impl FnOnce(&mut ViewContext<'_, V>) -> V,
|
|
|
|
) -> Self::Result<View<V>>
|
|
|
|
where
|
|
|
|
V: Render;
|
2023-10-26 17:41:42 +00:00
|
|
|
}
|
|
|
|
|
2023-10-31 00:43:07 +00:00
|
|
|
pub trait Entity<T>: Sealed {
|
2023-11-02 08:41:49 +00:00
|
|
|
type Weak: 'static;
|
2023-10-31 00:43:07 +00:00
|
|
|
|
|
|
|
fn entity_id(&self) -> EntityId;
|
|
|
|
fn downgrade(&self) -> Self::Weak;
|
|
|
|
fn upgrade_from(weak: &Self::Weak) -> Option<Self>
|
|
|
|
where
|
|
|
|
Self: Sized;
|
|
|
|
}
|
|
|
|
|
2023-11-09 00:34:38 +00:00
|
|
|
pub trait EventEmitter<E: Any>: 'static {}
|
|
|
|
|
2023-10-11 23:18:33 +00:00
|
|
|
pub enum GlobalKey {
|
|
|
|
Numeric(usize),
|
|
|
|
View(EntityId),
|
|
|
|
Type(TypeId),
|
|
|
|
}
|
|
|
|
|
2023-10-04 02:04:17 +00:00
|
|
|
pub trait BorrowAppContext {
|
2023-10-24 08:01:19 +00:00
|
|
|
fn with_text_style<F, R>(&mut self, style: TextStyleRefinement, f: F) -> R
|
|
|
|
where
|
|
|
|
F: FnOnce(&mut Self) -> R;
|
|
|
|
|
2023-11-02 08:41:49 +00:00
|
|
|
fn set_global<T: 'static>(&mut self, global: T);
|
2023-10-24 08:01:19 +00:00
|
|
|
}
|
2023-09-29 19:22:53 +00:00
|
|
|
|
2023-10-24 08:01:19 +00:00
|
|
|
impl<C> BorrowAppContext for C
|
|
|
|
where
|
|
|
|
C: BorrowMut<AppContext>,
|
|
|
|
{
|
2023-09-29 19:22:53 +00:00
|
|
|
fn with_text_style<F, R>(&mut self, style: TextStyleRefinement, f: F) -> R
|
|
|
|
where
|
|
|
|
F: FnOnce(&mut Self) -> R,
|
|
|
|
{
|
2023-10-24 08:01:19 +00:00
|
|
|
self.borrow_mut().push_text_style(style);
|
2023-09-29 19:22:53 +00:00
|
|
|
let result = f(self);
|
2023-10-24 08:01:19 +00:00
|
|
|
self.borrow_mut().pop_text_style();
|
2023-09-29 19:22:53 +00:00
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2023-11-02 08:41:49 +00:00
|
|
|
fn set_global<G: 'static>(&mut self, global: G) {
|
2023-10-24 08:01:19 +00:00
|
|
|
self.borrow_mut().set_global(global)
|
2023-10-21 15:52:47 +00:00
|
|
|
}
|
2023-09-29 19:22:53 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 17:29:44 +00:00
|
|
|
pub trait Flatten<T> {
|
|
|
|
fn flatten(self) -> Result<T>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Flatten<T> for Result<Result<T>> {
|
|
|
|
fn flatten(self) -> Result<T> {
|
|
|
|
self?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Flatten<T> for Result<T> {
|
|
|
|
fn flatten(self) -> Result<T> {
|
|
|
|
self
|
|
|
|
}
|
2023-09-19 19:19:22 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 04:08:53 +00:00
|
|
|
#[derive(Deref, DerefMut, Eq, PartialEq, Hash, Clone)]
|
2023-09-19 19:19:22 +00:00
|
|
|
pub struct SharedString(ArcCow<'static, str>);
|
|
|
|
|
2023-09-21 02:28:32 +00:00
|
|
|
impl Default for SharedString {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self(ArcCow::Owned("".into()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-20 02:55:13 +00:00
|
|
|
impl AsRef<str> for SharedString {
|
|
|
|
fn as_ref(&self) -> &str {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-21 15:52:47 +00:00
|
|
|
impl Borrow<str> for SharedString {
|
|
|
|
fn borrow(&self) -> &str {
|
|
|
|
self.as_ref()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-19 19:19:22 +00:00
|
|
|
impl std::fmt::Debug for SharedString {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
self.0.fmt(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-04 03:23:32 +00:00
|
|
|
impl std::fmt::Display for SharedString {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "{}", self.0.as_ref())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-19 19:19:22 +00:00
|
|
|
impl<T: Into<ArcCow<'static, str>>> From<T> for SharedString {
|
|
|
|
fn from(value: T) -> Self {
|
|
|
|
Self(value.into())
|
|
|
|
}
|
|
|
|
}
|