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 {
dbg!("update");
self.pending_updates += 1;
let result = update(self);
self.pending_updates -= 1;
@ -242,6 +243,8 @@ impl<Thread: 'static + Send + Sync> AppContext<Thread> {
}
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),

View file

@ -59,6 +59,7 @@ 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)?;
@ -73,6 +74,7 @@ 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))
}
@ -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<()> {
self.state.update(cx, |state, cx| {
element
.downcast_mut::<AnyElement<S>>()
.unwrap()
.paint(state, None, cx)
let boxed_element = element.downcast_mut::<Box<dyn Any>>().unwrap();
let element = boxed_element.downcast_mut::<AnyElement<S>>().unwrap();
element.paint(state, None, cx)
})
}
}
@ -132,6 +134,7 @@ impl<S: 'static> Element for AnyView<S> {
element: &mut Self::FrameState,
cx: &mut ViewContext<Self::State>,
) -> Result<()> {
dbg!("Element.paint for AnyView");
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<()> {
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();
@ -90,6 +91,7 @@ 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();

View file

@ -15,25 +15,31 @@ mod workspace;
// }
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");
gpui3::App::production().run(|cx| {
let window = cx.open_window(
WindowOptions {
bounds: WindowBounds::Fixed(Bounds {
size: gpui3::Size {
width: 800_f32.into(),
height: 600_f32.into(),
},
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()
}),
..Default::default()
}),
..Default::default()
},
|cx| workspace(cx),
);
cx.activate(true);
},
|cx| {
dbg!("in build_root_view");
workspace(cx)
},
);
cx.activate(true);
});
});
}

View file

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