Skip to main content

Binding

Enum Binding 

Source
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

Source

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.

Source

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.

Source

pub fn is_gesture(&self) -> bool

Whether this binding drives raw-XY swipe capture (the Gesture arm).

Source

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.

Source

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 Clone for Binding

Source§

fn clone(&self) -> Binding

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Binding

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Binding

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Binding

Source§

impl From<Action> for Binding

Source§

fn from(action: Action) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Binding

Source§

fn eq(&self, other: &Binding) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Binding

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Binding

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more