zed/crates/gpui3/src/gpui3.rs

110 lines
2.3 KiB
Rust
Raw Normal View History

2023-09-19 19:19:22 +00:00
mod app;
mod color;
mod element;
mod elements;
2023-09-20 02:55:13 +00:00
mod executor;
2023-09-19 19:19:22 +00:00
mod geometry;
mod platform;
mod renderer;
mod scene;
mod style;
mod style_helpers;
2023-09-20 03:55:49 +00:00
mod styled;
2023-09-19 19:19:22 +00:00
mod taffy;
2023-09-20 18:03:37 +00:00
mod text_system;
2023-09-20 02:55:13 +00:00
mod util;
2023-09-19 19:19:22 +00:00
mod window;
use anyhow::Result;
pub use app::*;
pub use color::*;
pub use element::*;
pub use elements::*;
2023-09-20 02:55:13 +00:00
pub use executor::*;
2023-09-19 19:19:22 +00:00
pub use geometry::*;
pub use platform::*;
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
use std::ops::{Deref, DerefMut};
pub use style::*;
pub use style_helpers::*;
2023-09-20 03:55:49 +00:00
pub use styled::*;
2023-09-19 19:19:22 +00:00
use taffy::TaffyLayoutEngine;
2023-09-21 02:28:32 +00:00
pub use taffy::{AvailableSpace, LayoutId};
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;
pub use window::*;
pub trait Context {
type EntityContext<'a, 'w, T: 'static>;
fn entity<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T,
) -> Handle<T>;
fn update_entity<T: 'static, R>(
&mut self,
handle: &Handle<T>,
update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, '_, T>) -> R,
) -> R;
}
#[derive(Clone, Eq, PartialEq)]
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-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)
}
}
impl<T: Into<ArcCow<'static, str>>> From<T> for SharedString {
fn from(value: T) -> Self {
Self(value.into())
}
}
pub enum Reference<'a, T> {
Immutable(&'a T),
Mutable(&'a mut T),
}
impl<'a, T> Deref for Reference<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
match self {
Reference::Immutable(target) => target,
Reference::Mutable(target) => target,
}
}
}
impl<'a, T> DerefMut for Reference<'a, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
match self {
Reference::Immutable(_) => {
panic!("cannot mutably deref an immutable reference. this is a bug in GPUI.");
}
Reference::Mutable(target) => target,
}
}
}