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
38
39
40
41
42
43
44
45
46
47
48
49
//! Containment module for boring implmentations of the [`Display`] trait

use crate::axislike::VirtualDPad;
use crate::user_input::{InputKind, UserInput};
use std::fmt::Display;

impl Display for UserInput {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            // The representation of the button
            UserInput::Single(button) => write!(f, "{button}"),
            // The representation of each button, seperated by "+"
            UserInput::Chord(button_set) => {
                let mut string = String::default();
                for button in button_set.iter() {
                    string.push('+');
                    string.push_str(&button.to_string());
                }
                write!(f, "{string}")
            }
            UserInput::VirtualDPad(VirtualDPad {
                up,
                down,
                left,
                right,
            }) => {
                write!(
                    f,
                    "VirtualDPad(up: {}, down: {}, left: {}, right: {})",
                    up, down, left, right
                )
            }
        }
    }
}

impl Display for InputKind {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            InputKind::SingleAxis(axis) => write!(f, "{axis:?}"),
            InputKind::DualAxis(axis) => write!(f, "{axis:?}"),
            InputKind::GamepadButton(button) => write!(f, "{button:?}"),
            InputKind::Mouse(button) => write!(f, "{button:?}"),
            InputKind::MouseWheel(button) => write!(f, "{button:?}"),
            InputKind::MouseMotion(button) => write!(f, "{button:?}"),
            InputKind::Keyboard(button) => write!(f, "{button:?}"),
        }
    }
}