rich_sdl2_rust/event/joystick/
power_level.rs

1//! A representation of the power level of the battery in the joystick.
2
3use crate::bind;
4
5/// A power level of a joystick.
6#[derive(Debug, Clone, Copy)]
7#[non_exhaustive]
8pub enum PowerLevel {
9    /// A power level is unavailable.
10    Unknown,
11    /// The power level is a few left.
12    Empty,
13    /// The power level is on low.
14    Low,
15    /// The power level is on medium.
16    Medium,
17    /// The power level is full.
18    Full,
19    /// The power is coming from wired.
20    Wired,
21}
22
23impl From<bind::SDL_JoystickPowerLevel> for PowerLevel {
24    fn from(raw: bind::SDL_JoystickPowerLevel) -> Self {
25        match raw {
26            bind::SDL_JOYSTICK_POWER_EMPTY => PowerLevel::Empty,
27            bind::SDL_JOYSTICK_POWER_LOW => PowerLevel::Low,
28            bind::SDL_JOYSTICK_POWER_MEDIUM => PowerLevel::Medium,
29            bind::SDL_JOYSTICK_POWER_FULL => PowerLevel::Full,
30            bind::SDL_JOYSTICK_POWER_WIRED => PowerLevel::Wired,
31            _ => PowerLevel::Unknown,
32        }
33    }
34}