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
impl ZoomState
Sourcepub fn with_scale_range(min_scale: f32, max_scale: f32) -> Self
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.
Sourcepub fn scale_non_reactive(&self) -> f32
pub fn scale_non_reactive(&self) -> f32
Current scale without snapshot subscription.
Sourcepub fn offset_non_reactive(&self) -> Point
pub fn offset_non_reactive(&self) -> Point
Current pan offset without snapshot subscription.
pub fn min_scale(&self) -> f32
pub fn max_scale(&self) -> f32
Sourcepub fn is_transformed(&self) -> bool
pub fn is_transformed(&self) -> bool
Whether the content is currently transformed away from identity.
Sourcepub fn is_zoomed_in(&self) -> bool
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.
Sourcepub fn set_offset(&self, offset: Point)
pub fn set_offset(&self, offset: Point)
Sets the pan offset directly.
Sourcepub fn apply_transform(&self, centroid: Point, pan: Point, zoom: f32)
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.
Sourcepub fn layer(&self) -> GraphicsLayer
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.