Explicitly push a node in the dispatch tree when painting a new view

This commit is contained in:
Antonio Scandurra 2024-01-11 12:48:05 +01:00
parent 142a8b68c8
commit d088ace404
4 changed files with 21 additions and 19 deletions

View file

@ -1942,13 +1942,12 @@ impl<'a> WindowContext<'a> {
focus_handle: Option<FocusHandle>,
f: impl FnOnce(Option<FocusHandle>, &mut Self) -> R,
) -> R {
let parent_view_id = self.parent_view_id();
let window = &mut self.window;
let focus_id = focus_handle.as_ref().map(|handle| handle.id);
window
.next_frame
.dispatch_tree
.push_node(context.clone(), focus_id, parent_view_id);
.push_node(context.clone(), focus_id, None);
let result = f(focus_handle, self);
@ -1968,6 +1967,18 @@ impl<'a> WindowContext<'a> {
result
}
pub(crate) fn paint_view<R>(&mut self, view_id: EntityId, f: impl FnOnce(&mut Self) -> R) -> R {
self.with_view_id(view_id, |cx| {
cx.window
.next_frame
.dispatch_tree
.push_node(None, None, Some(view_id));
let result = f(cx);
cx.window.next_frame.dispatch_tree.pop_node();
result
})
}
/// Update or initialize state for an element with the given id that lives across multiple
/// frames. If an element with this id existed in the rendered frame, its state will be passed
/// to the given closure. The state returned by the closure will be stored so it can be referenced