Add Context::read_window, WindowHandle::root, and change ViewContext.view() to return a reference
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -239,6 +239,14 @@ impl<'a, T> Context for ModelContext<'a, T> {
|
||||
{
|
||||
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<T> Borrow<AppContext> for ModelContext<'_, T> {
|
||||
|
||||
@@ -58,6 +58,15 @@ impl Context for TestAppContext {
|
||||
let app = self.app.borrow();
|
||||
app.read_model(handle, read)
|
||||
}
|
||||
|
||||
fn read_window<R>(
|
||||
&self,
|
||||
window: &AnyWindowHandle,
|
||||
read: impl FnOnce(AnyView, &AppContext) -> R,
|
||||
) -> Result<R> {
|
||||
let app = self.app.borrow();
|
||||
app.read_window(window, read)
|
||||
}
|
||||
}
|
||||
|
||||
impl TestAppContext {
|
||||
@@ -146,6 +155,11 @@ impl TestAppContext {
|
||||
Some(read(lock.try_global()?, &lock))
|
||||
}
|
||||
|
||||
pub fn set_global<G: 'static, R>(&mut self, global: G) {
|
||||
let mut lock = self.app.borrow_mut();
|
||||
lock.set_global(global);
|
||||
}
|
||||
|
||||
pub fn update_global<G: 'static, R>(
|
||||
&mut self,
|
||||
update: impl FnOnce(&mut G, &mut AppContext) -> R,
|
||||
|
||||
Reference in New Issue
Block a user