layout: Centralize handling key releases

This commit is contained in:
Dorota Czaplejewicz
2019-12-17 14:03:02 +00:00
parent 950310c8a5
commit 34db364a62
3 changed files with 198 additions and 115 deletions

View File

@ -29,6 +29,27 @@ pub struct KeyState {
pub action: Action,
}
impl KeyState {
#[must_use]
pub fn into_activated(self) -> KeyState {
match self.action {
Action::LockView { lock: _, unlock: _ } => KeyState {
locked: self.locked ^ true,
..self
},
_ => self,
}
}
#[must_use]
pub fn into_released(self) -> KeyState {
KeyState {
pressed: PressType::Released,
..self
}
}
}
/// Sorts an iterator by converting it to a Vector and back
fn sorted<'a, I: Iterator<Item=&'a str>>(
iter: I