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

@ -66,6 +66,16 @@ impl Context for AsyncAppContext {
let mut lock = app.borrow_mut();
lock.update_window(window, f)
}
fn read_window<R>(
&self,
window: &AnyWindowHandle,
read: impl FnOnce(AnyView, &AppContext) -> R,
) -> Result<R> {
let app = self.app.upgrade().context("app was released")?;
let lock = app.borrow();
lock.read_window(window, read)
}
}
impl AsyncAppContext {
@ -250,6 +260,14 @@ impl Context for AsyncWindowContext {
{
self.app.read_model(handle, read)
}
fn read_window<R>(
&self,
window: &AnyWindowHandle,
read: impl FnOnce(AnyView, &AppContext) -> R,
) -> Result<R> {
self.app.read_window(window, read)
}
}
impl VisualContext for AsyncWindowContext {