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: InputOwnershipWho owns the pointer and the keyboard this frame.
viewport_size: [f32; 2]Viewport size in logical pixels [width, height].
Implementations§
Source§impl ViewportContext
impl ViewportContext
Sourcepub const fn new(
ownership: InputOwnership,
viewport_size: [f32; 2],
) -> ViewportContext
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}Sourcepub 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
pub const fn with_ownership( ownership: PointerOwnership, viewport_size: [f32; 2], ) -> ViewportContext
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
impl Clone for ViewportContext
Source§fn clone(&self) -> ViewportContext
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ViewportContext
Source§impl Debug for ViewportContext
impl Debug for ViewportContext
Source§impl Default for ViewportContext
impl Default for ViewportContext
Source§fn default() -> ViewportContext
fn default() -> ViewportContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Forget for ViewportContext
impl Freeze for ViewportContext
impl Move for ViewportContext
impl RefUnwindSafe for ViewportContext
impl Send for ViewportContext
impl Sync for ViewportContext
impl Unpin for ViewportContext
impl UnsafeUnpin for ViewportContext
impl UnwindSafe for ViewportContext
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
Mutably borrows from an owned value. Read more