diff options
author | 2023-02-14 06:59:37 +0100 | |
---|---|---|
committer | 2023-02-14 07:03:24 +0100 | |
commit | 0272cac89e2bb3e037d0d9d5caa8b7c584386417 (patch) | |
tree | 4a2bb0b95ece3f27ce8ccdc7535b5f901bfc0763 /native/src/widget | |
parent | 5569e12149f9c29345fe404552ce156ef0bebf0e (diff) | |
download | iced-0272cac89e2bb3e037d0d9d5caa8b7c584386417.tar.gz iced-0272cac89e2bb3e037d0d9d5caa8b7c584386417.tar.bz2 iced-0272cac89e2bb3e037d0d9d5caa8b7c584386417.zip |
Move `Handle` and `Icon` definitions in `pick_list`
Diffstat (limited to 'native/src/widget')
-rw-r--r-- | native/src/widget/pick_list.rs | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs index 17fb00d5..b9f6f088 100644 --- a/native/src/widget/pick_list.rs +++ b/native/src/widget/pick_list.rs @@ -20,76 +20,6 @@ use std::borrow::Cow; pub use iced_style::pick_list::{Appearance, StyleSheet}; -/// The icon of a [`Handle`]. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Icon<Font> { - /// Font that will be used to display the `text`, - pub font: Font, - /// Text that will be shown. - pub text: String, - /// Font size of the content. - pub size: Option<u16>, -} - -/// The handle to the right side of the [`PickList`]. -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum Handle<Font> { - /// Displays an arrow icon (▼). - /// - /// This is the default. - Arrow { - /// Font size of the content. - size: Option<u16>, - }, - /// A custom static handle. - Static(Icon<Font>), - /// A custom dynamic handle. - Dynamic { - /// The [`Icon`] used when [`PickList`] is closed. - closed: Icon<Font>, - /// The [`Icon`] used when [`PickList`] is open. - open: Icon<Font>, - }, - /// No handle will be shown. - None, -} - -impl<Font> Default for Handle<Font> { - fn default() -> Self { - Self::Arrow { size: None } - } -} - -impl<Font: Clone> Handle<Font> { - fn content<Renderer: text::Renderer<Font = Font>>( - &self, - is_open: bool, - ) -> Option<(Font, String, Option<u16>)> { - match self { - Self::Arrow { size } => Some(( - Renderer::ICON_FONT, - Renderer::ARROW_DOWN_ICON.to_string(), - *size, - )), - Self::Static(Icon { font, text, size }) => { - Some((font.clone(), text.clone(), *size)) - } - Self::Dynamic { open, closed } => { - if is_open { - Some((open.font.clone(), open.text.clone(), open.size)) - } else { - Some(( - closed.font.clone(), - closed.text.clone(), - closed.size, - )) - } - } - Self::None => None, - } - } -} - /// A widget for selecting a single value from a list of options. #[allow(missing_debug_implementations)] pub struct PickList<'a, T, Message, Renderer> @@ -366,6 +296,76 @@ impl<T> Default for State<T> { } } +/// The handle to the right side of the [`PickList`]. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum Handle<Font> { + /// Displays an arrow icon (▼). + /// + /// This is the default. + Arrow { + /// Font size of the content. + size: Option<u16>, + }, + /// A custom static handle. + Static(Icon<Font>), + /// A custom dynamic handle. + Dynamic { + /// The [`Icon`] used when [`PickList`] is closed. + closed: Icon<Font>, + /// The [`Icon`] used when [`PickList`] is open. + open: Icon<Font>, + }, + /// No handle will be shown. + None, +} + +impl<Font> Default for Handle<Font> { + fn default() -> Self { + Self::Arrow { size: None } + } +} + +impl<Font: Clone> Handle<Font> { + fn content<Renderer: text::Renderer<Font = Font>>( + &self, + is_open: bool, + ) -> Option<(Font, String, Option<u16>)> { + match self { + Self::Arrow { size } => Some(( + Renderer::ICON_FONT, + Renderer::ARROW_DOWN_ICON.to_string(), + *size, + )), + Self::Static(Icon { font, text, size }) => { + Some((font.clone(), text.clone(), *size)) + } + Self::Dynamic { open, closed } => { + if is_open { + Some((open.font.clone(), open.text.clone(), open.size)) + } else { + Some(( + closed.font.clone(), + closed.text.clone(), + closed.size, + )) + } + } + Self::None => None, + } + } +} + +/// The icon of a [`Handle`]. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Icon<Font> { + /// Font that will be used to display the `text`, + pub font: Font, + /// Text that will be shown. + pub text: String, + /// Font size of the content. + pub size: Option<u16>, +} + /// Computes the layout of a [`PickList`]. pub fn layout<Renderer, T>( renderer: &Renderer, |