Skip to content

Commit

Permalink
changed cow type to a generic that requires display to allow for more…
Browse files Browse the repository at this point in the history
… times to be passed in
  • Loading branch information
Redhawk18 committed Aug 14, 2023
1 parent 93a9a2d commit 69f3096
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
10 changes: 6 additions & 4 deletions src/native/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cow<'a, [T]>>,
options: &'a [T],
on_selected: impl Fn(usize, T) -> Message + 'static,
text_size: f32,
padding: f32,
Expand All @@ -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,

Check failure on line 321 in src/native/helpers.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced_aw/iced_aw/src/native/helpers.rs
[T]: ToOwned<Owned = Vec<T>>,
{

crate::SelectionList::new_with(
options,
on_selected,
Expand All @@ -337,7 +339,7 @@ where
/// [`SelectionList`]: crate::SelectionList
#[must_use]
pub fn selection_list<'a, T, Message, Renderer>(
options: impl Into<Cow<'a, [T]>>,
options: &'a [T],
on_selected: impl Fn(usize, T) -> Message + 'static,
) -> crate::SelectionList<'a, T, Message, Renderer>
where
Expand All @@ -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<Owned = Vec<T>>,
{
crate::SelectionList::new(options, on_selected)
Expand Down
21 changes: 8 additions & 13 deletions src/native/selection_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand All @@ -56,20 +56,16 @@ where
Message: 'a + Clone,
Renderer: 'a + core::Renderer + core::text::Renderer<Font = core::Font>,
Renderer::Theme: StyleSheet + container::StyleSheet + scrollable::StyleSheet,
T: Clone + ToString + Eq + Hash,
T: Clone + Display + Eq + Hash,
[T]: ToOwned<Owned = Vec<T>>,
{
/// 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<Cow<'a, [T]>>,
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,
Expand All @@ -96,17 +92,16 @@ 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<Cow<'a, [T]>>,
options: &'a [T],
on_selected: impl Fn(usize, T) -> Message + 'static,
text_size: f32,
padding: f32,
style: <Renderer::Theme as StyleSheet>::Style,
selected: Option<usize>,
font: Font,
) -> Self {
let options = options.into();
let container = Container::new(Scrollable::new(List {
options: options.clone(),
options,
font,
text_size,
padding,
Expand Down
10 changes: 5 additions & 5 deletions src/native/selection_list/list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Build and show dropdown `ListMenus`.
use std::{
borrow::Cow,
collections::hash_map::DefaultHasher,
fmt::Display,
hash::{Hash, Hasher},
marker::PhantomData,
};
Expand All @@ -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<Owned = Vec<T>>,
Renderer: core::Renderer + core::text::Renderer<Font = core::Font>,
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,
Expand Down Expand Up @@ -63,7 +63,7 @@ pub struct ListState {

impl<'a, T, Message, Renderer> Widget<Message, Renderer> for List<'a, T, Message, Renderer>
where
T: Clone + ToString + Eq + Hash,
T: Clone + Display + Eq + Hash,
Renderer: core::Renderer + core::text::Renderer<Font = core::Font>,
Renderer::Theme: StyleSheet,
{
Expand Down Expand Up @@ -278,7 +278,7 @@ where
impl<'a, T, Message, Renderer> From<List<'a, T, Message, Renderer>>
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<Font = core::Font>,
Renderer::Theme: StyleSheet,
Expand Down

0 comments on commit 69f3096

Please sign in to comment.