Skip to main content

InputOwnership

Struct InputOwnership 

Source
pub struct InputOwnership {
    pub pointer: PointerOwnership,
    pub keyboard: KeyboardOwnership,
}
Expand description

Who owns the pointer and who owns the keyboard, as the application’s routing decided this frame.

The per-framework helpers (adapters::egui::ownership, adapters::winit::ownership in viewport-lib-input) compute it from framework state; a host that hit-tests its own widgets builds it directly.

Fields§

§pointer: PointerOwnership

Who owns the pointer.

§keyboard: KeyboardOwnership

Who owns the keyboard.

Implementations§

Source§

impl InputOwnership

Source

pub const NONE: InputOwnership

Neither the pointer nor the keyboard is the viewport’s.

Source

pub const fn full_window() -> InputOwnership

A viewport that fills its window with nothing drawn over it: it owns both.

Examples found in repository?
examples/custom_controller.rs (line 42)
38fn main() {
39    // 1. RESOLVE: feed native-shaped events into ViewportInput for one frame.
40    let mut input = ViewportInput::from_preset(BindingPreset::Viewer);
41    input.begin_frame(ViewportContext::new(
42        InputOwnership::full_window(),
43        [800.0, 600.0],
44    ));
45
46    // In the primitives preset, plain left-drag (no modifiers) orbits. Drive it
47    // by hand: place the pointer, press the button there (that sets the drag
48    // origin), then move across the viewport to accumulate the drag delta.
49    input.push_event(ViewportEvent::PointerMoved {
50        position: [400.0, 300.0].into(),
51    });
52    input.push_event(ViewportEvent::MouseButton {
53        button: MouseButton::Left,
54        state: ButtonState::Pressed,
55    });
56    input.push_event(ViewportEvent::PointerMoved {
57        position: [460.0, 300.0].into(),
58    });
59
60    let frame: ActionFrame = input.resolve();
61
62    // 2. APPLY: hand the resolved frame to your controller.
63    let mut camera = Camera::default();
64    let before = camera.orientation();
65
66    let mut controller = HalfSpeedOrbit;
67    controller.apply(&mut camera, &frame, 1.0 / 60.0);
68
69    println!("resolved orbit delta : {:?}", frame.navigation.orbit);
70    println!("camera orientation before : {before:?}");
71    println!("camera orientation after  : {:?}", camera.orientation());
72    println!(
73        "moved: {}",
74        before.abs_diff_eq(camera.orientation(), 1e-6) == false
75    );
76}
Source

pub const fn pointer_only(pointer: PointerOwnership) -> InputOwnership

Pointer ownership pointer, with the keyboard following it: owned when the pointer is Owned or Grabbed. For a host with no text fields of its own; one that has them sets the keyboard axis from their focus.

Trait Implementations§

Source§

impl Clone for InputOwnership

Source§

fn clone(&self) -> InputOwnership

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 InputOwnership

Source§

impl Debug for InputOwnership

Source§

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

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

impl Default for InputOwnership

Source§

fn default() -> InputOwnership

Returns the “default value” for a type. Read more
Source§

impl Eq for InputOwnership

Source§

impl Hash for InputOwnership

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for InputOwnership

Source§

fn eq(&self, other: &InputOwnership) -> 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 InputOwnership

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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 = !

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.