devotee_backend/
middling.rs

1/// Type trait that can point on a texel reference.
2pub trait TexelDesignatorRef<'a> {
3    /// Texel reference.
4    type TexelRef;
5}
6
7/// Type trait that can point on a mutable texel reference.
8pub trait TexelDesignatorMut<'a> {
9    /// Mutable texel reference.
10    type TexelMut;
11}
12
13/// Helper type to represent texel reference.
14pub type TexelRef<'a, This> = <This as TexelDesignatorRef<'a>>::TexelRef;
15
16/// Helper type to represent mutable texel reference.
17pub type TexelMut<'a, This> = <This as TexelDesignatorMut<'a>>::TexelMut;
18
19/// So-so display surface trait for reuse purposes.
20pub trait Surface: for<'a> TexelDesignatorRef<'a> + for<'a> TexelDesignatorMut<'a> {
21    /// Specific texel type.
22    type Texel;
23
24    /// Get texel reference given its coordinates.
25    fn texel(&self, x: u32, y: u32) -> Option<TexelRef<'_, Self>>;
26
27    /// Get mutable texel reference given its coordinates.
28    fn texel_mut(&mut self, x: u32, y: u32) -> Option<TexelMut<'_, Self>>;
29
30    /// Clear the surface with the given color.
31    fn clear(&mut self, value: Self::Texel);
32
33    /// Get surface width.
34    fn width(&self) -> u32;
35
36    /// Get surface height.
37    fn height(&self) -> u32;
38}
39
40/// Input handler trait with optional input caching.
41pub trait InputHandler<Event, EventContext> {
42    /// Handle input event, optionally consume it.
43    fn handle_event(&mut self, event: Event, event_context: &EventContext) -> Option<Event>;
44
45    /// Update internal state over tick event.
46    fn update(&mut self);
47}
48
49/// Event context generalization.
50pub trait EventContext<EventSpace> {
51    /// Surface space coordinates representation.
52    type SurfaceSpace;
53
54    /// Recalculate from the event space coordinates into the surface space coordinates.
55    fn estimate_surface_space(&self, event_space: EventSpace) -> Self::SurfaceSpace;
56}