Replace Window::parent_view_id() with Window::current_view() (#24212)

Chatted with @as-cii about limitations in the `Window::parent_view_id()`
API (see:
https://github.com/zed-industries/zed/pull/24182/commits/662153dcfdd80804f4041761c09c4a309d79f6d4)
and realized that I shouldn't be using the dispatch tree's data
structures as they are layout dependent. I've introduced a new stack to
`Window`, `rendered_entity_stack`, that tracks exactly which view's
elements are being drawn. As such, I've also been able to remove the
`Option<>` around the previous API.

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-02-04 10:50:21 -08:00 committed by GitHub
parent 667396c44b
commit e768eb0a34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 52 deletions

View file

@ -155,9 +155,11 @@ impl Element for AnyView {
let layout_id = window.request_layout(root_style, None, cx);
(layout_id, None)
} else {
let mut element = (self.render)(self, window, cx);
let layout_id = element.request_layout(window, cx);
(layout_id, Some(element))
window.with_rendered_view(self.entity_id(), |window| {
let mut element = (self.render)(self, window, cx);
let layout_id = element.request_layout(window, cx);
(layout_id, Some(element))
})
}
}
@ -197,12 +199,16 @@ impl Element for AnyView {
let refreshing = mem::replace(&mut window.refreshing, true);
let prepaint_start = window.prepaint_index();
let (mut element, accessed_entities) = cx.detect_accessed_entities(|cx| {
let mut element = (self.render)(self, window, cx);
element.layout_as_root(bounds.size.into(), window, cx);
element.prepaint_at(bounds.origin, window, cx);
element
});
let (mut element, accessed_entities) =
window.with_rendered_view(self.entity_id(), |window| {
cx.detect_accessed_entities(|cx| {
let mut element = (self.render)(self, window, cx);
element.layout_as_root(bounds.size.into(), window, cx);
element.prepaint_at(bounds.origin, window, cx);
element
})
});
let prepaint_end = window.prepaint_index();
window.refreshing = refreshing;
@ -223,7 +229,10 @@ impl Element for AnyView {
)
} else {
let mut element = element.take().unwrap();
element.prepaint(window, cx);
window.with_rendered_view(self.entity_id(), |window| {
element.prepaint(window, cx);
});
Some(element)
}
}
@ -247,7 +256,9 @@ impl Element for AnyView {
if let Some(element) = element {
let refreshing = mem::replace(&mut window.refreshing, true);
element.paint(window, cx);
window.with_rendered_view(self.entity_id(), |window| {
element.paint(window, cx);
});
window.refreshing = refreshing;
} else {
window.reuse_paint(element_state.paint_range.clone());