From b755b2d6024615852cc7d70f815293f10479c499 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sat, 22 Jan 2022 13:21:59 -0700 Subject: [PATCH] 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. --- crates/gpui/src/app.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 37b73b9ca0..31efb4991e 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -2938,6 +2938,17 @@ impl ViewHandle { }) } + pub fn defer(&self, cx: &mut C, update: F) + where + C: AsMut, + F: 'static + FnOnce(&mut T, &mut ViewContext), + { + 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)