pub struct Camera {
pub center: [f32; 2],
pub zoom: f32,
pub viewport: [f32; 2],
pub fade: f32,
pub target_center: [f32; 2],
pub target_zoom: f32,
pub gliding: bool,
pub pixel_ratio: f32,
}Fields§
§center: [f32; 2]§zoom: f32§viewport: [f32; 2]§fade: f32§target_center: [f32; 2]§target_zoom: f32§gliding: bool§pixel_ratio: f32Physical pixels per CSS pixel — a host’s devicePixelRatio. Default 1.
viewport, project, unproject and pan_pixels all speak physical
pixels and need no adjustment: the host already hands us physical
coordinates, and geometry that is framed by fit_bounds rescales
itself when the viewport grows.
What this exists for is the handful of sizes the engine states in
pixels itself — label type size, the gap between a node and its
label, hit-test slop, LOD cutoffs. Those were chosen by eye at 1x, so
they mean CSS pixels; left unscaled they would each halve in apparent
size the moment a host rendered at 2x. Multiply any such constant by
this via css_px.
Implementations§
Source§impl Camera
impl Camera
pub fn new(width: f32, height: f32) -> Self
Sourcepub fn css_px(&self, len: f32) -> f32
pub fn css_px(&self, len: f32) -> f32
Convert a CSS-pixel length to physical pixels. See pixel_ratio.
Sourcepub fn set_pixel_ratio(&mut self, ratio: f32)
pub fn set_pixel_ratio(&mut self, ratio: f32)
Set the device pixel ratio, ignoring non-positive or non-finite input (a zero would collapse every pixel constant to nothing).
pub fn uniform(&self) -> CameraUniform
pub fn pan_pixels(&mut self, dx: f32, dy: f32)
pub fn zoom_by(&mut self, factor: f32)
Sourcepub fn fit_bounds(&mut self, min: [f32; 2], max: [f32; 2])
pub fn fit_bounds(&mut self, min: [f32; 2], max: [f32; 2])
Center and zoom so the world-space AABB [min, max] fits the viewport with margin.
Sourcepub fn fit_bounds_at_least(
&mut self,
min: [f32; 2],
max: [f32; 2],
min_extent: f32,
)
pub fn fit_bounds_at_least( &mut self, min: [f32; 2], max: [f32; 2], min_extent: f32, )
fit_bounds, but never framing tighter than
min_extent on either axis. See grow_to_min_extent.
Sourcepub fn snap_to(&mut self, center: [f32; 2], zoom: f32)
pub fn snap_to(&mut self, center: [f32; 2], zoom: f32)
Jump immediately to center/zoom (no glide); clears any glide.
Sourcepub fn tick(&mut self, dt_ms: f32, dur_ms: f32)
pub fn tick(&mut self, dt_ms: f32, dur_ms: f32)
Advance an in-flight glide by dt_ms, using dur_ms to set the pace.
Built-in smooth (exponential) ease — no graph-explorer-style dependency.
No-op when not gliding; snaps when dur_ms <= 0.
Sourcepub fn view_for_bounds(&self, min: [f32; 2], max: [f32; 2]) -> ([f32; 2], f32)
pub fn view_for_bounds(&self, min: [f32; 2], max: [f32; 2]) -> ([f32; 2], f32)
Compute the (center, zoom) that frames world-AABB [min,max] with margin.
Sourcepub fn glide_bounds(&mut self, min: [f32; 2], max: [f32; 2])
pub fn glide_bounds(&mut self, min: [f32; 2], max: [f32; 2])
Glide to frame world-AABB [min,max].
Auto Trait Implementations§
impl Freeze for Camera
impl RefUnwindSafe for Camera
impl Send for Camera
impl Sync for Camera
impl Unpin for Camera
impl UnsafeUnpin for Camera
impl UnwindSafe for Camera
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more