pub struct InteractiveView {
pub scale: f32,
pub tx: f32,
pub ty: f32,
}Expand description
The retained state of an InteractiveViewer: the scale factor and the
translation applied to the child. The screen point q receives the content
painted flat at p according to q = scale · p + (tx, ty). The identity
(scale = 1, zero translation) places the child as is in the viewport.
All the gesture mathematics lives here (pure, testable): the shell merely
calls pan and zoom_at,
then renders the matrix.
Fields§
§scale: f32The current scale factor (1.0 = natural size).
tx: f32The paint translation, in logical pixels.
ty: f32The paint translation along the y axis, in logical pixels; tx is the x axis.
Implementations§
Source§impl InteractiveView
impl InteractiveView
Sourcepub fn matrix(&self) -> Affine
pub fn matrix(&self) -> Affine
The matrix q = scale · p + t (scaling about the origin, then translation).
Sourcepub fn pan(self, dx: f32, dy: f32) -> Self
pub fn pan(self, dx: f32, dy: f32) -> Self
Pans the content by (dx, dy) screen pixels: the finger or cursor pushes
the content by the same delta.
Sourcepub fn clamped(self, viewport: Rect) -> Self
pub fn clamped(self, viewport: Rect) -> Self
Clamps the translation so that the content (at the current scale) always
covers the viewport: an edge of the content cannot be dragged inside
the viewport. When the content is smaller than the viewport (zoomed out
below 1), it is centred. At scale 1, panning is nil (the content fills
exactly).
Sourcepub fn zoom_at(self, factor: f32, cursor: Point, min: f32, max: f32) -> Self
pub fn zoom_at(self, factor: f32, cursor: Point, min: f32, max: f32) -> Self
Zooms by factor while keeping the screen point cursor fixed (a
cursor-anchored zoom), with the final scale clamped to [min, max]. The
point of the content under the cursor does not move — the behaviour expected
of a wheel or a pinch.