pub struct View2d {
pub center_x: f64,
pub center_y: f64,
pub view_size: f64,
}Expand description
2D view transform (pan & zoom).
view_size is the world-space height mapped to the canvas vertical extent.
Smaller values mean more zoom.
Fields§
§center_x: f64§center_y: f64§view_size: f64World-space height visible on canvas. Always positive.
Implementations§
Source§impl View2d
impl View2d
Sourcepub fn set(&mut self, center_x: f64, center_y: f64, view_size: f64)
pub fn set(&mut self, center_x: f64, center_y: f64, view_size: f64)
Set view parameters. view_size is clamped to positive.
Sourcepub fn pan(&mut self, dx: f64, dy: f64, canvas_height: f64)
pub fn pan(&mut self, dx: f64, dy: f64, canvas_height: f64)
Pan by pixel delta. Speed scales with view_size / canvas_height.
Sourcepub fn zoom_at(
&mut self,
delta: f64,
canvas_x: f64,
canvas_y: f64,
canvas_width: f64,
canvas_height: f64,
)
pub fn zoom_at( &mut self, delta: f64, canvas_x: f64, canvas_y: f64, canvas_width: f64, canvas_height: f64, )
Zoom centered on a canvas position. delta > 0 zooms in.
Sourcepub fn canvas_to_world(
&self,
cx: f64,
cy: f64,
canvas_width: f64,
canvas_height: f64,
) -> (f64, f64)
pub fn canvas_to_world( &self, cx: f64, cy: f64, canvas_width: f64, canvas_height: f64, ) -> (f64, f64)
Convert canvas coordinates to world coordinates.
Sourcepub fn world_to_canvas(
&self,
wx: f64,
wy: f64,
canvas_width: f64,
canvas_height: f64,
) -> (f64, f64)
pub fn world_to_canvas( &self, wx: f64, wy: f64, canvas_width: f64, canvas_height: f64, ) -> (f64, f64)
Convert world coordinates to canvas coordinates.
Sourcepub fn fit(
&mut self,
world_width: f64,
world_height: f64,
canvas_width: f64,
canvas_height: f64,
)
pub fn fit( &mut self, world_width: f64, world_height: f64, canvas_width: f64, canvas_height: f64, )
Fit the entire world region into the canvas.
Sourcepub fn zoom_factor(&self, reference_view_size: f64) -> f64
pub fn zoom_factor(&self, reference_view_size: f64) -> f64
Current zoom factor relative to a reference view_size.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for View2d
impl RefUnwindSafe for View2d
impl Send for View2d
impl Sync for View2d
impl Unpin for View2d
impl UnsafeUnpin for View2d
impl UnwindSafe for View2d
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