Skip to main content

Viewport

Struct Viewport 

Source
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: f64

Horizontal translation, in screen pixels.

§y: f64

Vertical translation, in screen pixels.

§zoom: f64

Zoom factor.

Implementations§

Source§

impl Viewport

Source

pub const fn new(x: f64, y: f64, zoom: f64) -> Self

Source

pub const fn offset(&self) -> Point

The translation as a point.

Source

pub const fn with_offset(self, offset: Point) -> Self

The same viewport translated to offset.

Source

pub fn screen_to_flow(&self, p: Point) -> Point

Convert a point relative to the container (screen pixels) to flow space.

Source

pub fn flow_to_screen(&self, p: Point) -> Point

Convert a flow-space point to screen pixels relative to the container.

Source

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.

Source

pub fn panned(self, by: Point) -> Self

Pans by a screen-space delta.

Source

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.

Source

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.

Source

pub fn lerp(&self, other: &Viewport, t: f64) -> Viewport

Trait Implementations§

Source§

impl Clone for Viewport

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Viewport

Source§

impl Debug for Viewport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Viewport

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Viewport

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Viewport

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DependencyElement for T
where T: 'static + PartialEq + Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more