Skip to main content

lgui_core/application/
handle.rs

1use std::sync::Arc;
2
3pub type ApplicationTask = Box<dyn FnOnce() + Send + 'static>;
4
5/// Cloneable, platform-neutral access to the running application event loop.
6#[derive(Clone)]
7pub struct ApplicationHandle {
8    post: Arc<dyn Fn(ApplicationTask) + Send + Sync>,
9    request_frame: Arc<dyn Fn() + Send + Sync>,
10}
11
12impl ApplicationHandle {
13    pub fn new(
14        post: impl Fn(ApplicationTask) + Send + Sync + 'static,
15        request_frame: impl Fn() + Send + Sync + 'static,
16    ) -> Self {
17        Self {
18            post: Arc::new(post),
19            request_frame: Arc::new(request_frame),
20        }
21    }
22
23    pub fn post(&self, task: impl FnOnce() + Send + 'static) {
24        (self.post)(Box::new(task));
25    }
26
27    pub fn request_frame(&self) {
28        (self.request_frame)();
29    }
30}