pub struct Input { /* private fields */ }Implementations§
Source§impl Input
impl Input
pub fn new() -> Self
Sourcepub fn gamepads(&self) -> impl Iterator<Item = &Gamepad>
pub fn gamepads(&self) -> impl Iterator<Item = &Gamepad>
Iterator over currently connected gamepads.
Sourcepub fn first_gamepad(&self) -> Option<&Gamepad>
pub fn first_gamepad(&self) -> Option<&Gamepad>
The first connected gamepad, if any. Convenient for single-player input.
Sourcepub fn poll_gamepads(&mut self)
pub fn poll_gamepads(&mut self)
Drain pending gamepad events into per-pad state, tracking hot-plug. Call once per
frame before update.
Sourcepub fn set_rumble(&mut self, id: GamepadId, magnitude: f32, duration_ms: u32)
pub fn set_rumble(&mut self, id: GamepadId, magnitude: f32, duration_ms: u32)
Rumble id at magnitude (0..=1) for duration_ms. No-op when the pad has no
force feedback or no backend is available.
pub fn key_held(&self, k: Key) -> bool
pub fn key_pressed(&self, k: Key) -> bool
pub fn key_released(&self, k: Key) -> bool
Sourcepub fn any_key_pressed(&self) -> bool
pub fn any_key_pressed(&self) -> bool
Any key other than a modifier (Shift, Ctrl, Alt, Super, …) went down this frame: the
classic “press any key”. Modifiers alone don’t count, so Alt-Tabbing away or holding
Shift doesn’t skip a screen; Input::keys_pressed still reports them.
Sourcepub fn keys_pressed(&self) -> impl Iterator<Item = Key> + '_
pub fn keys_pressed(&self) -> impl Iterator<Item = Key> + '_
Every key that went down this frame, modifiers included, in no particular order (for “press a key to bind it”, cheat codes, typing a name).
Sourcepub fn any_mouse_pressed(&self) -> bool
pub fn any_mouse_pressed(&self) -> bool
Any mouse button went down this frame.
Sourcepub fn any_pressed(&self) -> bool
pub fn any_pressed(&self) -> bool
Anything at all went down this frame: a non-modifier key (Input::any_key_pressed),
a mouse button, a button on any connected gamepad, or a finger touching the screen
(Input::any_touch_pressed). For “press any key to continue”, skipping intros, and
waking an idle game.
use game_toolkit_input::Input;
enum Screen { Title, Playing }
fn update(input: &Input, screen: &mut Screen) {
if matches!(screen, Screen::Title) && input.any_pressed() {
*screen = Screen::Playing;
}
}
let mut screen = Screen::Title;
update(&Input::default(), &mut screen); // nothing pressed yet
assert!(matches!(screen, Screen::Title));Sourcepub fn touches(&self) -> impl Iterator<Item = &Touch>
pub fn touches(&self) -> impl Iterator<Item = &Touch>
Fingers currently on the screen, in no particular order.
Sourcepub fn touch(&self, id: u64) -> Option<&Touch>
pub fn touch(&self, id: u64) -> Option<&Touch>
The finger with this Touch::id, if it is still down.
Sourcepub fn touches_started(&self) -> &[Touch]
pub fn touches_started(&self) -> &[Touch]
Fingers that went down this frame, in event order. A tap that starts and ends within
one frame shows up here and in Input::touches_ended, but not in Input::touches.
Sourcepub fn touches_ended(&self) -> &[Touch]
pub fn touches_ended(&self) -> &[Touch]
Fingers that lifted this frame, in event order. Touches the platform cancels (e.g. the
browser took over the gesture, or the window lost focus) vanish from
Input::touches without appearing here, so a cancelled touch never counts as a tap.
Sourcepub fn any_touch_pressed(&self) -> bool
pub fn any_touch_pressed(&self) -> bool
Any finger went down this frame.
Sourcepub fn set_touch_emulates_mouse(&mut self, on: bool)
pub fn set_touch_emulates_mouse(&mut self, on: bool)
Let the first finger on a touchscreen act as the mouse, so a game written for the
mouse also works on a phone. Off by default (also settable through
AppConfig::touch_emulates_mouse).
While on, the first finger down moves Input::mouse_pos to where it touched (without
a Input::mouse_delta jump), presses and holds MouseButton::Left, drags the
cursor along, and releases the button where it lifts. Other fingers are ignored until
it lifts. A cancelled touch lets go of the button without a Input::mouse_released
edge, so it never counts as a click. Input::touches and friends keep working.
No effect on Windows: the OS already turns touches into mouse events there, which winit passes on, so emulating them again would press twice.
Sourcepub fn touch_emulates_mouse(&self) -> bool
pub fn touch_emulates_mouse(&self) -> bool
Whether Input::set_touch_emulates_mouse is on.
pub fn mouse_held(&self, b: MouseButton) -> bool
pub fn mouse_pressed(&self, b: MouseButton) -> bool
pub fn mouse_released(&self, b: MouseButton) -> bool
Sourcepub fn mouse_pos(&self) -> (f32, f32)
pub fn mouse_pos(&self) -> (f32, f32)
Cursor position: physical window pixels, or canvas pixels when a virtual resolution
is set (outside 0..size while the cursor is over the border). See
Input::mouse_pos_window for the raw window position.
Sourcepub fn mouse_pos_window(&self) -> (f32, f32)
pub fn mouse_pos_window(&self) -> (f32, f32)
Cursor position in physical window pixels, ignoring any virtual resolution; for overlays drawn onto the window itself.
Sourcepub fn mouse_delta(&self) -> (f32, f32)
pub fn mouse_delta(&self) -> (f32, f32)
How far the cursor moved this frame, in the same space as Input::mouse_pos.
Sourcepub fn set_pointer_mapping(&mut self, mapping: Option<PointerMapping>)
pub fn set_pointer_mapping(&mut self, mapping: Option<PointerMapping>)
Report the mouse and touches in another space than window pixels: with Some,
Input::mouse_pos, Input::mouse_delta and new Touch positions are mapped
through it. The toolkit calls this every frame with the virtual-resolution canvas’s
placement, so games don’t need to; None (the default) reports window pixels.
Sourcepub fn pointer_mapping(&self) -> Option<PointerMapping>
pub fn pointer_mapping(&self) -> Option<PointerMapping>
The mapping set by Input::set_pointer_mapping.
pub fn scroll(&self) -> (f32, f32)
pub fn handle_window_event(&mut self, event: &WindowEvent)
Trait Implementations§
Auto Trait Implementations§
impl !Sync for Input
impl Forget for Input
impl Freeze for Input
impl RefUnwindSafe for Input
impl Send for Input
impl Unpin for Input
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.