diff --git a/src/native/helpers.rs b/src/native/helpers.rs index e1e60887..dbdbf5ee 100644 --- a/src/native/helpers.rs +++ b/src/native/helpers.rs @@ -298,12 +298,13 @@ where } #[cfg(feature = "selection_list")] +use std::fmt::Display; /// Shortcut helper to create a [`SelectionList`] Widget. /// /// [`SelectionList`]: crate::SelectionList #[must_use] pub fn selection_list_with<'a, T, Message, Renderer>( - options: impl Into>, + options: &'a [T], on_selected: impl Fn(usize, T) -> Message + 'static, text_size: f32, padding: f32, @@ -317,9 +318,10 @@ where Renderer::Theme: crate::style::selection_list::StyleSheet + iced_widget::container::StyleSheet + iced_widget::scrollable::StyleSheet, - T: Clone + ToString + Eq + Hash, + T: Clone + Display + Eq + Hash, [T]: ToOwned>, { + crate::SelectionList::new_with( options, on_selected, @@ -337,7 +339,7 @@ where /// [`SelectionList`]: crate::SelectionList #[must_use] pub fn selection_list<'a, T, Message, Renderer>( - options: impl Into>, + options: &'a [T], on_selected: impl Fn(usize, T) -> Message + 'static, ) -> crate::SelectionList<'a, T, Message, Renderer> where @@ -346,7 +348,7 @@ where Renderer::Theme: crate::style::selection_list::StyleSheet + iced_widget::container::StyleSheet + iced_widget::scrollable::StyleSheet, - T: Clone + ToString + Eq + Hash, + T: Clone + Display + Eq + Hash, [T]: ToOwned>, { crate::SelectionList::new(options, on_selected) diff --git a/src/native/selection_list.rs b/src/native/selection_list.rs index 718d7fc3..48081113 100644 --- a/src/native/selection_list.rs +++ b/src/native/selection_list.rs @@ -19,8 +19,8 @@ use iced_widget::{ }; pub use list::List; -use std::marker::PhantomData; -use std::{borrow::Cow, hash::Hash}; +use std::hash::Hash; +use std::{fmt::Display, marker::PhantomData}; /// A widget for selecting a single value from a dynamic scrollable list of options. #[allow(missing_debug_implementations)] @@ -35,7 +35,7 @@ where /// Container for Rendering List. container: Container<'a, Message, Renderer>, /// List of Elements to Render. - options: Cow<'a, [T]>, + options: &'a [T], /// Label Font font: Renderer::Font, /// The Containers Width @@ -56,20 +56,16 @@ where Message: 'a + Clone, Renderer: 'a + core::Renderer + core::text::Renderer, Renderer::Theme: StyleSheet + container::StyleSheet + scrollable::StyleSheet, - T: Clone + ToString + Eq + Hash, + T: Clone + Display + Eq + Hash, [T]: ToOwned>, { /// Creates a new [`SelectionList`] with the given list of `options`, /// the current selected value, and the `message` to produce when an option is /// selected. This will default the `style`, `text_size` and `padding`. use `new_with` /// to set those. - pub fn new( - options: impl Into>, - on_selected: impl Fn(usize, T) -> Message + 'static, - ) -> Self { - let options = options.into(); + pub fn new(options: &'a [T], on_selected: impl Fn(usize, T) -> Message + 'static) -> Self { let container = Container::new(Scrollable::new(List { - options: options.clone(), + options, font: Font::default(), text_size: 12.0, padding: 5.0, @@ -96,7 +92,7 @@ where /// the current selected value, the message to produce when an option is /// selected, the `style`, `text_size`, `padding` and `font`. pub fn new_with( - options: impl Into>, + options: &'a [T], on_selected: impl Fn(usize, T) -> Message + 'static, text_size: f32, padding: f32, @@ -104,9 +100,8 @@ where selected: Option, font: Font, ) -> Self { - let options = options.into(); let container = Container::new(Scrollable::new(List { - options: options.clone(), + options, font, text_size, padding, diff --git a/src/native/selection_list/list.rs b/src/native/selection_list/list.rs index 1d399d83..add92a7e 100644 --- a/src/native/selection_list/list.rs +++ b/src/native/selection_list/list.rs @@ -1,7 +1,7 @@ //! Build and show dropdown `ListMenus`. use std::{ - borrow::Cow, collections::hash_map::DefaultHasher, + fmt::Display, hash::{Hash, Hasher}, marker::PhantomData, }; @@ -28,13 +28,13 @@ use iced_widget::{ #[allow(missing_debug_implementations)] pub struct List<'a, T: 'a, Message, Renderer> where - T: Clone + ToString + Eq + Hash, + T: Clone + Display + Eq + Hash, [T]: ToOwned>, Renderer: core::Renderer + core::text::Renderer, Renderer::Theme: StyleSheet, { /// Options pointer to hold all rendered strings - pub options: Cow<'a, [T]>, + pub options: &'a [T], /// Hovered Item Pointer /// Label Font pub font: Renderer::Font, @@ -63,7 +63,7 @@ pub struct ListState { impl<'a, T, Message, Renderer> Widget for List<'a, T, Message, Renderer> where - T: Clone + ToString + Eq + Hash, + T: Clone + Display + Eq + Hash, Renderer: core::Renderer + core::text::Renderer, Renderer::Theme: StyleSheet, { @@ -278,7 +278,7 @@ where impl<'a, T, Message, Renderer> From> for Element<'a, Message, Renderer> where - T: Clone + ToString + Eq + Hash, + T: Clone + Display + Eq + Hash, Message: 'a, Renderer: 'a + core::Renderer + core::text::Renderer, Renderer::Theme: StyleSheet,