Skip to main content

AxisBinding

Struct AxisBinding 

Source
pub struct AxisBinding { /* private fields */ }
Expand description

One control that reads back a number, and the knobs it reads through.

A pad lane, a trigger, a joystick axis and a button composite read in -1..=1. A PointerDelta lane and a WheelDelta lane read how far they moved through scale, which nothing clamps.

Implementations§

Source§

impl AxisBinding

Source

pub const DEFAULT_DEADZONE: f32 = 0.15

Distance a pad or joystick control moves before it reads at all.

Source

pub fn pad(axis: PadAxis) -> Self

One lane of the standard gamepad layout.

Examples found in repository?
examples/breakout-game.rs (line 243)
228    fn bindings(&self) -> Vec<AxisBinding> {
229        match self {
230            Move::Paddle => vec![
231                AxisBinding::from(ButtonAxis {
232                    negative: Key::A,
233                    positive: Key::D,
234                }),
235                AxisBinding::from(ButtonAxis {
236                    negative: Key::Left,
237                    positive: Key::Right,
238                }),
239                AxisBinding::from(ButtonAxis {
240                    negative: Pad::DPadLeft,
241                    positive: Pad::DPadRight,
242                }),
243                AxisBinding::pad(PadAxis::LeftX),
244            ],
245        }
246    }
More examples
Hide additional examples
examples/input-lab.rs (line 93)
90    fn bindings(&self) -> Vec<AxisBinding> {
91        match self {
92            Self::LeftX => vec![
93                AxisBinding::pad(PadAxis::LeftX),
94                ButtonAxis {
95                    negative: Key::A,
96                    positive: Key::D,
97                }
98                .into(),
99            ],
100            Self::LeftY => vec![
101                AxisBinding::pad(PadAxis::LeftY),
102                ButtonAxis {
103                    negative: Key::S,
104                    positive: Key::W,
105                }
106                .into(),
107            ],
108            Self::RightX => vec![
109                AxisBinding::pad(PadAxis::RightX),
110                ButtonAxis {
111                    negative: Key::J,
112                    positive: Key::L,
113                }
114                .into(),
115            ],
116            Self::RightY => vec![
117                AxisBinding::pad(PadAxis::RightY),
118                ButtonAxis {
119                    negative: Key::K,
120                    positive: Key::I,
121                }
122                .into(),
123            ],
124            Self::LeftTrigger => vec![
125                AxisBinding::pad(PadAxis::LeftTrigger),
126                ButtonAxis {
127                    negative: Key::Minus,
128                    positive: Key::BracketLeft,
129                }
130                .into(),
131            ],
132            Self::RightTrigger => vec![
133                AxisBinding::pad(PadAxis::RightTrigger),
134                ButtonAxis {
135                    negative: Key::Equal,
136                    positive: Key::BracketRight,
137                }
138                .into(),
139            ],
140            Self::PointerSideways => vec![AxisBinding::pointer_delta(PointerDelta::Sideways)],
141            Self::PointerUp => vec![AxisBinding::pointer_delta(PointerDelta::Up)],
142            Self::WheelUp => vec![AxisBinding::wheel(WheelDelta::Up)],
143            Self::WheelSideways => vec![AxisBinding::wheel(WheelDelta::Sideways)],
144        }
145    }
Source

pub fn joystick(control: JoystickControl) -> Self

One axis of a device with no standard layout, by the number its platform reports for it; capture one rather than writing one.

Source

pub fn pointer_delta(lane: PointerDelta) -> Self

Pixels one lane of the pointer moved this frame, read through scale alone: nothing clamps what it reads.

Examples found in repository?
examples/animation.rs (line 582)
579    fn bindings(&self) -> Vec<AxisBinding> {
580        match self {
581            Axis::CameraYaw => {
582                vec![AxisBinding::pointer_delta(PointerDelta::Sideways).scale(CAMERA_YAW_SCALE)]
583            }
584            Axis::CameraPitch => {
585                vec![AxisBinding::pointer_delta(PointerDelta::Up).scale(CAMERA_PITCH_SCALE)]
586            }
587        }
588    }
More examples
Hide additional examples
examples/input-lab.rs (line 140)
90    fn bindings(&self) -> Vec<AxisBinding> {
91        match self {
92            Self::LeftX => vec![
93                AxisBinding::pad(PadAxis::LeftX),
94                ButtonAxis {
95                    negative: Key::A,
96                    positive: Key::D,
97                }
98                .into(),
99            ],
100            Self::LeftY => vec![
101                AxisBinding::pad(PadAxis::LeftY),
102                ButtonAxis {
103                    negative: Key::S,
104                    positive: Key::W,
105                }
106                .into(),
107            ],
108            Self::RightX => vec![
109                AxisBinding::pad(PadAxis::RightX),
110                ButtonAxis {
111                    negative: Key::J,
112                    positive: Key::L,
113                }
114                .into(),
115            ],
116            Self::RightY => vec![
117                AxisBinding::pad(PadAxis::RightY),
118                ButtonAxis {
119                    negative: Key::K,
120                    positive: Key::I,
121                }
122                .into(),
123            ],
124            Self::LeftTrigger => vec![
125                AxisBinding::pad(PadAxis::LeftTrigger),
126                ButtonAxis {
127                    negative: Key::Minus,
128                    positive: Key::BracketLeft,
129                }
130                .into(),
131            ],
132            Self::RightTrigger => vec![
133                AxisBinding::pad(PadAxis::RightTrigger),
134                ButtonAxis {
135                    negative: Key::Equal,
136                    positive: Key::BracketRight,
137                }
138                .into(),
139            ],
140            Self::PointerSideways => vec![AxisBinding::pointer_delta(PointerDelta::Sideways)],
141            Self::PointerUp => vec![AxisBinding::pointer_delta(PointerDelta::Up)],
142            Self::WheelUp => vec![AxisBinding::wheel(WheelDelta::Up)],
143            Self::WheelSideways => vec![AxisBinding::wheel(WheelDelta::Sideways)],
144        }
145    }
Source

pub fn wheel(lane: WheelDelta) -> Self

Notches lane of the wheel turned this frame, read through scale alone: nothing clamps what it reads.

Examples found in repository?
examples/input-lab.rs (line 142)
90    fn bindings(&self) -> Vec<AxisBinding> {
91        match self {
92            Self::LeftX => vec![
93                AxisBinding::pad(PadAxis::LeftX),
94                ButtonAxis {
95                    negative: Key::A,
96                    positive: Key::D,
97                }
98                .into(),
99            ],
100            Self::LeftY => vec![
101                AxisBinding::pad(PadAxis::LeftY),
102                ButtonAxis {
103                    negative: Key::S,
104                    positive: Key::W,
105                }
106                .into(),
107            ],
108            Self::RightX => vec![
109                AxisBinding::pad(PadAxis::RightX),
110                ButtonAxis {
111                    negative: Key::J,
112                    positive: Key::L,
113                }
114                .into(),
115            ],
116            Self::RightY => vec![
117                AxisBinding::pad(PadAxis::RightY),
118                ButtonAxis {
119                    negative: Key::K,
120                    positive: Key::I,
121                }
122                .into(),
123            ],
124            Self::LeftTrigger => vec![
125                AxisBinding::pad(PadAxis::LeftTrigger),
126                ButtonAxis {
127                    negative: Key::Minus,
128                    positive: Key::BracketLeft,
129                }
130                .into(),
131            ],
132            Self::RightTrigger => vec![
133                AxisBinding::pad(PadAxis::RightTrigger),
134                ButtonAxis {
135                    negative: Key::Equal,
136                    positive: Key::BracketRight,
137                }
138                .into(),
139            ],
140            Self::PointerSideways => vec![AxisBinding::pointer_delta(PointerDelta::Sideways)],
141            Self::PointerUp => vec![AxisBinding::pointer_delta(PointerDelta::Up)],
142            Self::WheelUp => vec![AxisBinding::wheel(WheelDelta::Up)],
143            Self::WheelSideways => vec![AxisBinding::wheel(WheelDelta::Sideways)],
144        }
145    }
Source§

impl AxisBinding

Source

pub fn deadzone(self, deadzone: f32) -> Self

Reads nothing until the control has moved deadzone of its way, then stretches what is left over the whole range; AxisBinding::DEFAULT_DEADZONE for a pad or joystick control, and nothing for the rest.

Clamped into 0.0..=0.95, a fraction of that way, so a control always keeps a range to read in.

Source

pub fn scale(self, scale: f32) -> Self

Multiplies what the control reads, as a fraction of it; 1.0 until set.

A control with a range of its own keeps to it whatever this is set to. A pointer lane or a wheel lane has none, so it reads its own distance times this: pixels for a pointer lane, notches for a wheel lane.

Examples found in repository?
examples/material-playground.rs (line 705)
703    fn bindings(&self) -> Vec<AxisBinding> {
704        match self {
705            Self::Wheel => vec![AxisBinding::from(WheelDelta::Up).scale(4.0)],
706        }
707    }
More examples
Hide additional examples
examples/ui-fonts.rs (line 511)
509    fn bindings(&self) -> Vec<AxisBinding> {
510        match self {
511            Self::Wheel => vec![AxisBinding::from(WheelDelta::Up).scale(4.0)],
512        }
513    }
examples/animation.rs (line 582)
579    fn bindings(&self) -> Vec<AxisBinding> {
580        match self {
581            Axis::CameraYaw => {
582                vec![AxisBinding::pointer_delta(PointerDelta::Sideways).scale(CAMERA_YAW_SCALE)]
583            }
584            Axis::CameraPitch => {
585                vec![AxisBinding::pointer_delta(PointerDelta::Up).scale(CAMERA_PITCH_SCALE)]
586            }
587        }
588    }
Source

pub fn invert(self) -> Self

Flips which way the control counts, for a control that reads the other way round.

Trait Implementations§

Source§

impl Clone for AxisBinding

Source§

fn clone(&self) -> AxisBinding

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 Copy for AxisBinding

Source§

impl Debug for AxisBinding

Source§

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

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

impl Display for AxisBinding

Source§

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

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

impl<N: Into<ButtonBinding>, P: Into<ButtonBinding>> From<ButtonAxis<N, P>> for AxisBinding

Source§

fn from(pair: ButtonAxis<N, P>) -> Self

A pair, negative counting down and positive counting up; a diagonal never reads longer than a straight direction.

Source§

impl From<PadAxis> for AxisBinding

Source§

fn from(axis: PadAxis) -> Self

Converts to this type from the input type.
Source§

impl From<PointerDelta> for AxisBinding

Source§

fn from(lane: PointerDelta) -> Self

Converts to this type from the input type.
Source§

impl From<WheelDelta> for AxisBinding

Source§

fn from(lane: WheelDelta) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for AxisBinding

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AxisBinding

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<S> Holds<<S as InputActions>::Axis, AxisBinding> for S
where S: InputActions,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

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