Checkpoint: Fix downcasting
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user