Skip to main content

devotee_backend/
middling.rs

1/// So-so display surface trait for reuse purposes.
2pub trait Surface {
3    /// Specific texel type.
4    type Texel;
5
6    /// Get texel given its coordinates.
7    fn texel(&self, x: u32, y: u32) -> Option<Self::Texel>;
8
9    /// Set texel given its coordinates.
10    fn set_texel(&mut self, x: u32, y: u32, value: Self::Texel);
11
12    /// Clear the surface with the given color.
13    fn clear(&mut self, value: Self::Texel);
14
15    /// Get surface width.
16    fn width(&self) -> u32;
17
18    /// Get surface height.
19    fn height(&self) -> u32;
20}
21
22/// The surface that can be filled directly.
23pub trait Fill<I>: Surface {
24    /// Fill the surface from the provided `data`.
25    fn fill_from(&mut self, data: I);
26}
27
28/// Input handler trait with optional input caching.
29pub trait InputHandler<Event, EventContext> {
30    /// Handle input event, optionally consume it.
31    fn handle_event(&mut self, event: Event, event_context: &EventContext) -> Option<Event>;
32
33    /// Update internal state over tick event.
34    fn update(&mut self);
35}
36
37/// Event context generalization.
38pub trait EventContext<EventSpace> {
39    /// Surface space coordinates representation.
40    type SurfaceSpace;
41
42    /// Recalculate from the event space coordinates into the surface space coordinates.
43    fn estimate_surface_space(&self, event_space: EventSpace) -> Self::SurfaceSpace;
44}