Checkpoint: Fix downcasting

This commit is contained in:
Marshall Bowers 2023-09-29 22:53:24 -04:00
parent f50a23accd
commit c7fc5f3ab7
5 changed files with 65 additions and 43 deletions

View file

@ -232,6 +232,7 @@ impl<Thread: 'static + Send + Sync> AppContext<Thread> {
} }
fn update<R>(&mut self, update: impl FnOnce(&mut Self) -> R) -> R { fn update<R>(&mut self, update: impl FnOnce(&mut Self) -> R) -> R {
dbg!("update");
self.pending_updates += 1; self.pending_updates += 1;
let result = update(self); let result = update(self);
self.pending_updates -= 1; self.pending_updates -= 1;
@ -242,6 +243,8 @@ impl<Thread: 'static + Send + Sync> AppContext<Thread> {
} }
fn flush_effects(&mut self) { fn flush_effects(&mut self) {
dbg!("Flush effects");
while let Some(effect) = self.pending_effects.pop_front() { while let Some(effect) = self.pending_effects.pop_front() {
match effect { match effect {
Effect::Notify(entity_id) => self.apply_notify_effect(entity_id), Effect::Notify(entity_id) => self.apply_notify_effect(entity_id),

View file

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

View file

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

View file

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

View file

@ -19,6 +19,7 @@ pub fn workspace(cx: &mut WindowContext) -> RootView<Workspace> {
impl Workspace { impl Workspace {
fn new(cx: &mut ViewContext<Self>) -> Self { fn new(cx: &mut ViewContext<Self>) -> Self {
dbg!("Workspace::new");
Self { Self {
left_panel: collab_panel(cx), left_panel: collab_panel(cx),
right_panel: collab_panel(cx), right_panel: collab_panel(cx),
@ -28,31 +29,38 @@ impl Workspace {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
let theme = rose_pine_dawn(); let theme = rose_pine_dawn();
themed(rose_pine_dawn(), cx, |cx| { dbg!("Render workspace");
div() div().size_full().fill(gpui3::hsla(0.83, 1., 0.5, 1.))
.size_full()
.flex() // TODO: Debug font not font.
.flex_col() //.child("Is this thing on?")
.font("Zed Sans Extended")
.gap_0() // themed(rose_pine_dawn(), cx, |cx| {
.justify_start() // div()
.items_start() // .size_full()
.text_color(theme.lowest.base.default.foreground) // .flex()
.fill(theme.middle.base.default.background) // .flex_col()
.child(titlebar(cx)) // .font("Zed Sans Extended")
.child( // .gap_0()
div() // .justify_start()
.flex_1() // .items_start()
.w_full() // .text_color(theme.lowest.base.default.foreground)
.flex() // // .fill(theme.middle.base.default.background)
.flex_row() // .fill(gpui3::hsla(0.83, 1., 0.5, 1.))
.overflow_hidden() // .child(titlebar(cx))
.child(self.left_panel.clone()) // .child(
.child(div().h_full().flex_1()) // div()
.child(self.right_panel.clone()), // .flex_1()
) // .w_full()
.child(statusbar::statusbar(cx)) // .flex()
}) // .flex_row()
// .overflow_hidden()
// .child(self.left_panel.clone())
// .child(div().h_full().flex_1())
// .child(self.right_panel.clone()),
// )
// .child(statusbar::statusbar(cx))
// })
} }
} }