lgui_core/platform/
runtime.rs1use std::sync::Arc;
2
3use crate::{
4 core::{InputEvent, RuntimeOutput, UiTask, UiTaskSpawner, UiWake},
5 session::UiSession,
6};
7
8#[derive(Clone)]
9pub struct WakeHandle {
10 wake: UiWake,
11}
12
13impl WakeHandle {
14 pub fn new(wake: impl Fn() + Send + Sync + 'static) -> Self {
15 Self {
16 wake: Arc::new(wake),
17 }
18 }
19
20 pub fn wake(&self) {
21 (self.wake)();
22 }
23
24 pub fn as_ui_wake(&self) -> UiWake {
25 Arc::clone(&self.wake)
26 }
27}
28
29pub trait InputSink {
30 fn handle_input(&mut self, input: InputEvent) -> RuntimeOutput;
31}
32
33impl InputSink for UiSession {
34 fn handle_input(&mut self, input: InputEvent) -> RuntimeOutput {
35 UiSession::handle_input(self, input)
36 }
37}
38
39pub fn task_spawner(executor: impl Fn(UiTask) + Send + Sync + 'static) -> UiTaskSpawner {
40 Arc::new(executor)
41}
42
43#[cfg(test)]
44#[path = "runtime_test.rs"]
45mod tests;