From 39f49186cefa688a1cc80ed754ec4028c642636a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 14 Dec 2022 03:29:20 +0100 Subject: Rename `pick_list::AccessoryContent` to `Handle` ... and rename `Default` variant to `Arrow`. --- native/src/widget/pick_list.rs | 61 ++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 32 deletions(-) (limited to 'native/src/widget') diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 6a2061b9..43ae7ebb 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -20,56 +20,56 @@ use std::borrow::Cow; pub use iced_style::pick_list::{Appearance, StyleSheet}; -/// The content to the right side of the [`PickList`]. +/// The handle to the right side of the [`PickList`]. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum AccessoryContent +pub enum Handle where Renderer: text::Renderer, { - /// Default accessory content. - Default { + /// Displays an arrow icon (▼). + /// + /// This is the default. + Arrow { /// Font size of the content. size: Option, }, - /// Custom accessory content. + /// A custom handle. Custom { - /// Font which will be used in the accessory content. + /// Font that will be used to display the `text`, font: Renderer::Font, - /// Content which will be shown. - content: String, + /// Text that will be shown. + text: String, /// Font size of the content. size: Option, }, - /// No accessory content will be shown. + /// No handle will be shown. None, } -impl Default for AccessoryContent +impl Default for Handle where Renderer: text::Renderer, { fn default() -> Self { - Self::Default { size: None } + Self::Arrow { size: None } } } -impl AccessoryContent +impl Handle where Renderer: text::Renderer, { fn content(&self) -> Option<(Renderer::Font, String, Option)> { match self { - AccessoryContent::Default { size } => Some(( + Self::Arrow { size } => Some(( Renderer::ICON_FONT, Renderer::ARROW_DOWN_ICON.to_string(), *size, )), - AccessoryContent::Custom { - font, - content, - size, - } => Some((font.clone(), content.clone(), *size)), - AccessoryContent::None => None, + Self::Custom { font, text, size } => { + Some((font.clone(), text.clone(), *size)) + } + Self::None => None, } } } @@ -90,7 +90,7 @@ where padding: Padding, text_size: Option, font: Renderer::Font, - accessory_content: AccessoryContent, + handle: Handle, style: ::Style, } @@ -125,7 +125,7 @@ where padding: Self::DEFAULT_PADDING, text_size: None, font: Default::default(), - accessory_content: Default::default(), + handle: Default::default(), style: Default::default(), } } @@ -160,12 +160,9 @@ where self } - /// Sets the [`AccessoryContent`] of the [`PickList`]. - pub fn accessory_content( - mut self, - accessory_content: AccessoryContent, - ) -> Self { - self.accessory_content = accessory_content; + /// Sets the [`Handle`] of the [`PickList`]. + pub fn handle(mut self, handle: Handle) -> Self { + self.handle = handle; self } @@ -279,7 +276,7 @@ where &self.font, self.placeholder.as_deref(), self.selected.as_ref(), - &self.accessory_content, + &self.handle, &self.style, ) } @@ -581,7 +578,7 @@ pub fn draw( font: &Renderer::Font, placeholder: Option<&str>, selected: Option<&T>, - accessory_content: &AccessoryContent, + handle: &Handle, style: &::Style, ) where Renderer: text::Renderer, @@ -608,14 +605,14 @@ pub fn draw( style.background, ); - if let Some((font, content, size)) = accessory_content.content() { + if let Some((font, text, size)) = handle.content() { let size = f32::from(size.unwrap_or_else(|| renderer.default_size())); renderer.fill_text(Text { - content: &content, + content: &text, size, font, - color: style.accessory_content_color, + color: style.handle_color, bounds: Rectangle { x: bounds.x + bounds.width - f32::from(padding.horizontal()), y: bounds.center_y() - size / 2.0, -- cgit