pub struct InputState {
pub keys_down: HashSet<Key>,
pub keys_pressed: HashSet<Key>,
pub keys_released: HashSet<Key>,
pub mouse_down: HashSet<MouseButton>,
pub mouse_pressed: HashSet<MouseButton>,
pub mouse_released: HashSet<MouseButton>,
pub cursor_pos: Option<(f32, f32)>,
pub wheel_delta: (f32, f32),
/* private fields */
}Expand description
Snapshot of user input.
This is intentionally minimal for now, but it already supports:
- current key/button state (
down) - per-frame transitions (
pressed/released) - cursor position and wheel delta
- mouse movement delta
Fields§
§keys_down: HashSet<Key>§keys_pressed: HashSet<Key>§keys_released: HashSet<Key>§mouse_down: HashSet<MouseButton>§mouse_pressed: HashSet<MouseButton>§mouse_released: HashSet<MouseButton>§cursor_pos: Option<(f32, f32)>Cursor position in physical pixels (as reported by winit).
wheel_delta: (f32, f32)Accumulated wheel delta since last begin_frame.
Implementations§
Source§impl InputState
impl InputState
Sourcepub fn start_frame(&mut self)
pub fn start_frame(&mut self)
Called at the start of a render/update frame.
Important: this does not clear edge-triggered sets (pressed/released).
Those are cleared at end_frame so events delivered before RedrawRequested
are still visible to systems during Universe::update.
pub fn key_down(&self, key: &Key) -> bool
pub fn key_pressed(&self, key: &Key) -> bool
pub fn key_released(&self, key: &Key) -> bool
Sourcepub fn mouse_movement(&self) -> (f32, f32)
pub fn mouse_movement(&self) -> (f32, f32)
Returns the mouse movement delta (dx, dy) since the last frame. Returns (0, 0) if cursor position is not available.
Sourcepub fn mouse_dragging(&self) -> bool
pub fn mouse_dragging(&self) -> bool
Whether the user is currently dragging the mouse (button held + cursor moved this frame).
Sourcepub fn mouse_drag_delta(&self) -> (f32, f32)
pub fn mouse_drag_delta(&self) -> (f32, f32)
Mouse drag delta (dx, dy) in pixels for this frame.
Whether the given mouse button is currently dragging (that button is held + cursor moved this frame).
Mouse drag delta (dx, dy) in pixels for this frame, gated to the given button.
pub fn text_input_events(&self) -> &[TextInputFrameEvent]
Trait Implementations§
Source§impl Clone for InputState
impl Clone for InputState
Source§fn clone(&self) -> InputState
fn clone(&self) -> InputState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for InputState
impl Debug for InputState
Source§impl Default for InputState
impl Default for InputState
Source§fn default() -> InputState
fn default() -> InputState
Auto Trait Implementations§
impl Freeze for InputState
impl RefUnwindSafe for InputState
impl Send for InputState
impl Sync for InputState
impl Unpin for InputState
impl UnsafeUnpin for InputState
impl UnwindSafe for InputState
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.