diff options
| author | HampusM <hampus@hampusmat.com> | 2026-09-22 18:22:46 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-09-22 18:22:46 +0200 |
| commit | c73ab25c9dbe40284cfd38beaf31e2a20a9810de (patch) | |
| tree | 51c5817a0c252a172c03a47e36886e563a4e623d /engine/src/windowing/keyboard.rs | |
| parent | 2ccda0cd5f81909fddc74d95f960f781a64bcae1 (diff) | |
refactor(engine): fix portion of clippy lints
Diffstat (limited to 'engine/src/windowing/keyboard.rs')
| -rw-r--r-- | engine/src/windowing/keyboard.rs | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/engine/src/windowing/keyboard.rs b/engine/src/windowing/keyboard.rs index dffa95e..a8ec6df 100644 --- a/engine/src/windowing/keyboard.rs +++ b/engine/src/windowing/keyboard.rs @@ -14,6 +14,7 @@ impl Keyboard { /// Returns whether the given key was just pressed this frame. This function will /// return `false` if the key was also pressed the previous frame. + #[must_use] pub fn just_pressed(&self, key: Key) -> bool { self.get_key_state(key) == KeyState::Pressed @@ -22,6 +23,7 @@ impl Keyboard /// Returns whether the given key was just released this frame. This function will /// return `false` if the key was also released the previous frame. + #[must_use] pub fn just_released(&self, key: Key) -> bool { self.get_key_state(key) == KeyState::Released @@ -29,12 +31,14 @@ impl Keyboard } /// Returns whether the given key is currently pressed. + #[must_use] pub fn pressed(&self, key: Key) -> bool { self.get_key_state(key) == KeyState::Pressed } /// Returns whether the given key is currently released. + #[must_use] pub fn released(&self, key: Key) -> bool { self.get_key_state(key) == KeyState::Released @@ -66,13 +70,11 @@ impl Keyboard { let bits = self.keys.get(key as usize); - let state = match bits & KEY_CURR_PRESSED_BITS { + match bits & KEY_CURR_PRESSED_BITS { KEY_CURR_PRESSED_BITS => KeyState::Pressed, 0 => KeyState::Released, _ => unreachable!(), - }; - - state + } } #[must_use] @@ -80,15 +82,14 @@ impl Keyboard { let bits = self.keys.get(key as usize); - let state = match bits & KEY_PREV_PRESSED_BITS { + match bits & KEY_PREV_PRESSED_BITS { KEY_PREV_PRESSED_BITS => KeyState::Pressed, 0 => KeyState::Released, _ => unreachable!(), - }; - - state + } } + #[must_use] pub fn text_keys(&self) -> &str { &self.text_keys @@ -109,7 +110,7 @@ impl Keyboard pub fn make_key_states_previous(&mut self) { for byte in self.keys.bytes_mut() { - *byte = (*byte >> 1) & 0b01010101 | *byte & 0b10101010; + *byte = (*byte >> 1) & 0b0101_0101 | *byte & 0b1010_1010; } } @@ -125,7 +126,7 @@ impl Keyboard #[non_exhaustive] pub enum Key { - /// <kbd>`</kbd> on a US keyboard. This is also called a backtick or grave. + #[doc = "<kbd>`</kbd> on a US keyboard. This is also called a backtick or grave."] /// This is the <kbd>半角</kbd>/<kbd>全角</kbd>/<kbd>漢字</kbd> /// (hankaku/zenkaku/kanji) key on Japanese keyboards Backquote, @@ -243,12 +244,12 @@ pub enum Key /// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>. AltLeft, /// <kbd>Alt</kbd>, <kbd>Option</kbd>, or <kbd>⌥</kbd>. - /// This is labeled <kbd>AltGr</kbd> on many keyboard layouts. + /// This is labeled <kbd>`AltGr`</kbd> on many keyboard layouts. AltRight, /// <kbd>Backspace</kbd> or <kbd>⌫</kbd>. /// Labeled <kbd>Delete</kbd> on Apple keyboards. Backspace, - /// <kbd>CapsLock</kbd> or <kbd>⇪</kbd> + /// <kbd>`CapsLock`</kbd> or <kbd>⇪</kbd> CapsLock, /// The application context menu key, which is typically found between the right /// <kbd>Super</kbd> key and the right <kbd>Control</kbd> key. @@ -276,7 +277,7 @@ pub enum Key /// Japanese: <kbd>カタカナ</kbd>/<kbd>ひらがな</kbd>/<kbd>ローマ字</kbd> /// (katakana/hiragana/romaji) KanaMode, - /// Korean: HangulMode <kbd>한/영</kbd> (han/yeong) + /// Korean: `HangulMode` <kbd>한/영</kbd> (han/yeong) /// /// Japanese (Mac keyboard): <kbd>か</kbd> (kana) Lang1, @@ -306,9 +307,9 @@ pub enum Key Home, /// <kbd>Insert</kbd> or <kbd>Ins</kbd>. Not present on Apple keyboards. Insert, - /// <kbd>Page Down</kbd>, <kbd>PgDn</kbd>, or <kbd>⇟</kbd> + /// <kbd>Page Down</kbd>, <kbd>`PgDn`</kbd>, or <kbd>⇟</kbd> PageDown, - /// <kbd>Page Up</kbd>, <kbd>PgUp</kbd>, or <kbd>⇞</kbd> + /// <kbd>Page Up</kbd>, <kbd>`PgUp`</kbd>, or <kbd>⇞</kbd> PageUp, /// <kbd>↓</kbd> ArrowDown, @@ -327,7 +328,7 @@ pub enum Key Numpad1, /// <kbd>2 ↓</kbd> on a keyboard. <kbd>2 ABC</kbd> on a phone or remote control Numpad2, - /// <kbd>3 PgDn</kbd> on a keyboard. <kbd>3 DEF</kbd> on a phone or remote control + /// <kbd>3 `PgDn`</kbd> on a keyboard. <kbd>3 DEF</kbd> on a phone or remote control Numpad3, /// <kbd>4 ←</kbd> on a keyboard. <kbd>4 GHI</kbd> on a phone or remote control Numpad4, @@ -340,15 +341,15 @@ pub enum Key Numpad7, /// <kbd>8 ↑</kbd> on a keyboard. <kbd>8 TUV</kbd> on a phone or remote control Numpad8, - /// <kbd>9 PgUp</kbd> on a keyboard. <kbd>9 WXYZ</kbd> or <kbd>9 WXY</kbd> on a phone - /// or remote control + /// <kbd>9 `PgUp`</kbd> on a keyboard. <kbd>9 WXYZ</kbd> or <kbd>9 WXY</kbd> on a + /// phone or remote control Numpad9, /// <kbd>+</kbd> NumpadAdd, /// Found on the Microsoft Natural Keyboard. NumpadBackspace, /// <kbd>C</kbd> or <kbd>A</kbd> (All Clear). Also for use with numpads that have a - /// <kbd>Clear</kbd> key that is separate from the <kbd>NumLock</kbd> key. On the + /// <kbd>Clear</kbd> key that is separate from the <kbd>`NumLock`</kbd> key. On the /// Mac, the numpad <kbd>Clear</kbd> key is encoded as [`NumLock`]. /// /// [`NumLock`]: Self::NumLock @@ -393,7 +394,7 @@ pub enum Key /// This key is typically found below the <kbd>7</kbd> key and to the left of /// the <kbd>0</kbd> key. /// - /// Use <kbd>"NumpadMultiply"</kbd> for the <kbd>*</kbd> key on + /// Use <kbd>"`NumpadMultiply`"</kbd> for the <kbd>*</kbd> key on /// numeric keypads. NumpadStar, /// <kbd>-</kbd> @@ -403,10 +404,10 @@ pub enum Key /// <kbd>Fn</kbd> This is typically a hardware key that does not generate a separate /// code. Fn, - /// <kbd>FLock</kbd> or <kbd>FnLock</kbd>. Function Lock key. Found on the Microsoft - /// Natural Keyboard. + /// <kbd>`FLock`</kbd> or <kbd>`FnLock`</kbd>. Function Lock key. Found on the + /// Microsoft Natural Keyboard. FnLock, - /// <kbd>PrtScr SysRq</kbd> or <kbd>Print Screen</kbd> + /// <kbd>`PrtScr` `SysRq`</kbd> or <kbd>Print Screen</kbd> PrintScreen, /// <kbd>Scroll Lock</kbd> ScrollLock, @@ -577,6 +578,7 @@ impl TryFrom<winit::keyboard::KeyCode> for Key { type Error = UnknownKeyCodeError; + #[allow(clippy::too_many_lines)] fn try_from(key_code: winit::keyboard::KeyCode) -> Result<Self, Self::Error> { match key_code { |
