pub struct Events {Show 13 fields
pub keys: [ButtonState; 256],
pub mouse_buttons: [ButtonState; 8],
pub mouse_scroll_line: Option<(f32, f32)>,
pub mouse_scroll_pixel: Option<(f64, f64)>,
pub modifiers: ModifiersState,
pub gamepad_connected: [bool; 4],
pub gamepad_buttons: [[ButtonState; 20]; 4],
pub gamepad_axes: [[f32; 6]; 4],
pub resize_event: Option<Size2D>,
pub close_requested: bool,
pub focused: bool,
pub frame: u64,
pub network: NetworkEvents,
}Expand description
Per-frame input state snapshot.
Events holds all input state for a single frame. It is populated by calling
process_window_event and
process_gilrs_event as events arrive, then
frozen for the frame. At the end of the frame, end_frame
advances the frame counter and clears transient state.
§Keyboard
use optic_window::*;
if events.key(KeyCode::Space, Is::Pressed) {
// space was just pressed this frame
}
if events.key(KeyCode::ControlLeft, Is::Held) {
// ctrl is held down
}§Mouse
use optic_window::*;
if events.mouse(Mouse::Left, Is::Pressed) {
// left click this frame
}§Gamepad
use optic_window::*;
if events.gamepad_button(0, GamepadButton::A, Is::Pressed) {
// gamepad 0 pressed A this frame
}
let axis = events.gamepad_axis(0, GamepadAxis::LeftX);Fields§
§keys: [ButtonState; 256]§mouse_scroll_line: Option<(f32, f32)>§mouse_scroll_pixel: Option<(f64, f64)>§modifiers: ModifiersState§gamepad_connected: [bool; 4]§gamepad_axes: [[f32; 6]; 4]§resize_event: Option<Size2D>§close_requested: bool§focused: bool§frame: u64§network: NetworkEventsImplementations§
Source§impl Events
impl Events
Sourcepub const GAMEPAD_AXIS_DEADZONE: f32 = 0.15
pub const GAMEPAD_AXIS_DEADZONE: f32 = 0.15
Default deadzone for gamepad analog axes.
Sourcepub fn process_window_event(&mut self, event: &WindowEvent, _window: &Window)
pub fn process_window_event(&mut self, event: &WindowEvent, _window: &Window)
Process a single winit WindowEvent, updating internal state.
Called by the game loop for each event in the winit event queue.
Sourcepub fn process_gilrs_event(&mut self, event: &Event)
pub fn process_gilrs_event(&mut self, event: &Event)
Process a single gilrs gamepad event.
Sourcepub fn end_frame(&mut self)
pub fn end_frame(&mut self)
Advance the frame counter and clear per-frame transient state.
Must be called at the end of every frame. Resets scroll deltas,
resize events, and network events. The close_requested flag
persists across frames (the user must manually clear it).
Sourcepub fn key_combo(&self, primary: KeyCode, modifier: KeyCode, action: Is) -> bool
pub fn key_combo(&self, primary: KeyCode, modifier: KeyCode, action: Is) -> bool
Query a key combo: primary must match action while modifier is held.
use optic_window::*;
if events.key_combo(KeyCode::KeyC, KeyCode::ControlLeft, Is::Pressed) {
// Ctrl+C was pressed
}Sourcepub fn key_combo_n(&self, keys: &[(KeyCode, Is)]) -> bool
pub fn key_combo_n(&self, keys: &[(KeyCode, Is)]) -> bool
Query multiple keys simultaneously — all must match their respective actions.
Sourcepub fn gamepad_connected(&self, id: usize) -> bool
pub fn gamepad_connected(&self, id: usize) -> bool
True if a gamepad with the given id is currently connected.
Sourcepub fn gamepad_count(&self) -> usize
pub fn gamepad_count(&self) -> usize
Number of currently connected gamepads.
Query a gamepad button by GamepadButton and Is action.
True if any button on the given gamepad matches the action.
Sourcepub fn any_gamepad(&self, action: Is) -> bool
pub fn any_gamepad(&self, action: Is) -> bool
True if any button on any connected gamepad matches the action.
Sourcepub fn gamepad_axis_raw(&self, id: usize, axis: GamepadAxis) -> f32
pub fn gamepad_axis_raw(&self, id: usize, axis: GamepadAxis) -> f32
Raw gamepad axis value (no deadzone applied).
Sourcepub fn gamepad_axis(&self, id: usize, axis: GamepadAxis) -> f32
pub fn gamepad_axis(&self, id: usize, axis: GamepadAxis) -> f32
Gamepad axis value with the default deadzone ([GAMEPAD_AXIS_DEADZONE]).
Values below the deadzone are snapped to 0.0.
Sourcepub fn gamepad_axis_deadzoned(
&self,
id: usize,
axis: GamepadAxis,
deadzone: f32,
) -> f32
pub fn gamepad_axis_deadzoned( &self, id: usize, axis: GamepadAxis, deadzone: f32, ) -> f32
Gamepad axis value with a custom deadzone.
Auto Trait Implementations§
impl Freeze for Events
impl RefUnwindSafe for Events
impl Send for Events
impl Sync for Events
impl Unpin for Events
impl UnsafeUnpin for Events
impl UnwindSafe for Events
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.