pub trait ScrollExt: Sized {
// Required methods
fn offset(self, signal: RwSignal<f32>) -> Self;
fn follow_end(self, signal: RwSignal<bool>) -> Self;
}Expand description
Controls the offset of a scroll view through a signal.
Import the trait to use it:
use smudge_core::reactive::RwSignal;
use smudge_core::widget::panel;
use smudge_widgets::{ScrollExt, column, scroll};
let offset = RwSignal::new(0.0);
let view = scroll(column().child(panel())).offset(offset);Required Methods§
Sourcefn offset(self, signal: RwSignal<f32>) -> Self
fn offset(self, signal: RwSignal<f32>) -> Self
Scrolls with signal: the view reads the signal for its offset, so a
write from anywhere moves the content, clamped to the content’s size.
The wheel writes the same signal, and the view writes the clamped offset back to it, so the view, the thumb and the signal stay in step.
Sourcefn follow_end(self, signal: RwSignal<bool>) -> Self
fn follow_end(self, signal: RwSignal<bool>) -> Self
Keeps the view at the end of its content while signal reads true.
While it follows, every frame that grows the content leaves the view
pinned to the end in the same frame, so a line appended to a log is
already in view. The core applies that pin after each layout pass,
where the painted heights the offset signal round-trips through are
one frame old. The view writes the painted end back to the offset
signal, so a signal set with ScrollExt::offset tracks the position
on screen and catches up one frame after a frame that grew the
content.
The signal is also where the view reports where the user is: any
wheel step that moves the view up from the end writes false, and a
step down that lands within four logical pixels of the end writes
true. Writing true from the application jumps to the end.
A view that starts following with content shorter than itself stays
at offset zero until the content grows past it.
Give the signal to one view. Two views that share it pin and release together, and a wheel step over either one decides for both.
While it follows, the offset signal is the view’s to write: a write
from the application is overwritten, and the way to move the view is
to write false first.
use smudge_core::geometry::Color;
use smudge_core::reactive::{RwSignal, prelude::*};
use smudge_core::style::px;
use smudge_core::widget::panel;
use smudge_widgets::{ScrollExt, column, scroll};
let following = RwSignal::new(true);
let view = scroll(
column().child(panel().height(px(400.0)).background(Color::WHITE)),
)
.follow_end(following.clone())
.height(px(120.0));
// The view shows the end of the content from the first frame on,
// and stays there while the content grows.
following.set(false);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".