Allow scroll_to and snap_to to operate on a single axis

Co-authored-by: Rizzen Yazston <rizzen.yazston@gmail.com>
This commit is contained in:
Héctor Ramón Jiménez 2025-11-29 06:23:18 +01:00
parent 19569f7900
commit 8e372ce256
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 67 additions and 27 deletions

View file

@ -9,10 +9,13 @@ pub use crate::core::widget::operation::scrollable::{
};
/// Snaps the scrollable with the given [`Id`] to the provided [`RelativeOffset`].
pub fn snap_to<T>(id: impl Into<Id>, offset: RelativeOffset) -> Task<T> {
pub fn snap_to<T>(
id: impl Into<Id>,
offset: impl Into<RelativeOffset<Option<f32>>>,
) -> Task<T> {
task::effect(Action::widget(operation::scrollable::snap_to(
id.into(),
offset,
offset.into(),
)))
}
@ -20,15 +23,18 @@ pub fn snap_to<T>(id: impl Into<Id>, offset: RelativeOffset) -> Task<T> {
pub fn snap_to_end<T>(id: impl Into<Id>) -> Task<T> {
task::effect(Action::widget(operation::scrollable::snap_to(
id.into(),
RelativeOffset::END,
RelativeOffset::END.into(),
)))
}
/// Scrolls the scrollable with the given [`Id`] to the provided [`AbsoluteOffset`].
pub fn scroll_to<T>(id: impl Into<Id>, offset: AbsoluteOffset) -> Task<T> {
pub fn scroll_to<T>(
id: impl Into<Id>,
offset: impl Into<AbsoluteOffset<Option<f32>>>,
) -> Task<T> {
task::effect(Action::widget(operation::scrollable::scroll_to(
id.into(),
offset,
offset.into(),
)))
}