#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u32)] pub enum ButtonId { Up = 0, Down = 1, Left = 2, Right = 3, A = 4, B = 5, X = 6, Y = 7, L = 8, R = 9, Start = 10, Select = 11, } #[derive(Default, Clone, Copy, Debug)] pub struct Button { pub pressed: bool, pub released: bool, pub down: bool, pub hold_frames: u32, } impl Button { pub fn begin_frame(&mut self, is_down_now: bool) { let was_down = self.down; self.down = is_down_now.clone(); self.pressed = !was_down && self.down; self.released = was_down && !self.down; if self.down { self.hold_frames = self.hold_frames.saturating_add(1); } else { self.hold_frames = 0; } } }