input_actions/action/
action.rs

1use crate::{action, source};
2
3pub type Id = &'static str;
4
5/// As in Rewired, an Action is a application/consumer facing event which a
6/// [`User`](crate::UserId) can trigger via a [`Device`](crate::device::Kind).
7///
8/// To configure an action:
9/// - Call [`System::add_action`](crate::System::add_action)
10/// - Add the [`Action Id`](Id) used in `add_action` to add the action to an [`action set`](crate::binding::ActionSet).
11/// - Add the action set via [`System::add_action_set`](crate::System::add_action_set).
12/// - Enable the action set for a given user via [`System::mark_action_set_enabled`](crate::System::mark_action_set_enabled).
13///
14/// Once configured, [`System::get_user_action`](crate::System::get_user_action) can be called to get the [`action state`](action::State).
15#[derive(Clone)]
16pub struct Action {
17	kind: source::Kind,
18	behavior: action::Behavior,
19}
20
21impl Action {
22	pub fn new(kind: source::Kind) -> Self {
23		Self {
24			kind,
25			behavior: action::Behavior::default(),
26		}
27	}
28
29	pub fn with_behavior(mut self, behavior: action::Behavior) -> Self {
30		self.behavior = behavior;
31		self
32	}
33
34	pub(crate) fn kind(&self) -> source::Kind {
35		self.kind
36	}
37
38	pub(crate) fn behavior(&self) -> &action::Behavior {
39		&self.behavior
40	}
41}