From 1adb7fa58c5a9e412917ac4a6f8f41df1b39e640 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 13 Sep 2023 09:28:04 -0600 Subject: [PATCH] Checkpoint --- crates/storybook/src/sketch.rs | 43 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/crates/storybook/src/sketch.rs b/crates/storybook/src/sketch.rs index c66b5970e8..087535bbde 100644 --- a/crates/storybook/src/sketch.rs +++ b/crates/storybook/src/sketch.rs @@ -114,7 +114,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { } impl<'a, 'w> WindowContext<'a, 'w> { - fn add_entity( + fn entity( &mut self, build_entity: impl FnOnce(&mut ViewContext<'_, '_, T>) -> T, ) -> Handle { @@ -541,6 +541,15 @@ impl Element for AnyView { } } +impl Clone for AnyView { + fn clone(&self) -> Self { + Self { + view: self.view.clone(), + parent_state_type: PhantomData, + } + } +} + pub struct Div(PhantomData); impl Element for Div { @@ -580,22 +589,28 @@ pub struct Workspace { left_panel: AnyView, } -fn workspace( - state: &mut Workspace, - cx: &mut ViewContext, -) -> impl Element { - div() - // .child(state.left_panel.render(cx)) +fn workspace(cx: &mut WindowContext) -> View { + let workspace = cx.entity(|cx| Workspace { + left_panel: collab_panel(cx).into_any(), + }); + view(workspace, |workspace, cx| { + div().child(workspace.left_panel.clone()) + }) } pub struct CollabPanel { filter_editor: Handle, } +fn collab_panel(cx: &mut WindowContext) -> View { + let panel = cx.entity(|cx| CollabPanel::new(cx)); + view(panel, |panel, cx| div()) +} + impl CollabPanel { fn new(cx: &mut ViewContext) -> Self { Self { - filter_editor: cx.add_entity(|cx| Editor::new(cx)), + filter_editor: cx.entity(|cx| Editor::new(cx)), } } } @@ -626,16 +641,6 @@ mod tests { #[test] fn test() { let mut cx = AppContext::new(); - - let workspace = cx.open_window(|cx| { - let workspace = cx.add_entity(|cx| Workspace { - left_panel: view(cx.add_entity(|cx| CollabPanel::new(cx)), |panel, cx| div()) - .into_any(), - }); - - view(workspace, |workspace, cx| div()) - }); - - // cx.open_window(workspace::Workspace, state) + cx.open_window(|cx| workspace(cx)); } }