mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 11:21:30 +11:00
Changing return types of get_keys from Option<Vec<Key>> to Vec<Key> (#260)
* KeyHandler: Updated return type to Vec on get_keys * Window: Updated Window structs get_keys return type across all currently supported OS's * Updated return type of get_keys of Window, and updated the docs for all related functions * Docs: Corrected incorrect variable ident in docs post update * Resolved error resulting from get_keys return type change * Formatting: Ran cargo fmt Co-authored-by: Zij-IT <elijah.reed@hartvigsen.xyz>
This commit is contained in:
parent
67fe3a6f29
commit
deb235507f
|
@ -100,13 +100,11 @@ fn main() {
|
|||
println!("Menu id {} pressed", menu_id);
|
||||
});
|
||||
|
||||
window.get_keys().map(|keys| {
|
||||
for t in keys {
|
||||
match t {
|
||||
Key::W => println!("holding w!"),
|
||||
Key::T => println!("holding t!"),
|
||||
_ => (),
|
||||
}
|
||||
window.get_keys().iter().for_each(|key| {
|
||||
match key {
|
||||
Key::W => println!("holding w!"),
|
||||
Key::T => println!("holding t!"),
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -46,24 +46,16 @@ fn main() {
|
|||
*i = (noise << 16) | (noise << 8) | noise;
|
||||
}
|
||||
|
||||
window.get_keys().map(|keys| {
|
||||
for t in keys {
|
||||
match t {
|
||||
Key::W => println!("holding w!"),
|
||||
Key::T => println!("holding t!"),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
window.get_keys().iter().for_each(|key| match key {
|
||||
Key::W => println!("holding w!"),
|
||||
Key::T => println!("holding t!"),
|
||||
_ => (),
|
||||
});
|
||||
|
||||
window.get_keys_released().map(|keys| {
|
||||
for t in keys {
|
||||
match t {
|
||||
Key::W => println!("released w!"),
|
||||
Key::T => println!("released t!"),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
window.get_keys_released().iter().for_each(|key| match key {
|
||||
Key::W => println!("released w!"),
|
||||
Key::T => println!("released t!"),
|
||||
_ => (),
|
||||
});
|
||||
|
||||
window
|
||||
|
|
|
@ -32,7 +32,7 @@ impl KeyHandler {
|
|||
self.keys[key as usize] = state;
|
||||
}
|
||||
|
||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys(&self) -> Vec<Key> {
|
||||
let mut index: u16 = 0;
|
||||
let mut keys: Vec<Key> = Vec::new();
|
||||
|
||||
|
@ -46,7 +46,7 @@ impl KeyHandler {
|
|||
index += 1;
|
||||
}
|
||||
|
||||
Some(keys)
|
||||
keys
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
|
@ -73,7 +73,7 @@ impl KeyHandler {
|
|||
self.key_callback = Some(callback);
|
||||
}
|
||||
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> {
|
||||
let mut index: u16 = 0;
|
||||
let mut keys: Vec<Key> = Vec::new();
|
||||
|
||||
|
@ -89,10 +89,10 @@ impl KeyHandler {
|
|||
index += 1;
|
||||
}
|
||||
|
||||
Some(keys)
|
||||
keys
|
||||
}
|
||||
|
||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||
let mut keys: Vec<Key> = Vec::new();
|
||||
|
||||
for (idx, is_down) in self.keys.iter().enumerate() {
|
||||
|
@ -103,7 +103,7 @@ impl KeyHandler {
|
|||
}
|
||||
}
|
||||
|
||||
Some(keys)
|
||||
keys
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -559,18 +559,16 @@ impl Window {
|
|||
/// ```no_run
|
||||
/// # use minifb::*;
|
||||
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||
/// window.get_keys().map(|keys| {
|
||||
/// for t in keys {
|
||||
/// match t {
|
||||
/// window.get_keys().iter().for_each(|key|
|
||||
/// match key {
|
||||
/// Key::W => println!("holding w"),
|
||||
/// Key::T => println!("holding t"),
|
||||
/// _ => (),
|
||||
/// }
|
||||
/// }
|
||||
/// });
|
||||
/// );
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys(&self) -> Vec<Key> {
|
||||
self.0.get_keys()
|
||||
}
|
||||
|
||||
|
@ -583,18 +581,16 @@ impl Window {
|
|||
/// ```no_run
|
||||
/// # use minifb::*;
|
||||
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||
/// window.get_keys_pressed(KeyRepeat::No).map(|keys| {
|
||||
/// for t in keys {
|
||||
/// match t {
|
||||
/// window.get_keys_pressed(KeyRepeat::No).iter().for_each(|key|
|
||||
/// match key {
|
||||
/// Key::W => println!("pressed w"),
|
||||
/// Key::T => println!("pressed t"),
|
||||
/// _ => (),
|
||||
/// }
|
||||
/// }
|
||||
/// });
|
||||
/// );
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> {
|
||||
self.0.get_keys_pressed(repeat)
|
||||
}
|
||||
|
||||
|
@ -606,18 +602,16 @@ impl Window {
|
|||
/// ```no_run
|
||||
/// # use minifb::*;
|
||||
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||
/// window.get_keys_released().map(|keys| {
|
||||
/// for t in keys {
|
||||
/// match t {
|
||||
/// window.get_keys_released().iter().for_each(|key|
|
||||
/// match key {
|
||||
/// Key::W => println!("released w"),
|
||||
/// Key::T => println!("released t"),
|
||||
/// _ => (),
|
||||
/// }
|
||||
/// }
|
||||
/// });
|
||||
/// );
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||
self.0.get_keys_released()
|
||||
}
|
||||
|
||||
|
|
|
@ -479,17 +479,17 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> {
|
||||
self.key_handler.get_keys_pressed(repeat)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys_released()
|
||||
}
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys(&self) -> Vec<Key> {
|
||||
match *self {
|
||||
#[cfg(feature = "x11")]
|
||||
Window::X11(ref w) => w.get_keys(),
|
||||
|
@ -215,7 +215,7 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> {
|
||||
match *self {
|
||||
#[cfg(feature = "x11")]
|
||||
Window::X11(ref w) => w.get_keys_pressed(repeat),
|
||||
|
@ -224,7 +224,7 @@ impl Window {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||
match *self {
|
||||
#[cfg(feature = "x11")]
|
||||
Window::X11(ref w) => w.get_keys_released(),
|
||||
|
|
|
@ -588,15 +588,15 @@ impl Window {
|
|||
(self.width as usize, self.height as usize)
|
||||
}
|
||||
|
||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys()
|
||||
}
|
||||
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> {
|
||||
self.key_handler.get_keys_pressed(repeat)
|
||||
}
|
||||
|
||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys_released()
|
||||
}
|
||||
|
||||
|
|
|
@ -674,17 +674,17 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> {
|
||||
self.key_handler.get_keys_pressed(repeat)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys_released()
|
||||
}
|
||||
|
||||
|
|
|
@ -188,15 +188,15 @@ impl Window {
|
|||
self.window.set_mouse_cursor(visibility);
|
||||
}
|
||||
|
||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys()
|
||||
}
|
||||
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> {
|
||||
self.key_handler.get_keys_pressed(repeat)
|
||||
}
|
||||
|
||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys_released()
|
||||
}
|
||||
|
||||
|
|
|
@ -719,17 +719,17 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> {
|
||||
self.key_handler.get_keys_pressed(repeat)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
||||
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||
self.key_handler.get_keys_released()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue