~starkingdoms/starkingdoms

ref: f18ae98396e29e3c8056f8ab79e51aa30c0564c9 starkingdoms/client/src/input/mod.rs -rw-r--r-- 1.5 KiB
f18ae983 — c0repwn3r fix renderers 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::error::Error;
use async_trait::async_trait;

/*
Functions the input subsystem needs to perform:
- init
- register and unregister event handlers for:
    - mouse movement
    - keydown, keyup, keypress
    - clicks
 */

#[async_trait]
pub trait InputSubsystem {
    async fn init() -> Result<Self, Box<dyn Error>> where Self: Sized;

    async fn register_on_mouse_move(&mut self, id: &str, callback: dyn FnMut(OnMouseMoveEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_mouse_move(&mut self, id: &str) -> Result<(), Box<dyn Error>>;

    async fn register_on_key_down(&mut self, id: &str, callback: dyn FnMut(OnKeyDownEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_key_down(&mut self, id: &str) -> Result<(), Box<dyn Error>>;

    async fn register_on_key_up(&mut self, id: &str, callback: dyn FnMut(OnKeyUpEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_key_up(&mut self, id: &str) -> Result<(), Box<dyn Error>>;

    async fn register_on_keypress(&mut self, id: &str, callback: dyn FnMut(OnKeypressEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_keypress(&mut self, id: &str) -> Result<(), Box<dyn Error>>;

    async fn register_on_click(&mut self, id: &str, callback: dyn FnMut(OnClickEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_click(&mut self, id: &str) -> Result<(), Box<dyn Error>>;
}

pub struct OnMouseMoveEvent {}
pub struct OnKeyDownEvent {}
pub struct OnKeyUpEvent {}
pub struct OnKeypressEvent {}
pub struct OnClickEvent {}