pub struct PanZoomView<State>where
State: 'static,{ /* private fields */ }Expand description
A pan/zoom viewport over one child — a node-and-edge graph, a map, a large
image — without hand-rolling the gesture math. pan_zoom lays its child
out at its natural size and places it under a scale-then-translate
transform (PanZoomTransform) the user drives: primary drag pans (unless
the child claims the press), a touch pinch or a desktop ctrl/⌘+wheel and
trackpad pinch zooms about the gesture’s focal point, clamped to
.min_scale/.max_scale. A plain wheel still reaches the child, and the
child sees its own unscaled local coordinates at any zoom. Flat-re-exported
from frust-widgets so app code never names that crate directly; see
PanZoomView’s own doc for the full contract (.inertia glide,
.on_transform notification, and the PanZoomController handle’s
jump_to/fit_to_bounds/fit_rect).
use frust::authoring::{PaintCtx, PaintScene};
use frust::{Component, PanZoomController, PanZoomTransform, View, canvas, pan_zoom};
use kurbo::{Point, Size};
use peniko::Color;
#[derive(Default)]
struct Board;
struct BoardState {
zoom: PanZoomController,
transform: PanZoomTransform,
}
impl Component for Board {
type State = BoardState;
fn init(&self) -> Self::State {
BoardState {
zoom: PanZoomController::new(),
transform: PanZoomTransform::IDENTITY,
}
}
fn build(&self, state: &mut Self::State) -> impl View<Self::State> {
pan_zoom(Self::surface())
.max_scale(4.0)
.inertia(true)
.controller(state.zoom.clone())
.on_transform(|state: &mut BoardState, t| state.transform = t)
}
}
impl Board {
fn surface() -> impl View<BoardState> {
canvas(|scene: &mut dyn PaintScene, size: Size, _ctx: &PaintCtx| {
scene.fill_rect(Point::ZERO, size, Color::from_rgb8(0x20, 0x20, 0x20));
})
.size(Size::new(2000.0, 1500.0))
}
}
frust::app!(Board);A declarative pan/zoom container. See the module docs.
Implementations§
Source§impl<State> PanZoomView<State>where
State: 'static,
impl<State> PanZoomView<State>where
State: 'static,
Sourcepub fn min_scale(self, scale: f64) -> PanZoomView<State>
pub fn min_scale(self, scale: f64) -> PanZoomView<State>
The smallest scale a zoom may reach (default DEFAULT_MIN_SCALE).
Non-positive or non-finite values are ignored.
Sourcepub fn max_scale(self, scale: f64) -> PanZoomView<State>
pub fn max_scale(self, scale: f64) -> PanZoomView<State>
The largest scale a zoom may reach (default DEFAULT_MAX_SCALE).
Non-positive or non-finite values are ignored.
Sourcepub fn inertia(self, inertia: bool) -> PanZoomView<State>
pub fn inertia(self, inertia: bool) -> PanZoomView<State>
Let a released pan glide to rest (default false).
Sourcepub fn on_transform<F>(self, on_transform: F) -> PanZoomView<State>
pub fn on_transform<F>(self, on_transform: F) -> PanZoomView<State>
Run on_transform(state, transform) after every change to the
transform (see the module docs).
Sourcepub fn controller(self, controller: PanZoomController) -> PanZoomView<State>
pub fn controller(self, controller: PanZoomController) -> PanZoomView<State>
Attach a PanZoomController.
Trait Implementations§
Source§impl<State> View<State> for PanZoomView<State>where
State: 'static,
impl<State> View<State> for PanZoomView<State>where
State: 'static,
Source§type Element = PanZoomWidget
type Element = PanZoomWidget
Source§fn build(&self, ctx: &mut BuildCtx<'_>) -> PanZoomWidget
fn build(&self, ctx: &mut BuildCtx<'_>) -> PanZoomWidget
Source§fn rebuild(
&self,
prev: &PanZoomView<State>,
element: &mut PanZoomWidget,
ctx: &mut BuildCtx<'_>,
) -> ChangeFlags
fn rebuild( &self, prev: &PanZoomView<State>, element: &mut PanZoomWidget, ctx: &mut BuildCtx<'_>, ) -> ChangeFlags
prev (the previous view of the same type) against the live
element, mutating it in place and reporting what changed.Auto Trait Implementations§
impl<State> !RefUnwindSafe for PanZoomView<State>
impl<State> !Send for PanZoomView<State>
impl<State> !Sync for PanZoomView<State>
impl<State> !UnwindSafe for PanZoomView<State>
impl<State> Freeze for PanZoomView<State>
impl<State> Unpin for PanZoomView<State>
impl<State> UnsafeUnpin for PanZoomView<State>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Source§impl<State, V> ViewSeq<State, One> for Vwhere
State: 'static,
V: View<State>,
impl<State, V> ViewSeq<State, One> for Vwhere
State: 'static,
V: View<State>,
Source§fn extend_views(self, out: &mut Vec<AnyView<State>>)
fn extend_views(self, out: &mut Vec<AnyView<State>>)
out — erasing each
with AnyView::new (a no-op for an element already an AnyView).