This commit is contained in:
Antonio Scandurra 2023-10-24 10:31:35 +02:00
parent 18eb4a7292
commit 953857f8e3
5 changed files with 69 additions and 54 deletions

View file

@ -316,6 +316,9 @@ impl AppContext {
Effect::NotifyGlobalObservers { global_type } => {
self.apply_notify_global_observers_effect(global_type);
}
Effect::Defer { callback } => {
self.apply_defer_effect(callback);
}
}
} else {
break;
@ -436,6 +439,10 @@ impl AppContext {
.retain(&type_id, |observer| observer(self));
}
fn apply_defer_effect(&mut self, callback: Box<dyn FnOnce(&mut Self) + Send + Sync + 'static>) {
callback(self);
}
pub fn to_async(&self) -> AsyncAppContext {
AsyncAppContext {
app: unsafe { mem::transmute(self.this.clone()) },
@ -496,6 +503,12 @@ impl AppContext {
})
}
pub fn defer(&mut self, f: impl FnOnce(&mut AppContext) + 'static + Send + Sync) {
self.push_effect(Effect::Defer {
callback: Box::new(f),
});
}
pub fn text_system(&self) -> &Arc<TextSystem> {
&self.text_system
}
@ -772,6 +785,9 @@ pub(crate) enum Effect {
NotifyGlobalObservers {
global_type: TypeId,
},
Defer {
callback: Box<dyn FnOnce(&mut AppContext) + Send + Sync + 'static>,
},
}
pub(crate) struct AnyDrag {