pub struct KeyBindings { /* private fields */ }Expand description
Central key binding registry.
Manages multiple binding groups and provides a unified query interface.
Game systems query actions (not raw keys) each frame via is_active().
Implementations§
Source§impl KeyBindings
impl KeyBindings
pub fn new() -> Self
Sourcepub fn add_group(&mut self, group: BindingGroup)
pub fn add_group(&mut self, group: BindingGroup)
Add a binding group.
Sourcepub fn set_group_enabled(&mut self, name: &str, enabled: bool)
pub fn set_group_enabled(&mut self, name: &str, enabled: bool)
Enable or disable a named group.
pub fn is_group_enabled(&self, name: &str) -> bool
Sourcepub fn bind(&mut self, action: impl Into<Action>, key: Key)
pub fn bind(&mut self, action: impl Into<Action>, key: Key)
Add a simple key binding to the default (first enabled) group.
Sourcepub fn update(
&mut self,
held: &HashSet<Key>,
just_pressed: &HashSet<Key>,
just_released: &HashSet<Key>,
mouse_delta: (f32, f32),
scroll: f32,
time: f32,
dt: f32,
)
pub fn update( &mut self, held: &HashSet<Key>, just_pressed: &HashSet<Key>, just_released: &HashSet<Key>, mouse_delta: (f32, f32), scroll: f32, time: f32, dt: f32, )
Update internal state from raw input this frame.
Must be called once per frame before any is_active queries.
Sourcepub fn is_active(
&self,
action: &str,
trigger: Trigger,
held: &HashSet<Key>,
just_pressed: &HashSet<Key>,
just_released: &HashSet<Key>,
) -> bool
pub fn is_active( &self, action: &str, trigger: Trigger, held: &HashSet<Key>, just_pressed: &HashSet<Key>, just_released: &HashSet<Key>, ) -> bool
Returns true if the named action is currently active with the given trigger type.
Sourcepub fn just_pressed(
&self,
action: &str,
held: &HashSet<Key>,
just_pressed: &HashSet<Key>,
just_released: &HashSet<Key>,
) -> bool
pub fn just_pressed( &self, action: &str, held: &HashSet<Key>, just_pressed: &HashSet<Key>, just_released: &HashSet<Key>, ) -> bool
Convenience: just pressed.
Sourcepub fn is_held(
&self,
action: &str,
held: &HashSet<Key>,
just_pressed: &HashSet<Key>,
just_released: &HashSet<Key>,
) -> bool
pub fn is_held( &self, action: &str, held: &HashSet<Key>, just_pressed: &HashSet<Key>, just_released: &HashSet<Key>, ) -> bool
Convenience: held.
Sourcepub fn all_actions(&self) -> Vec<&str>
pub fn all_actions(&self) -> Vec<&str>
List all known actions across all groups.
Sourcepub fn display_binding(&self, action: &str) -> Option<&str>
pub fn display_binding(&self, action: &str) -> Option<&str>
Get the display string for the primary binding of an action.
Sourcepub fn chord_just_fired(&self, action: &str) -> bool
pub fn chord_just_fired(&self, action: &str) -> bool
Check if a chord action fired this frame.
Trait Implementations§
Source§impl Default for KeyBindings
impl Default for KeyBindings
Source§fn default() -> KeyBindings
fn default() -> KeyBindings
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for KeyBindings
impl RefUnwindSafe for KeyBindings
impl Send for KeyBindings
impl Sync for KeyBindings
impl Unpin for KeyBindings
impl UnsafeUnpin for KeyBindings
impl UnwindSafe for KeyBindings
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
Mutably borrows from an owned value. Read more
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>
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>
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)
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)
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.