Skip to content

Commit

Permalink
Use Into<Id> for scrollable::Id arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 30, 2025
1 parent a7bc1e7 commit fb87c97
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions widget/src/scrollable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ where
}

/// Sets the [`Id`] of the [`Scrollable`].
pub fn id(mut self, id: Id) -> Self {
self.id = Some(id);
pub fn id(mut self, id: impl Into<Id>) -> Self {
self.id = Some(id.into());
self
}

Expand Down Expand Up @@ -1228,25 +1228,36 @@ impl From<Id> for widget::Id {
}
}

impl From<&'static str> for Id {
fn from(id: &'static str) -> Self {
Self::new(id)
}
}

/// Produces a [`Task`] that snaps the [`Scrollable`] with the given [`Id`]
/// to the provided [`RelativeOffset`].
pub fn snap_to<T>(id: Id, offset: RelativeOffset) -> Task<T> {
task::effect(Action::widget(operation::scrollable::snap_to(id.0, offset)))
pub fn snap_to<T>(id: impl Into<Id>, offset: RelativeOffset) -> Task<T> {
task::effect(Action::widget(operation::scrollable::snap_to(
id.into().0,
offset,
)))
}

/// Produces a [`Task`] that scrolls the [`Scrollable`] with the given [`Id`]
/// to the provided [`AbsoluteOffset`].
pub fn scroll_to<T>(id: Id, offset: AbsoluteOffset) -> Task<T> {
pub fn scroll_to<T>(id: impl Into<Id>, offset: AbsoluteOffset) -> Task<T> {
task::effect(Action::widget(operation::scrollable::scroll_to(
id.0, offset,
id.into().0,
offset,
)))
}

/// Produces a [`Task`] that scrolls the [`Scrollable`] with the given [`Id`]
/// by the provided [`AbsoluteOffset`].
pub fn scroll_by<T>(id: Id, offset: AbsoluteOffset) -> Task<T> {
pub fn scroll_by<T>(id: impl Into<Id>, offset: AbsoluteOffset) -> Task<T> {
task::effect(Action::widget(operation::scrollable::scroll_by(
id.0, offset,
id.into().0,
offset,
)))
}

Expand Down

0 comments on commit fb87c97

Please sign in to comment.