From fb87c971591042228c6ba5286e9d2efaf9852517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 30 Jan 2025 02:52:24 +0100 Subject: [PATCH] Use `Into` for `scrollable::Id` arguments --- widget/src/scrollable.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index b08d5d09eb..8ac70da87c 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -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) -> Self { + self.id = Some(id.into()); self } @@ -1228,25 +1228,36 @@ impl From 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(id: Id, offset: RelativeOffset) -> Task { - task::effect(Action::widget(operation::scrollable::snap_to(id.0, offset))) +pub fn snap_to(id: impl Into, offset: RelativeOffset) -> Task { + 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(id: Id, offset: AbsoluteOffset) -> Task { +pub fn scroll_to(id: impl Into, offset: AbsoluteOffset) -> Task { 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(id: Id, offset: AbsoluteOffset) -> Task { +pub fn scroll_by(id: impl Into, offset: AbsoluteOffset) -> Task { task::effect(Action::widget(operation::scrollable::scroll_by( - id.0, offset, + id.into().0, + offset, ))) }