Skip to main content

ZoomState

Struct ZoomState 

Source
pub struct ZoomState { /* private fields */ }
Expand description

Shared zoom/pan transform state for Modifier::zoomable.

Cloning shares the same underlying state (like ScrollState).

Implementations§

Source§

impl ZoomState

Source

pub fn new() -> Self

Creates a state at scale 1.0 with a 1.0..=8.0 zoom range.

Source

pub fn with_scale_range(min_scale: f32, max_scale: f32) -> Self

Creates a state at scale 1.0 clamping zoom to min_scale..=max_scale.

Source

pub fn id(&self) -> u64

Stable identity of this state (shared across clones).

Source

pub fn scale(&self) -> f32

Current scale (reactive — subscribes the caller to changes).

Source

pub fn scale_non_reactive(&self) -> f32

Current scale without snapshot subscription.

Source

pub fn offset(&self) -> Point

Current pan offset in dp (reactive).

Source

pub fn offset_non_reactive(&self) -> Point

Current pan offset without snapshot subscription.

Source

pub fn min_scale(&self) -> f32

Source

pub fn max_scale(&self) -> f32

Source

pub fn is_transformed(&self) -> bool

Whether the content is currently transformed away from identity.

Source

pub fn is_zoomed_in(&self) -> bool

Whether the content is currently zoomed in beyond identity.

Pan gestures only apply while this is true: an image at (or below) its natural size has nothing to pan, and drags over it belong to enclosing scrollables.

Source

pub fn set_scale(&self, scale: f32)

Sets the scale directly (clamped to the configured range).

Source

pub fn set_offset(&self, offset: Point)

Sets the pan offset directly.

Source

pub fn reset(&self)

Resets to identity (scale clamped into range, zero offset).

Source

pub fn apply_transform(&self, centroid: Point, pan: Point, zoom: f32)

Applies one gesture step: zoom by zoom about centroid, then pan.

centroid and pan are in the element’s display frame; for finger gestures the anchor must be the centroid of the pointers BEFORE the step (as reported by TransformGestureEvent::Transform). With the top-left-origin layer produced by ZoomState::layer, a content point c renders at p = c * scale + offset; this update applies p' = zoom * (p - centroid) + centroid + pan, which keeps the content glued to the fingers.

Pan is inert while not zoomed in: whenever the resulting scale is at (or below) identity the offset is clamped back to zero, so a pinch that zooms out to scale <= 1 — or a pure centroid pan at identity — never leaves the content stranded at a stray offset.

Source

pub fn layer(&self) -> GraphicsLayer

Builds the GraphicsLayer rendering this transform.

Reads the state reactively, so it is meant for the lazy Modifier::graphics_layer(move || state.layer()) form.

Trait Implementations§

Source§

impl Clone for ZoomState

Source§

fn clone(&self) -> ZoomState

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 Default for ZoomState

Source§

fn default() -> Self

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

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.

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