pub struct Viewport {
pub x: f64,
pub y: f64,
pub zoom: f64,
}Expand description
The pan/zoom state of the flow canvas.
x/y are the screen point (relative to the container) that the flow
origin is drawn at, so a flow-space point p appears on screen at
p * zoom + offset(). The same shape — and, with the serde feature, the
same serialization — as react-flow’s viewport.
Fields§
§x: f64Horizontal translation, in screen pixels.
y: f64Vertical translation, in screen pixels.
zoom: f64Zoom factor.
Implementations§
Source§impl Viewport
impl Viewport
pub const fn new(x: f64, y: f64, zoom: f64) -> Self
Sourcepub const fn with_offset(self, offset: Point) -> Self
pub const fn with_offset(self, offset: Point) -> Self
The same viewport translated to offset.
Sourcepub fn screen_to_flow(&self, p: Point) -> Point
pub fn screen_to_flow(&self, p: Point) -> Point
Convert a point relative to the container (screen pixels) to flow space.
Sourcepub fn flow_to_screen(&self, p: Point) -> Point
pub fn flow_to_screen(&self, p: Point) -> Point
Convert a flow-space point to screen pixels relative to the container.
Sourcepub fn zoom_about(
self,
zoom: f64,
screen: Point,
min_zoom: f64,
max_zoom: f64,
) -> Self
pub fn zoom_about( self, zoom: f64, screen: Point, min_zoom: f64, max_zoom: f64, ) -> Self
Zooms about a screen point, so whatever is under it stays under it.
A zoom that is not a number is refused rather than clamped — f64::clamp
keeps a NaN, and a NaN here would spread to every coordinate drawn from
this viewport, with nothing left on screen to say why.
Sourcepub fn is_sane(self, min_zoom: f64, max_zoom: f64) -> bool
pub fn is_sane(self, min_zoom: f64, max_zoom: f64) -> bool
Whether this could have come from an editor rather than from a corrupt or hand-edited file: every coordinate a number, and the zoom within the given limits.
Sourcepub fn fit(
drawing: Option<Rect>,
safe: Rect,
min_zoom: f64,
max_zoom: f64,
) -> Self
pub fn fit( drawing: Option<Rect>, safe: Rect, min_zoom: f64, max_zoom: f64, ) -> Self
Frames drawing inside safe — the part of the screen that is actually
clear, which is not the whole of it when panels float over the edges. An
empty drawing centres the origin instead, so a fresh canvas opens with
room on every side. The zoom is clamped to [min_zoom, max_zoom]; pass
a max_zoom below the interactive limit so fitting a single small node
never magnifies it to fill the screen.