pub struct View {
pub center: [f64; 2],
pub scale: f64,
pub width: f64,
pub height: f64,
pub dpr: f64,
}Expand description
Camera state. Not part of the document; hosts may persist it as view state.
Fields§
§center: [f64; 2]World point at the center of the target.
scale: f64CSS pixels per model unit.
width: f64Target width in CSS pixels.
height: f64Target height in CSS pixels.
dpr: f64Device pixels per CSS pixel.
Implementations§
Source§impl View
impl View
Sourcepub fn validate(&self) -> Result<(), RenderError>
pub fn validate(&self) -> Result<(), RenderError>
Validate finite, positive values.
§Errors
RenderError::InvalidView for NaN/∞, non-positive sizes or out-of-range zoom.
Sourcepub fn device_size(&self) -> (u32, u32)
pub fn device_size(&self) -> (u32, u32)
Target size in device pixels (rounded, at least 1×1).
Sourcepub fn device_scale(&self) -> f64
pub fn device_scale(&self) -> f64
Device pixels per model unit.
Sourcepub fn world_to_device(&self, p: Point) -> [f64; 2]
pub fn world_to_device(&self, p: Point) -> [f64; 2]
World → device pixels.
Sourcepub fn world_to_css(&self, p: Point) -> [f64; 2]
pub fn world_to_css(&self, p: Point) -> [f64; 2]
World → CSS pixels.
Sourcepub fn css_to_world(&self, x: f64, y: f64) -> Point
pub fn css_to_world(&self, x: f64, y: f64) -> Point
CSS pixels (relative to the target’s top-left corner) → world.
Sourcepub fn zoomed_at(&self, x: f64, y: f64, factor: f64) -> Self
pub fn zoomed_at(&self, x: f64, y: f64, factor: f64) -> Self
Zoom by factor keeping the world point under CSS position (x, y) fixed.
Trait Implementations§
impl Copy for View
Source§impl<'de> Deserialize<'de> for View
impl<'de> Deserialize<'de> for View
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for View
Auto Trait Implementations§
impl Freeze for View
impl RefUnwindSafe for View
impl Send for View
impl Sync for View
impl Unpin for View
impl UnsafeUnpin for View
impl UnwindSafe for View
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