WIP

Nathan Sobo created

Change summary

crates/gpui3/src/app.rs                         | 27 ++++++--------
crates/gpui3/src/platform/mac/metal_renderer.rs |  1 
crates/gpui3/src/view.rs                        |  7 +--
crates/gpui3/src/window.rs                      |  4 -
crates/storybook2/src/storybook2.rs             | 33 ++++++++----------
crates/storybook2/src/workspace.rs              |  5 --
6 files changed, 30 insertions(+), 47 deletions(-)

Detailed changes

crates/gpui3/src/app.rs 🔗

@@ -230,19 +230,16 @@ impl<Thread: 'static + Send + Sync> AppContext<Thread> {
     }
 
     fn update<R>(&mut self, update: impl FnOnce(&mut Self) -> R) -> R {
-        dbg!("update");
         self.pending_updates += 1;
         let result = update(self);
-        self.pending_updates -= 1;
-        if self.pending_updates == 0 {
+        if self.pending_updates == 1 {
             self.flush_effects();
         }
+        self.pending_updates -= 1;
         result
     }
 
     fn flush_effects(&mut self) {
-        dbg!("Flush effects");
-
         while let Some(effect) = self.pending_effects.pop_front() {
             match effect {
                 Effect::Notify(entity_id) => self.apply_notify_effect(entity_id),
@@ -319,16 +316,16 @@ impl AppContext<MainThread> {
         options: crate::WindowOptions,
         build_root_view: impl FnOnce(&mut WindowContext) -> RootView<S> + Send + 'static,
     ) -> WindowHandle<S> {
-        let id = self.windows.insert(None);
-        let handle = WindowHandle::new(id);
-        let mut window = Window::new(handle.into(), options, self);
-        let root_view = build_root_view(&mut WindowContext::mutable(
-            self.downcast_mut(),
-            &mut window,
-        ));
-        window.root_view.replace(root_view.into_any());
-        self.windows.get_mut(id).unwrap().replace(window);
-        handle
+        self.update(|cx| {
+            let id = cx.windows.insert(None);
+            let handle = WindowHandle::new(id);
+            let mut window = Window::new(handle.into(), options, cx);
+            let root_view =
+                build_root_view(&mut WindowContext::mutable(cx.downcast_mut(), &mut window));
+            window.root_view.replace(root_view.into_any());
+            cx.windows.get_mut(id).unwrap().replace(window);
+            handle
+        })
     }
 }
 

crates/gpui3/src/view.rs 🔗

@@ -59,7 +59,6 @@ impl<S: Send + Sync + 'static, P: Send + 'static> Element for View<S, P> {
         _: &mut Self::State,
         cx: &mut ViewContext<Self::State>,
     ) -> Result<(LayoutId, Self::FrameState)> {
-        dbg!("Layout view");
         self.state.update(cx, |state, cx| {
             let mut element = (self.render)(state, cx);
             let layout_id = element.layout(state, cx)?;
@@ -74,7 +73,6 @@ impl<S: Send + Sync + 'static, P: Send + 'static> Element for View<S, P> {
         element: &mut Self::FrameState,
         cx: &mut ViewContext<Self::State>,
     ) -> Result<()> {
-        dbg!("Paint view");
         self.state
             .update(cx, |state, cx| element.paint(state, None, cx))
     }
@@ -128,11 +126,10 @@ impl<S: 'static> Element for AnyView<S> {
     fn paint(
         &mut self,
         layout: Layout,
-        _: &mut Self::State,
-        element: &mut Self::FrameState,
+        _: &mut (),
+        element: &mut Box<dyn Any>,
         cx: &mut ViewContext<Self::State>,
     ) -> Result<()> {
-        dbg!("Element.paint for AnyView");
         self.view.lock().paint(layout, element.as_mut(), cx)
     }
 }

crates/gpui3/src/window.rs 🔗

@@ -128,7 +128,6 @@ impl<'a, 'w> WindowContext<'a, 'w> {
     }
 
     pub(crate) fn draw(&mut self) -> Result<()> {
-        dbg!("Draw");
         let unit_entity = self.unit_entity.clone();
         self.update_entity(&unit_entity, |_, cx| {
             let mut root_view = cx.window.root_view.take().unwrap();
@@ -138,14 +137,13 @@ impl<'a, 'w> WindowContext<'a, 'w> {
                 .layout_engine
                 .compute_layout(root_layout_id, available_space)?;
             let layout = cx.window.layout_engine.layout(root_layout_id)?;
-            dbg!("Paint root view");
             root_view.paint(layout, &mut (), &mut frame_state, cx)?;
             cx.window.root_view = Some(root_view);
             let scene = cx.window.scene.take();
 
             dbg!(&scene);
 
-            // todo!
+            // // todo!
             // self.run_on_main(|cx| {
             //     cx.window
             //         .platform_window

crates/storybook2/src/storybook2.rs 🔗

@@ -20,26 +20,21 @@ fn main() {
     SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
 
     gpui3::App::production().run(|cx| {
-        cx.run_on_main(|cx| {
-            dbg!("Run on main");
-            let window = cx.open_window(
-                WindowOptions {
-                    bounds: WindowBounds::Fixed(Bounds {
-                        size: gpui3::Size {
-                            width: 800_f32.into(),
-                            height: 600_f32.into(),
-                        },
-                        ..Default::default()
-                    }),
+        let window = cx.open_window(
+            WindowOptions {
+                bounds: WindowBounds::Fixed(Bounds {
+                    size: gpui3::Size {
+                        width: 800_f32.into(),
+                        height: 600_f32.into(),
+                    },
                     ..Default::default()
-                },
-                |cx| {
-                    dbg!("in build_root_view");
-                    workspace(cx)
-                },
-            );
-            cx.activate(true);
-        });
+                }),
+                ..Default::default()
+            },
+            |cx| workspace(cx),
+        );
+
+        cx.activate(true);
     });
 }
 

crates/storybook2/src/workspace.rs 🔗

@@ -19,7 +19,6 @@ pub fn workspace(cx: &mut WindowContext) -> RootView<Workspace> {
 
 impl Workspace {
     fn new(cx: &mut ViewContext<Self>) -> Self {
-        dbg!("Workspace::new");
         Self {
             left_panel: collab_panel(cx),
             right_panel: collab_panel(cx),
@@ -28,9 +27,7 @@ impl Workspace {
 
     fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
         let theme = rose_pine_dawn();
-
-        dbg!("Render workspace");
-        div()
+        div().fill(theme.middle.positive.default.background)
 
         // TODO: Implement style.
         //.size_full().fill(gpui3::hsla(0.83, 1., 0.5, 1.))