Add Context::read_window, WindowHandle::root, and change ViewContext.view() to return a reference
This commit is contained in:
parent
ad3b0bd227
commit
7a7ef1025d
7 changed files with 103 additions and 6 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue