mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 12:16:44 +01:00
36 lines
1,012 B
Rust
36 lines
1,012 B
Rust
use crate::*;
|
|
use std::time::Duration;
|
|
use std::thread::JoinHandle;
|
|
|
|
/// Event source
|
|
pub trait Input: Send + Sync + Sized {
|
|
/// Type of input event
|
|
type Event;
|
|
/// Result of handling input
|
|
type Handled; // TODO: make this an Option<Box dyn Command<Self>> containing the undo
|
|
/// Currently handled event
|
|
fn event (&self) -> &Self::Event;
|
|
/// Whether component should exit
|
|
fn is_done (&self) -> bool;
|
|
/// Mark component as done
|
|
fn done (&self);
|
|
}
|
|
|
|
/// Input thread entrypoint.
|
|
pub trait InputRun<T> {
|
|
fn run_input (engine: T, state: Self, timer: Duration) -> JoinHandle<()>;
|
|
}
|
|
|
|
/// Handle input through a mutable reference.
|
|
pub trait Handle<E: Input>: Send + Sync {
|
|
fn handle (&mut self, _input: &E) -> Perhaps<E::Handled> {
|
|
Ok(None)
|
|
}
|
|
}
|
|
|
|
/// Handle input through an immutable reference (e.g. [Arc<RwLock>] or [Arc<Mutex>])
|
|
pub trait HandleRef<E: Input>: Send + Sync {
|
|
fn handle (&self, _input: &E) -> Perhaps<E::Handled> {
|
|
Ok(None)
|
|
}
|
|
}
|