pub enum Binding {
Single(Action),
Gesture(BTreeMap<GestureDirection, Action>),
LongPress(LongPressBinding),
}Expand description
What a single rebindable ButtonId does: one
immediate Action, an independent short/long action pair, 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), Gesture serializes as a
table keyed by GestureDirection names (Up/Down/Left/Right/
Click), and LongPress as the structurally distinct
{ short = ..., long = ... } table.
The arms are disambiguated structurally: action variant names and gesture
direction names have zero overlap, while a long press requires both
lowercase short and long fields and rejects unknown fields. The
binding_untagged_* tests guard these routing invariants.
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.
LongPress(LongPressBinding)
Independent release-before-threshold and threshold actions.
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, the Gesture map’s
Click entry, or a
LongPress binding’s short action. 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 long-press binding keeps its short action as Click; its long action
is discarded because gesture and threshold modes are mutually exclusive.
A no-op when this is already a Gesture.
Sourcepub fn demote_to_single(&mut self, fallback: Action)
pub fn demote_to_single(&mut self, fallback: Action)
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
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.