Skip to main content

ViewportContext

Struct ViewportContext 

Source
pub struct ViewportContext {
    pub ownership: InputOwnership,
    pub viewport_size: [f32; 2],
}
Expand description

Per-frame viewport context passed to OrbitCameraController::begin_frame (and ViewportInput::begin_frame): who owns the input, and the viewport size.

Fields§

§ownership: InputOwnership

Who owns the pointer and the keyboard this frame.

§viewport_size: [f32; 2]

Viewport size in logical pixels [width, height].

Implementations§

Source§

impl ViewportContext

Source

pub const fn new( ownership: InputOwnership, viewport_size: [f32; 2], ) -> ViewportContext

A context from the application’s routing decision and the viewport size.

Examples found in repository?
examples/custom_controller.rs (lines 41-44)
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 with_ownership( ownership: PointerOwnership, viewport_size: [f32; 2], ) -> ViewportContext

👎Deprecated:

use ViewportContext::new(InputOwnership::pointer_only(ownership), size), or set the keyboard axis from your text focus

A context from pointer ownership alone, the keyboard following the pointer.

Trait Implementations§

Source§

impl Clone for ViewportContext

Source§

fn clone(&self) -> ViewportContext

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 ViewportContext

Source§

impl Debug for ViewportContext

Source§

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

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

impl Default for ViewportContext

Source§

fn default() -> ViewportContext

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

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.