diff --git a/crates/storybook/src/gpui3/app.rs b/crates/storybook/src/gpui3/app.rs index 9ab1e99a139800a0d5e3bc4e556c2aa5ff5d2d47..8d501341d018b58ad87e0788587c690f188a3592 100644 --- a/crates/storybook/src/gpui3/app.rs +++ b/crates/storybook/src/gpui3/app.rs @@ -23,15 +23,18 @@ impl AppContext { } } - pub fn open_window( + pub fn open_window( &mut self, build_root_view: impl FnOnce(&mut WindowContext) -> View, ) -> WindowHandle { - // let window = self.windows.insert_with_key(|id| { + let id = self.windows.insert(None); - // }); + let mut window = Window::new(id); + let root_view = build_root_view(&mut WindowContext::mutable(self, &mut window)); + window.root_view.replace(Box::new(root_view)); - unimplemented!() + self.windows.get_mut(id).unwrap().replace(window); + WindowHandle::new(id) } pub(crate) fn update_window( diff --git a/crates/storybook/src/gpui3/window.rs b/crates/storybook/src/gpui3/window.rs index 29677df58d6a1279c3cdc12891ed1d6018e70c15..feabe41aeb5b1b473b00fdec8104f18944dea90c 100644 --- a/crates/storybook/src/gpui3/window.rs +++ b/crates/storybook/src/gpui3/window.rs @@ -2,12 +2,15 @@ use super::{px, AppContext, Bounds, Context, EntityId, Handle, Pixels, Style, Ta use anyhow::Result; use derive_more::{Deref, DerefMut}; use gpui2::Reference; -use std::marker::PhantomData; +use std::{any::Any, marker::PhantomData}; + +pub struct AnyWindow {} pub struct Window { id: WindowId, rem_size: Pixels, layout_engine: Box, + pub(crate) root_view: Option>, } impl Window { @@ -16,6 +19,7 @@ impl Window { id, layout_engine: Box::new(TaffyLayoutEngine::new()), rem_size: px(16.), + root_view: None, } } } @@ -198,6 +202,15 @@ pub struct WindowHandle { state_type: PhantomData, } +impl WindowHandle { + pub fn new(id: WindowId) -> Self { + WindowHandle { + id, + state_type: PhantomData, + } + } +} + #[derive(Clone)] pub struct Layout { pub order: u32,