mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 21:13:02 +00:00
Add ViewHandle::defer
It's like update, but happens after the current effect instead of synchronously. Also, it doesn't allow the callback to return a value because there would be nothing to do with it.
This commit is contained in:
parent
8b04c5d3ac
commit
b755b2d602
1 changed files with 11 additions and 0 deletions
|
@ -2938,6 +2938,17 @@ impl<T: View> ViewHandle<T> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn defer<C, F>(&self, cx: &mut C, update: F)
|
||||
where
|
||||
C: AsMut<MutableAppContext>,
|
||||
F: 'static + FnOnce(&mut T, &mut ViewContext<T>),
|
||||
{
|
||||
let this = self.clone();
|
||||
cx.as_mut().defer(Box::new(move |cx| {
|
||||
this.update(cx, |view, cx| update(view, cx));
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn is_focused(&self, cx: &AppContext) -> bool {
|
||||
cx.focused_view_id(self.window_id)
|
||||
.map_or(false, |focused_id| focused_id == self.view_id)
|
||||
|
|
Loading…
Reference in a new issue