ScrollController & Physics
Scroll position, physics policies, metrics, and notifications.
Keep the controller outside rebuilds to preserve position.
| Member | Kind | Notes |
|---|---|---|
ScrollController::new() | Constructor | Holds pixel position |
jump_to(px) | Command | Immediate jump |
animate_to(px, dur, curve) | Command | Animated scroll |
position() | Query | ScrollMetrics: pixels, viewport, range |
ClampingScrollPhysics | Policy | Hard stop at edges |
BoundaryPhysics | Policy | Custom boundary behavior |
SnapPhysics | Policy | Snap to item/page boundaries |
ScrollController
use incular::prelude::*;
fn main() {
let controller = ScrollController::new();
controller.jump_to(0.0);
let app = Application::new(move |_cx| {
Container::builder()
.padding(EdgeInsets::all(24.0))
.alignment(Alignment::CENTER)
.child(
ListView::builder(100, |i| Text::new(format!("row {i}")))
.controller(controller.clone())
.physics(ScrollPhysics::clamping()),
)
.build()
.into()
})
.expect("valid application");
incular::run(app).expect("run application");
}PageController = ScrollController (see PageView).
ScrollPhysics
use incular::prelude::*;
fn main() {
println!("clamping: {:?}", ScrollPhysics::clamping());
println!("has physics: {}", true);
}Supporting enums
Scrollability: Enabled / Disabled. DragStartBehavior: Start /
Down. ScrollViewKeyboardDismissBehavior: Manual / OnDrag.
Metrics and notifications
ScrollMetrics carries pixels, viewport, and range extents.
NotificationListener::new(child) observes scroll notifications (return true
to stop bubbling); ScrollNotificationObserver::new(child) is the
passthrough form.
ScrollNotificationType: start / update / end / overscroll variants with
metrics payloads. See Physics for spring and
friction tuning.
ScrollView and SingleChildScrollView
use incular::prelude::*;
fn main() {
let controller = ScrollController::new();
let app = Application::new(move |_cx| {
SingleChildScrollView::new(Text::new("Hi")).controller(
controller.clone(),
).into()
})
.expect("valid application");
incular::run(app).expect("run application");
}ScrollView::vertical is the retained-viewport helper; SingleChildScrollView
adds direction, reversal, padding, and explicit controller/physics.
Related: ListView,
SliverList.