input_actions/binding/
layout.rs

1use crate::binding::ActionMap;
2use std::collections::HashMap;
3
4/// An identifier representing the way device inputs are mapped
5/// to [`actions`](`crate::action::Action`) via [`action maps`](ActionMap).
6pub type LayoutId = Option<&'static str>;
7
8/// An identifier representing [`ActionSet`], a set of bindings to a given action for each supported [`LayoutId`].
9/// Can be toggled on/off per user via [`System::mark_action_set_enabled`](crate::System::mark_action_set_enabled).
10pub type ActionSetId = Option<&'static str>;
11
12/// Represented by [`ActionSetId`].
13/// This is a collection of [`bindings`](ActionMap) per [`layout`](LayoutId)
14/// which are bound to a specific [`action`](crate::action::Action).
15#[derive(Debug, Clone)]
16pub struct ActionSet(HashMap<LayoutId, ActionMap>);
17
18impl Default for ActionSet {
19	fn default() -> Self {
20		Self(HashMap::new())
21	}
22}
23
24impl ActionSet {
25	/// Associates a layout with a map of action to device bindings.
26	pub fn with(mut self, layout: LayoutId, map: ActionMap) -> Self {
27		self.0.insert(layout, map);
28		self
29	}
30
31	pub(crate) fn get(&self, layout: &LayoutId) -> Option<&ActionMap> {
32		self.0.get(layout)
33	}
34}