WIP
This commit is contained in:
+20
-3
@@ -115,12 +115,12 @@ impl AppContext {
|
||||
|
||||
pub(crate) fn update_window<R>(
|
||||
&mut self,
|
||||
handle: AnyWindowHandle,
|
||||
id: WindowId,
|
||||
update: impl FnOnce(&mut WindowContext) -> R,
|
||||
) -> Result<R> {
|
||||
let mut window = self
|
||||
.windows
|
||||
.get_mut(handle.id)
|
||||
.get_mut(id)
|
||||
.ok_or_else(|| anyhow!("window not found"))?
|
||||
.take()
|
||||
.unwrap();
|
||||
@@ -129,7 +129,7 @@ impl AppContext {
|
||||
window.dirty = true;
|
||||
|
||||
self.windows
|
||||
.get_mut(handle.id)
|
||||
.get_mut(id)
|
||||
.ok_or_else(|| anyhow!("window not found"))?
|
||||
.replace(window);
|
||||
|
||||
@@ -152,6 +152,23 @@ impl AppContext {
|
||||
Effect::Notify(entity_id) => self.apply_notify_effect(entity_id),
|
||||
}
|
||||
}
|
||||
|
||||
let dirty_window_ids = self
|
||||
.windows
|
||||
.iter()
|
||||
.filter_map(|(window_id, window)| {
|
||||
let window = window.as_ref().unwrap();
|
||||
if window.dirty {
|
||||
Some(window_id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for dirty_window_id in dirty_window_ids {
|
||||
self.update_window(dirty_window_id, |cx| cx.draw());
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_notify_effect(&mut self, updated_entity: EntityId) {
|
||||
|
||||
@@ -133,7 +133,7 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
||||
if window_handle == self.window.handle {
|
||||
Ok(update(self))
|
||||
} else {
|
||||
self.app.update_window(window_handle, update)
|
||||
self.app.update_window(window_handle.id, update)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,7 +258,7 @@ impl<'a, 'w, T: Send + Sync + 'static> ViewContext<'a, 'w, T> {
|
||||
.entry(handle.id)
|
||||
.or_default()
|
||||
.push(Arc::new(move |cx| {
|
||||
cx.update_window(window_handle, |cx| {
|
||||
cx.update_window(window_handle.id, |cx| {
|
||||
if let Some(handle) = handle.upgrade(cx) {
|
||||
this.update(cx, |this, cx| on_notify(this, handle, cx))
|
||||
.is_ok()
|
||||
|
||||
Reference in New Issue
Block a user