From 5569e12149f9c29345fe404552ce156ef0bebf0e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Feb 2023 06:56:59 +0100 Subject: Rename `HandleContent` to `Icon` and simplify generics --- native/src/widget/pick_list.rs | 74 ++++++++++++------------------------------ 1 file changed, 20 insertions(+), 54 deletions(-) (limited to 'native') diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 862c4157..17fb00d5 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -20,49 +20,20 @@ use std::borrow::Cow; pub use iced_style::pick_list::{Appearance, StyleSheet}; -/// The content of the [`Handle`]. -#[derive(Clone)] -pub struct HandleContent -where - Renderer: text::Renderer, -{ +/// The icon of a [`Handle`]. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Icon { /// Font that will be used to display the `text`, - pub font: Renderer::Font, + pub font: Font, /// Text that will be shown. pub text: String, /// Font size of the content. pub size: Option, } -impl std::fmt::Debug for HandleContent -where - Renderer: text::Renderer, -{ - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("HandleIcon") - .field("text", &self.text) - .field("size", &self.size) - .finish() - } -} - -impl PartialEq for HandleContent -where - Renderer: text::Renderer, -{ - fn eq(&self, other: &Self) -> bool { - self.text.eq(&other.text) && self.size.eq(&other.size) - } -} - -impl Eq for HandleContent where Renderer: text::Renderer {} - /// The handle to the right side of the [`PickList`]. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum Handle -where - Renderer: text::Renderer, -{ +pub enum Handle { /// Displays an arrow icon (▼). /// /// This is the default. @@ -71,42 +42,36 @@ where size: Option, }, /// A custom static handle. - Static(HandleContent), + Static(Icon), /// A custom dynamic handle. Dynamic { - /// The [`HandleContent`] used when [`PickList`] is closed. - closed: HandleContent, - /// The [`HandleContent`] used when [`PickList`] is open. - open: HandleContent, + /// The [`Icon`] used when [`PickList`] is closed. + closed: Icon, + /// The [`Icon`] used when [`PickList`] is open. + open: Icon, }, /// No handle will be shown. None, } -impl Default for Handle -where - Renderer: text::Renderer, -{ +impl Default for Handle { fn default() -> Self { Self::Arrow { size: None } } } -impl Handle -where - Renderer: text::Renderer, -{ - fn content( +impl Handle { + fn content>( &self, is_open: bool, - ) -> Option<(Renderer::Font, String, Option)> { + ) -> Option<(Font, String, Option)> { match self { Self::Arrow { size } => Some(( Renderer::ICON_FONT, Renderer::ARROW_DOWN_ICON.to_string(), *size, )), - Self::Static(HandleContent { font, text, size }) => { + Self::Static(Icon { font, text, size }) => { Some((font.clone(), text.clone(), *size)) } Self::Dynamic { open, closed } => { @@ -141,7 +106,7 @@ where padding: Padding, text_size: Option, font: Renderer::Font, - handle: Handle, + handle: Handle, style: ::Style, } @@ -212,7 +177,7 @@ where } /// Sets the [`Handle`] of the [`PickList`]. - pub fn handle(mut self, handle: Handle) -> Self { + pub fn handle(mut self, handle: Handle) -> Self { self.handle = handle; self } @@ -630,7 +595,7 @@ pub fn draw<'a, T, Renderer>( font: &Renderer::Font, placeholder: Option<&str>, selected: Option<&T>, - handle: &Handle, + handle: &Handle, style: &::Style, state: impl FnOnce() -> &'a State, ) where @@ -659,7 +624,8 @@ pub fn draw<'a, T, Renderer>( style.background, ); - if let Some((font, text, size)) = handle.content(state.is_open) { + if let Some((font, text, size)) = handle.content::(state.is_open) + { let size = f32::from(size.unwrap_or_else(|| renderer.default_size())); renderer.fill_text(Text { -- cgit