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);
|
println!("Menu id {} pressed", menu_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.get_keys().map(|keys| {
|
window.get_keys().iter().for_each(|key| {
|
||||||
for t in keys {
|
match key {
|
||||||
match t {
|
Key::W => println!("holding w!"),
|
||||||
Key::W => println!("holding w!"),
|
Key::T => println!("holding t!"),
|
||||||
Key::T => println!("holding t!"),
|
_ => (),
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -46,24 +46,16 @@ fn main() {
|
||||||
*i = (noise << 16) | (noise << 8) | noise;
|
*i = (noise << 16) | (noise << 8) | noise;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.get_keys().map(|keys| {
|
window.get_keys().iter().for_each(|key| match key {
|
||||||
for t in keys {
|
Key::W => println!("holding w!"),
|
||||||
match t {
|
Key::T => println!("holding t!"),
|
||||||
Key::W => println!("holding w!"),
|
_ => (),
|
||||||
Key::T => println!("holding t!"),
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window.get_keys_released().map(|keys| {
|
window.get_keys_released().iter().for_each(|key| match key {
|
||||||
for t in keys {
|
Key::W => println!("released w!"),
|
||||||
match t {
|
Key::T => println!("released t!"),
|
||||||
Key::W => println!("released w!"),
|
_ => (),
|
||||||
Key::T => println!("released t!"),
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window
|
window
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl KeyHandler {
|
||||||
self.keys[key as usize] = state;
|
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 index: u16 = 0;
|
||||||
let mut keys: Vec<Key> = Vec::new();
|
let mut keys: Vec<Key> = Vec::new();
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ impl KeyHandler {
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(keys)
|
keys
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self) {
|
pub fn update(&mut self) {
|
||||||
|
@ -73,7 +73,7 @@ impl KeyHandler {
|
||||||
self.key_callback = Some(callback);
|
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 index: u16 = 0;
|
||||||
let mut keys: Vec<Key> = Vec::new();
|
let mut keys: Vec<Key> = Vec::new();
|
||||||
|
|
||||||
|
@ -89,10 +89,10 @@ impl KeyHandler {
|
||||||
index += 1;
|
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();
|
let mut keys: Vec<Key> = Vec::new();
|
||||||
|
|
||||||
for (idx, is_down) in self.keys.iter().enumerate() {
|
for (idx, is_down) in self.keys.iter().enumerate() {
|
||||||
|
@ -103,7 +103,7 @@ impl KeyHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(keys)
|
keys
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -559,18 +559,16 @@ impl Window {
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use minifb::*;
|
/// # use minifb::*;
|
||||||
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.get_keys().map(|keys| {
|
/// window.get_keys().iter().for_each(|key|
|
||||||
/// for t in keys {
|
/// match key {
|
||||||
/// match t {
|
|
||||||
/// Key::W => println!("holding w"),
|
/// Key::W => println!("holding w"),
|
||||||
/// Key::T => println!("holding t"),
|
/// Key::T => println!("holding t"),
|
||||||
/// _ => (),
|
/// _ => (),
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// );
|
||||||
/// });
|
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
pub fn get_keys(&self) -> Vec<Key> {
|
||||||
self.0.get_keys()
|
self.0.get_keys()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,18 +581,16 @@ impl Window {
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use minifb::*;
|
/// # use minifb::*;
|
||||||
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.get_keys_pressed(KeyRepeat::No).map(|keys| {
|
/// window.get_keys_pressed(KeyRepeat::No).iter().for_each(|key|
|
||||||
/// for t in keys {
|
/// match key {
|
||||||
/// match t {
|
|
||||||
/// Key::W => println!("pressed w"),
|
/// Key::W => println!("pressed w"),
|
||||||
/// Key::T => println!("pressed t"),
|
/// Key::T => println!("pressed t"),
|
||||||
/// _ => (),
|
/// _ => (),
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// );
|
||||||
/// });
|
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[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)
|
self.0.get_keys_pressed(repeat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,18 +602,16 @@ impl Window {
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use minifb::*;
|
/// # use minifb::*;
|
||||||
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.get_keys_released().map(|keys| {
|
/// window.get_keys_released().iter().for_each(|key|
|
||||||
/// for t in keys {
|
/// match key {
|
||||||
/// match t {
|
|
||||||
/// Key::W => println!("released w"),
|
/// Key::W => println!("released w"),
|
||||||
/// Key::T => println!("released t"),
|
/// Key::T => println!("released t"),
|
||||||
/// _ => (),
|
/// _ => (),
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// );
|
||||||
/// });
|
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||||
self.0.get_keys_released()
|
self.0.get_keys_released()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -479,17 +479,17 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
pub fn get_keys(&self) -> Vec<Key> {
|
||||||
self.key_handler.get_keys()
|
self.key_handler.get_keys()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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)
|
self.key_handler.get_keys_pressed(repeat)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||||
self.key_handler.get_keys_released()
|
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 {
|
match *self {
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
Window::X11(ref w) => w.get_keys(),
|
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 {
|
match *self {
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
Window::X11(ref w) => w.get_keys_pressed(repeat),
|
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 {
|
match *self {
|
||||||
#[cfg(feature = "x11")]
|
#[cfg(feature = "x11")]
|
||||||
Window::X11(ref w) => w.get_keys_released(),
|
Window::X11(ref w) => w.get_keys_released(),
|
||||||
|
|
|
@ -588,15 +588,15 @@ impl Window {
|
||||||
(self.width as usize, self.height as usize)
|
(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()
|
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)
|
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()
|
self.key_handler.get_keys_released()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -674,17 +674,17 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
pub fn get_keys(&self) -> Vec<Key> {
|
||||||
self.key_handler.get_keys()
|
self.key_handler.get_keys()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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)
|
self.key_handler.get_keys_pressed(repeat)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||||
self.key_handler.get_keys_released()
|
self.key_handler.get_keys_released()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,15 +188,15 @@ impl Window {
|
||||||
self.window.set_mouse_cursor(visibility);
|
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()
|
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)
|
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()
|
self.key_handler.get_keys_released()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -719,17 +719,17 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_keys(&self) -> Option<Vec<Key>> {
|
pub fn get_keys(&self) -> Vec<Key> {
|
||||||
self.key_handler.get_keys()
|
self.key_handler.get_keys()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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)
|
self.key_handler.get_keys_pressed(repeat)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_keys_released(&self) -> Option<Vec<Key>> {
|
pub fn get_keys_released(&self) -> Vec<Key> {
|
||||||
self.key_handler.get_keys_released()
|
self.key_handler.get_keys_released()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue