pub struct Input { /* private fields */ }Implementations§
Source§impl Input
impl Input
Sourcepub fn mouse_position(&self) -> Point2
pub fn mouse_position(&self) -> Point2
Returns the current mouse position in pixels.
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let _window = runner
9 .create_window("Input Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let window2 = runner
14 .create_window("Second Window", Point2::new(800, 600))
15 .build()
16 .expect("Failed to create second window");
17
18 let input = runner.create_input(None);
19 let mut input2 = runner.create_input(Some(&window2));
20
21 input2.listen_keyboard_event(|key, pressed| {
22 println!("Second window keyboard event: {} - {}", key, pressed);
23 });
24
25 while runner.pump_events(None) {
26 if input.mouse_pressed_once("Left") {
27 println!("Mouse position: {:?}", input.mouse_position());
28 }
29
30 if input2.mouse_pressed_once("Left") {
31 println!("Mouse position in second window: {:?}", input2.mouse_position());
32 }
33 }
34}Sourcepub fn mouse_pressed(&self, button: &str) -> bool
pub fn mouse_pressed(&self, button: &str) -> bool
Returns true if the mouse button is currently pressed down.
Expected button names are:
- “Left”
- “Right”
- “Middle”
- “Back”
- “Forward”
Sourcepub fn mouse_pressed_once(&self, button: &str) -> bool
pub fn mouse_pressed_once(&self, button: &str) -> bool
Returns true if the mouse button was pressed once since the last call to this method.
See Input::mouse_pressed for expected button names.
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let _window = runner
9 .create_window("Input Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let window2 = runner
14 .create_window("Second Window", Point2::new(800, 600))
15 .build()
16 .expect("Failed to create second window");
17
18 let input = runner.create_input(None);
19 let mut input2 = runner.create_input(Some(&window2));
20
21 input2.listen_keyboard_event(|key, pressed| {
22 println!("Second window keyboard event: {} - {}", key, pressed);
23 });
24
25 while runner.pump_events(None) {
26 if input.mouse_pressed_once("Left") {
27 println!("Mouse position: {:?}", input.mouse_position());
28 }
29
30 if input2.mouse_pressed_once("Left") {
31 println!("Mouse position in second window: {:?}", input2.mouse_position());
32 }
33 }
34}Sourcepub fn key_pressed(&self, key: &str) -> bool
pub fn key_pressed(&self, key: &str) -> bool
Returns true if the key is currently pressed down.
The key should be a string representation of the key, such as “a”, “Enter”, “Space”, etc.
The normal key names are used, such as:
- “a”
- “b”
- etc.
The modifier keys are also supported such as:
- “Shift”
- etc.
Which also can be combined with other keys, such as:
- “A” (Shift + “a”)
- “B” (Shift + “b”)
- etc.
This also supports unknown scancodes!
Sourcepub fn key_pressed_once(&self, key: &str) -> bool
pub fn key_pressed_once(&self, key: &str) -> bool
Returns true if the key was pressed once since the last call to this method.
See Input::key_pressed for expected key names.
Sourcepub fn listen_mouse_event<F>(&mut self, event: F)
pub fn listen_mouse_event<F>(&mut self, event: F)
Listens for mouse events.
Sourcepub fn listen_mouse_move_event<F>(&mut self, event: F)
pub fn listen_mouse_move_event<F>(&mut self, event: F)
Listens for mouse move events.
Sourcepub fn listen_keyboard_event<F>(&mut self, event: F)
pub fn listen_keyboard_event<F>(&mut self, event: F)
Listens for keyboard events.
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let _window = runner
9 .create_window("Input Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let window2 = runner
14 .create_window("Second Window", Point2::new(800, 600))
15 .build()
16 .expect("Failed to create second window");
17
18 let input = runner.create_input(None);
19 let mut input2 = runner.create_input(Some(&window2));
20
21 input2.listen_keyboard_event(|key, pressed| {
22 println!("Second window keyboard event: {} - {}", key, pressed);
23 });
24
25 while runner.pump_events(None) {
26 if input.mouse_pressed_once("Left") {
27 println!("Mouse position: {:?}", input.mouse_position());
28 }
29
30 if input2.mouse_pressed_once("Left") {
31 println!("Mouse position in second window: {:?}", input2.mouse_position());
32 }
33 }
34}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Input
impl !RefUnwindSafe for Input
impl !Send for Input
impl !Sync for Input
impl Unpin for Input
impl !UnwindSafe for Input
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more