Skip to main content

Vantage

Struct Vantage 

pub struct Vantage {
    pub zoom: Zoom,
    pub translation: Vec2,
}
Expand description

The whole of what a view-kind undo entry restores.

The two numbers the view holds, not a world rect — a rect would have to be re-framed against a viewport that may have resized since, which would land the camera somewhere the user never was.

The transform is here rather than in a backend because two backends read it: the on-screen painter converts every draw through it, and a recording canvas has to place its marks where the painter would have.

Fields§

§zoom: Zoom§translation: Vec2

Implementations§

§

impl Vantage

pub const fn resting() -> Vantage

The camera at rest: unity zoom, no pan.

pub fn world_to_screen(self, origin: Pos2, world: Pos2) -> Pos2

origin is the screen corner the viewport was laid out at.

pub fn screen_to_world(self, origin: Pos2, screen: Pos2) -> Pos2

pub fn remap_rect(self, origin: Pos2, world: Rect) -> Rect

pub fn remap_len(self, len: Bounded<WorldPxBounds>) -> f32

World-space length → screen-space length. The single place a world magnitude (radius, rounding, stroke width, wrap width) loses its unit.

pub fn remap_font(self, font: &Font) -> Font

The same face at the size it is drawn on screen.

pub fn visible(self, viewport: Rect) -> Rect

The world rect viewport shows from here.

pub fn framing( within: Rect, viewport_min: Pos2, content: Rect, max_zoom: Zoom, ) -> Vantage

The vantage that frames content centred in within, a screen region inside the viewport whose corner is viewport_min. within is not necessarily the whole viewport: floating chrome may leave less of it clear, and framing against the raw rect lands the model under the chrome. Padding is the caller’s — it pads content before framing it.

pub fn zoomed_about(self, origin: Pos2, anchor: Pos2, factor: Factor) -> Vantage

The same camera zoomed by factor about anchor (screen space, in a viewport cornered at origin), leaving the world under anchor where it was. Lands inside [Zoom::WORKED_MIN]..=[Zoom::WORKED_MAX] — a user working the camera stays in the band, where a framing may use the whole range.

Trait Implementations§

§

impl Clone for Vantage

§

fn clone(&self) -> Vantage

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for Vantage

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for Vantage

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Vantage, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl PartialEq for Vantage

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for Vantage

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Copy for Vantage

§

impl StructuralPartialEq for Vantage

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + Serialize + for<'a> Deserialize<'a> + Send + Sync,