pub struct KeyBinding {
pub key: String,
pub action: String,
pub screen: Option<AssetId>,
}Expand description
Maps a keyboard key to an action string.
When the bound key is pressed, the action fires once per press (like a
HitRegion click). Bindings only run while the cursor is free:
they’re inactive in worlds that capture the cursor for camera control.
While a TextInput has keyboard focus, bindings are suspended
so typing cannot trigger actions; a Screen’s toggle_key stays
live.
The action vocabulary is the same as HitRegion’s:
"scene:<name>": jump to the named Scene"quit": stop the application"screen:show:<name>": show the named Screen, replacing the top of the stack"screen:push:<name>": open the named Screen on top of what is showing"screen:hide": close the top Screen"screen:toggle:<name>": toggle the named Screen
InputKey names are case-sensitive canonical names (e.g. "Escape", "Space",
"Enter").
KeyBinding {
key: "Escape".into(),
action: "screen:toggle:pause_menu".into(),
..Default::default()
};Fields§
§key: StringThe key name to bind (e.g. "Escape").
action: StringThe action to fire when the key is pressed.
screen: Option<AssetId>Screen this binding is scoped to: the binding only fires while that screen is on top of the stack. Unset, the binding is global.
Trait Implementations§
Source§impl Clone for KeyBinding
impl Clone for KeyBinding
Source§fn clone(&self) -> KeyBinding
fn clone(&self) -> KeyBinding
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Component for KeyBinding
impl Component for KeyBinding
Source§const NAME: &'static str = "KeyBinding"
const NAME: &'static str = "KeyBinding"
The registry name a world authors this component under.
Source§fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>
fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>
Reconstruct this component from a blob record, whose bytes are the
serialized runtime component (cook already ran the asset -> component
translation). The default rejects: runtime-only components are never
stored in a blob, so only loadable types provide an implementation.
Source§fn inject_locator(&mut self, _locator: PayloadLocator)
fn inject_locator(&mut self, _locator: PayloadLocator)
Called after construction to inject the payload locator from the blob def.
Only meaningful for components with a compiled payload.
The default implementation does nothing (correct for most components).
Source§fn inject_name(&mut self, _id: AssetId)
fn inject_name(&mut self, _id: AssetId)
Called after construction to inject the asset’s identity from the blob
def. Only meaningful for components that look themselves up by id at
runtime. The default implementation does nothing.
Source§impl ComponentSlot for KeyBinding
impl ComponentSlot for KeyBinding
Source§const DISCRIMINANT: u8
const DISCRIMINANT: u8
The component type’s stable id, used as its
ComponentId.Source§fn slot(s: &ComponentStorage) -> &Column<Self>
fn slot(s: &ComponentStorage) -> &Column<Self>
Borrow this type’s column out of the storage.
Source§fn slot_mut(s: &mut ComponentStorage) -> &mut Column<Self>
fn slot_mut(s: &mut ComponentStorage) -> &mut Column<Self>
Mutably borrow this type’s column out of the storage.
Source§impl Debug for KeyBinding
impl Debug for KeyBinding
Source§impl Default for KeyBinding
impl Default for KeyBinding
Source§fn default() -> KeyBinding
fn default() -> KeyBinding
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for KeyBindingwhere
KeyBinding: Default,
impl<'de> Deserialize<'de> for KeyBindingwhere
KeyBinding: Default,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<KeyBinding, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<KeyBinding, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<KeyBinding> for ComponentAsset
impl From<KeyBinding> for ComponentAsset
Source§fn from(c: KeyBinding) -> Self
fn from(c: KeyBinding) -> Self
Converts to this type from the input type.
impl RuntimeComponent for KeyBinding
Source§impl Serialize for KeyBinding
impl Serialize for KeyBinding
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for KeyBinding
impl RefUnwindSafe for KeyBinding
impl Send for KeyBinding
impl Sync for KeyBinding
impl Unpin for KeyBinding
impl UnsafeUnpin for KeyBinding
impl UnwindSafe for KeyBinding
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