Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
WIP
Nathan Sobo89519b152199
diff --git a/crates/storybook/src/gpui3/app.rs b/crates/storybook/src/gpui3/app.rsindex 92e498e6adc..2222070888a 100644--- a/crates/storybook/src/gpui3/app.rs+++ b/crates/storybook/src/gpui3/app.rs@@ -1,13 +1,15 @@use anyhow::{anyhow, Result};use slotmap::SlotMap;-use std::{any::Any, marker::PhantomData};+use std::{any::Any, marker::PhantomData, rc::Rc};use super::{+ platform::Platform,window::{Window, WindowHandle, WindowId},Context, LayoutId, Reference, View, WindowContext,};pub struct AppContext {+ platform: Rc<dyn Platform>,pub(crate) entities: SlotMap<EntityId, Option<Box<dyn Any>>>,pub(crate) windows: SlotMap<WindowId, Option<Window>>,// We recycle this memory across layout requests.@@ -15,14 +17,19 @@ pub struct AppContext {}impl AppContext {- pub fn new() -> Self {+ pub fn new(platform: Rc<dyn Platform>) -> Self {AppContext {+ platform,entities: SlotMap::with_key(),windows: SlotMap::with_key(),layout_id_buffer: Default::default(),}}+ pub fn test() -> Self {+ Self::new(TestPlatform::new())+ }+pub fn open_window<S: 'static>(&mut self,build_root_view: impl FnOnce(&mut WindowContext) -> View<S>,diff --git a/crates/storybook/src/gpui3/geometry.rs b/crates/storybook/src/gpui3/geometry.rsindex f4c517138a2..64293d121be 100644--- a/crates/storybook/src/gpui3/geometry.rs+++ b/crates/storybook/src/gpui3/geometry.rs@@ -31,7 +31,7 @@ unsafe impl<T: Clone + Debug + Zeroable + Pod> Zeroable for Point<T> {}unsafe impl<T: Clone + Debug + Zeroable + Pod> Pod for Point<T> {}-#[derive(Refineable, Default, Clone, Copy, Debug)]+#[derive(Refineable, Default, Clone, Copy, Debug, PartialEq)]#[refineable(debug)]pub struct Size<T: Clone + Debug> {pub width: T,@@ -65,7 +65,7 @@ impl Size<Length> {}}-#[derive(Refineable, Clone, Default, Debug)]+#[derive(Refineable, Clone, Default, Debug, PartialEq)]#[refineable(debug)]pub struct Bounds<T: Clone + Debug> {pub origin: Point<T>,diff --git a/crates/storybook/src/gpui3/mod.rs b/crates/storybook/src/gpui3/mod.rsindex 36c9040f38e..79fba6f4477 100644--- a/crates/storybook/src/gpui3/mod.rs+++ b/crates/storybook/src/gpui3/mod.rs@@ -3,6 +3,7 @@ mod color;mod element;mod elements;mod geometry;+mod platform;mod renderer;mod scene;mod style;diff --git a/crates/storybook/src/gpui3/platform.rs b/crates/storybook/src/gpui3/platform.rsnew file mode 100644index 00000000000..f475ce39406--- /dev/null+++ b/crates/storybook/src/gpui3/platform.rs@@ -0,0 +1,58 @@+mod test;+use super::{AnyWindowHandle, Bounds, Point};+use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};++pub trait Platform {+ fn open_window(+ &self,+ handle: AnyWindowHandle,+ options: WindowOptions,+ ) -> Box<dyn PlatformWindow>;+}++pub trait PlatformWindow: HasRawWindowHandle + HasRawDisplayHandle {}++#[derive(Debug)]+pub struct WindowOptions<'a> {+ pub bounds: WindowBounds,+ pub titlebar: Option<TitlebarOptions<'a>>,+ pub center: bool,+ pub focus: bool,+ pub show: bool,+ pub kind: WindowKind,+ pub is_movable: bool,+}++#[derive(Debug, Default)]+pub struct TitlebarOptions<'a> {+ pub title: Option<&'a str>,+ pub appears_transparent: bool,+ pub traffic_light_position: Option<Point<f32>>,+}++#[derive(Copy, Clone, Debug)]+pub enum Appearance {+ Light,+ VibrantLight,+ Dark,+ VibrantDark,+}++impl Default for Appearance {+ fn default() -> Self {+ Self::Light+ }+}++#[derive(Copy, Clone, Debug, PartialEq, Eq)]+pub enum WindowKind {+ Normal,+ PopUp,+}++#[derive(Copy, Clone, Debug, PartialEq)]+pub enum WindowBounds {+ Fullscreen,+ Maximized,+ Fixed(Bounds<f32>),+}diff --git a/crates/storybook/src/gpui3/platform/test.rs b/crates/storybook/src/gpui3/platform/test.rsnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/crates/storybook/src/gpui3/window.rs b/crates/storybook/src/gpui3/window.rsindex 3b0f561643f..28e0bbb8c4c 100644--- a/crates/storybook/src/gpui3/window.rs+++ b/crates/storybook/src/gpui3/window.rs@@ -5,7 +5,10 @@ use super::{use anyhow::Result;use derive_more::{Deref, DerefMut};use gpui2::Reference;-use std::{any::Any, marker::PhantomData};+use std::{+ any::{Any, TypeId},+ marker::PhantomData,+};pub struct AnyWindow {}@@ -216,6 +219,11 @@ impl<S> WindowHandle<S> {}}+pub struct AnyWindowHandle {+ id: WindowId,+ state_type: TypeId,+}+#[derive(Clone)]pub struct Layout {pub order: u32,