pub struct Viewport {
pub origin: Vec2,
pub size: Vec2,
pub logical_size: Vec2,
pub scale: f32,
}Expand description
A fitted content rectangle measured in logical window coordinates.
Fields§
§origin: Vec2Top-left corner of the content, excluding letterbox bars.
size: Vec2Content dimensions in logical window coordinates.
logical_size: Vec2Content dimensions in game/UI units.
scale: f32Window logical pixels per UI unit.
Implementations§
Source§impl Viewport
impl Viewport
Sourcepub fn new(window: Vec2, reference: Vec2, mode: ScaleMode) -> Option<Self>
pub fn new(window: Vec2, reference: Vec2, mode: ScaleMode) -> Option<Self>
Computes a viewport. Returns None for minimized or invalid dimensions.
Sourcepub fn screen_to_ui(&self, screen: Vec2) -> Option<Vec2>
pub fn screen_to_ui(&self, screen: Vec2) -> Option<Vec2>
Converts a pointer to UI units, rejecting points inside the bars.
Sourcepub fn ui_to_screen(&self, ui: Vec2) -> Vec2
pub fn ui_to_screen(&self, ui: Vec2) -> Vec2
Converts UI units to logical window coordinates.
Sourcepub fn render_size(&self, dpi: Vec2) -> (u32, u32)
pub fn render_size(&self, dpi: Vec2) -> (u32, u32)
Target pixel dimensions at the given framebuffer scale, rounded and bounded.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Viewport
impl RefUnwindSafe for Viewport
impl Send for Viewport
impl Sync for Viewport
impl Unpin for Viewport
impl UnsafeUnpin for Viewport
impl UnwindSafe for Viewport
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