Add Context::read_window, WindowHandle::root, and change ViewContext.view() to return a reference

This commit is contained in:
Mikayla 2023-11-08 22:11:19 -08:00
parent ad3b0bd227
commit 7a7ef1025d
No known key found for this signature in database
7 changed files with 103 additions and 6 deletions

View file

@ -1007,6 +1007,22 @@ impl Context for AppContext {
let entity = self.entities.read(handle);
read(entity, self)
}
fn read_window<R>(
&self,
window: &AnyWindowHandle,
read: impl FnOnce(AnyView, &AppContext) -> R,
) -> Result<R> {
let window = self
.windows
.get(window.id)
.ok_or_else(|| anyhow!("window not found"))?
.as_ref()
.unwrap();
let root_view = window.root_view.clone().unwrap();
Ok(read(root_view, self))
}
}
/// These effects are processed at the end of each application update cycle.