Input

Struct Input 

Source
pub struct Input { /* private fields */ }

Implementations§

Source§

impl Input

Source

pub fn mouse_position(&self) -> Point2

Returns the current mouse position in pixels.

Examples found in repository?
examples/input.rs (line 27)
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}
Source

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”
Source

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?
examples/input.rs (line 26)
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}
Source

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!

Source

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.

Source

pub fn listen_mouse_event<F>(&mut self, event: F)
where F: Fn(&str, Point2, bool) + Send + Sync + 'static,

Listens for mouse events.

Source

pub fn listen_mouse_move_event<F>(&mut self, event: F)
where F: Fn(Point2) + Send + Sync + 'static,

Listens for mouse move events.

Source

pub fn listen_keyboard_event<F>(&mut self, event: F)
where F: Fn(&str, bool) + Send + Sync + 'static,

Listens for keyboard events.

Examples found in repository?
examples/input.rs (lines 21-23)
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§

Source§

impl Clone for Input

Source§

fn clone(&self) -> Input

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Input

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more