pub enum Binding {
Single(Action),
Gesture(BTreeMap<GestureDirection, Action>),
}Expand description
What a single rebindable ButtonId does: either one Action, or — for a
raw-XY-capable button placed in gesture mode — a per-GestureDirection
map (hold + swipe up/down/left/right, or a plain click).
There has only ever been one binding map per device; a gesture binding is just a binding whose payload is a direction map instead of a single action.
§Serialization
#[serde(untagged)]: Single serializes exactly as the
bare Action did before (a string "BrowserBack", or a single-key table
for the payload variants), and Gesture serializes as a
table keyed by GestureDirection names (Up/Down/Left/Right/
Click).
The two arms are disambiguated by the zero overlap between Action
variant names and GestureDirection variant names — untagged tries
Single(Action) first, and a table keyed by Up etc. cannot parse as an
externally-tagged Action, so it falls through to Gesture. A payload
action like { SetDpiPreset = 2 } is a valid externally-tagged Action, so
it stays Single and never reaches the Gesture arm. This invariant is the
entire safety basis for untagged routing; the binding_untagged_* tests
guard it (a future Action named Up/Down/Left/Right/Click would
silently mis-route, and those tests would fail).
Variants§
Single(Action)
One action, fired on press. The shape every non-gesture button uses.
Gesture(BTreeMap<GestureDirection, Action>)
Per-direction sub-bindings for a button in gesture mode. Keyed by the
committed swipe direction, with GestureDirection::Click holding the
plain-click (no-swipe) action.
Implementations§
Source§impl Binding
impl Binding
Sourcepub fn click_action(&self) -> Action
pub fn click_action(&self) -> Action
The plain-click action for this binding: the Single
action, or the Gesture map’s
Click entry. Falls back to Action::None
when a gesture binding has no explicit Click.
Lets the click-dispatch path stay binding-shape-agnostic.
Sourcepub fn direction_action(&self, direction: GestureDirection) -> Option<&Action>
pub fn direction_action(&self, direction: GestureDirection) -> Option<&Action>
The action bound to direction, if this is a gesture binding.
Single has no directions and returns None.
Sourcepub fn is_gesture(&self) -> bool
pub fn is_gesture(&self) -> bool
Whether this binding drives raw-XY swipe capture (the
Gesture arm).
Sourcepub fn upgrade_to_gesture(&mut self)
pub fn upgrade_to_gesture(&mut self)
Promote a Single binding in place to a
Gesture, keeping its action as the
GestureDirection::Click entry and leaving the swipe arms unbound.
A no-op when this is already a Gesture.
Sourcepub fn fill_gesture_defaults(&mut self)
pub fn fill_gesture_defaults(&mut self)
Fill any unbound directions of a Gesture binding
with their canonical default_gesture_binding, so a button promoted to
the gesture role always exposes the full five-direction set — rather than
leaving swipe arms the GUI renders as defaults but the runtime never
dispatches. A no-op on Single and on directions
already bound (existing user choices are preserved).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Binding
impl<'de> Deserialize<'de> for Binding
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Binding
impl StructuralPartialEq for Binding
Auto Trait Implementations§
impl Freeze for Binding
impl RefUnwindSafe for Binding
impl Send for Binding
impl Sync for Binding
impl Unpin for Binding
impl UnsafeUnpin for Binding
impl UnwindSafe for Binding
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.