diff options
author | 2020-04-18 19:53:27 +0200 | |
---|---|---|
committer | 2020-07-08 11:05:15 +0200 | |
commit | e29feef8ba4f95f286039fcc1ca2e53bfe5019c5 (patch) | |
tree | ac3e4e8bce0fcca65cd536f4a821fb5517b84947 /graphics | |
parent | ada8d7c77f9e1d4a1de762b514c9610f7e09b17f (diff) | |
download | iced-e29feef8ba4f95f286039fcc1ca2e53bfe5019c5.tar.gz iced-e29feef8ba4f95f286039fcc1ca2e53bfe5019c5.tar.bz2 iced-e29feef8ba4f95f286039fcc1ca2e53bfe5019c5.zip |
Render arrow icon in `ComboBox`
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/fonts/Icons.ttf | bin | 4912 -> 5032 bytes | |||
-rw-r--r-- | graphics/src/backend.rs | 7 | ||||
-rw-r--r-- | graphics/src/font.rs | 6 | ||||
-rw-r--r-- | graphics/src/widget/combo_box.rs | 52 |
4 files changed, 45 insertions, 20 deletions
diff --git a/graphics/fonts/Icons.ttf b/graphics/fonts/Icons.ttf Binary files differindex 1c832f86..5e455b69 100644 --- a/graphics/fonts/Icons.ttf +++ b/graphics/fonts/Icons.ttf diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs index b73c636e..dd7dbbc2 100644 --- a/graphics/src/backend.rs +++ b/graphics/src/backend.rs @@ -22,9 +22,14 @@ pub trait Text { /// The `char` representing a ✔ icon in the [`ICON_FONT`]. /// - /// [`ICON_FONT`]: #associatedconst.ICON_FONt + /// [`ICON_FONT`]: #associatedconst.ICON_FONT const CHECKMARK_ICON: char; + /// The `char` representing a ▼ icon in the built-in [`ICONS`] font. + /// + /// [`ICON_FONT`]: #associatedconst.ICON_FONT + const ARROW_DOWN_ICON: char; + /// Returns the default size of text. fn default_size(&self) -> u16; diff --git a/graphics/src/font.rs b/graphics/src/font.rs index bcc28857..5c62681c 100644 --- a/graphics/src/font.rs +++ b/graphics/src/font.rs @@ -31,3 +31,9 @@ pub const ICONS: iced_native::Font = iced_native::Font::External { #[cfg(feature = "font-icons")] #[cfg_attr(docsrs, doc(cfg(feature = "font-icons")))] pub const CHECKMARK_ICON: char = '\u{F00C}'; + +/// The `char` representing a ▼ icon in the built-in [`ICONS`] font. +/// +/// [`ICONS`]: const.ICONS.html +#[cfg(feature = "font-icons")] +pub const ARROW_DOWN_ICON: char = '\u{E800}'; diff --git a/graphics/src/widget/combo_box.rs b/graphics/src/widget/combo_box.rs index 27ea762a..92024c6c 100644 --- a/graphics/src/widget/combo_box.rs +++ b/graphics/src/widget/combo_box.rs @@ -35,27 +35,41 @@ where border_radius: 0, }; + let arrow_down = Primitive::Text { + content: B::ARROW_DOWN_ICON.to_string(), + font: B::ICON_FONT, + size: bounds.height * 0.7, + bounds: Rectangle { + x: bounds.x + bounds.width - f32::from(padding) * 2.0, + y: bounds.center_y(), + ..bounds + }, + color: Color::BLACK, + horizontal_alignment: HorizontalAlignment::Right, + vertical_alignment: VerticalAlignment::Center, + }; + ( - if let Some(label) = selected { - let label = Primitive::Text { - content: label, - size: f32::from(text_size), - font: Font::Default, - color: Color::BLACK, - bounds: Rectangle { - x: bounds.x + f32::from(padding), - y: bounds.center_y(), - ..bounds - }, - horizontal_alignment: HorizontalAlignment::Left, - vertical_alignment: VerticalAlignment::Center, - }; + Primitive::Group { + primitives: if let Some(label) = selected { + let label = Primitive::Text { + content: label, + size: f32::from(text_size), + font: Font::Default, + color: Color::BLACK, + bounds: Rectangle { + x: bounds.x + f32::from(padding), + y: bounds.center_y(), + ..bounds + }, + horizontal_alignment: HorizontalAlignment::Left, + vertical_alignment: VerticalAlignment::Center, + }; - Primitive::Group { - primitives: vec![background, label], - } - } else { - background + vec![background, label, arrow_down] + } else { + vec![background, arrow_down] + }, }, if is_mouse_over { mouse::Interaction::Pointer |