summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-01-30 02:52:24 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-01-30 02:52:24 +0100
commitfb87c971591042228c6ba5286e9d2efaf9852517 (patch)
tree28622d74f816d4eddb7044e9a8f3909fec83791a /widget
parenta7bc1e7da4a456b6fa53a7f9f86a6f1f0a172029 (diff)
downloadiced-fb87c971591042228c6ba5286e9d2efaf9852517.tar.gz
iced-fb87c971591042228c6ba5286e9d2efaf9852517.tar.bz2
iced-fb87c971591042228c6ba5286e9d2efaf9852517.zip
Use `Into<Id>` for `scrollable::Id` arguments
Diffstat (limited to 'widget')
-rw-r--r--widget/src/scrollable.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs
index b08d5d09..8ac70da8 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<Id>) -> Self {
+ self.id = Some(id.into());
self
}
@@ -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,
)))
}