Skip to main content

scroll

Function scroll 

Source
pub fn scroll(content: impl IntoElement) -> Element<ScrollView>
Expand description

Creates a view that clips content and scrolls it with the wheel.

The view is a panel one viewport tall, so give it a height, either directly or through a parent that sizes it. The content is laid out at its full height, however tall that is. A wheel scroll moves the content up while the pointer is over the view, clamped so the content’s bottom edge never rises above the bottom of the view’s content box, and a thin thumb at the right edge shows the position while the content overflows. The thumb is a position indicator only: it has no handlers and no dragging.

The offset can be controlled from outside through a signal, with ScrollExt::offset:

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 offset = RwSignal::new(0.0);
let view = scroll(
    column().child(panel().height(px(400.0)).background(Color::WHITE)),
)
.offset(offset.clone())
.height(px(120.0));

// Jump towards the bottom: the view clamps to what the content needs.
offset.set(f32::MAX);

Once the view and its content have painted, it writes the clamped offset back to the signal, so the signal always reads the position on screen. Before that, it applies any offset that is not negative as it is, which lets a view mount at a remembered position.