diff options
author | 2021-07-22 20:32:43 +0700 | |
---|---|---|
committer | 2021-07-22 20:32:43 +0700 | |
commit | f076649fbb575ee036ab0b3f4511690e3379c115 (patch) | |
tree | 805377d47609364a579597c1c3966250d4f2e03a /graphics | |
parent | a2b1ba522a8b90a2e539fff5936c798efc3f3807 (diff) | |
parent | a866f8742e4ddf5714455519790fed0f961fad66 (diff) | |
download | iced-f076649fbb575ee036ab0b3f4511690e3379c115.tar.gz iced-f076649fbb575ee036ab0b3f4511690e3379c115.tar.bz2 iced-f076649fbb575ee036ab0b3f4511690e3379c115.zip |
Merge pull request #888 from Ace4896/picklist-placeholder
Add Placeholders to PickList
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/src/widget/pick_list.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/graphics/src/widget/pick_list.rs b/graphics/src/widget/pick_list.rs index 32dfbdf9..88a590b5 100644 --- a/graphics/src/widget/pick_list.rs +++ b/graphics/src/widget/pick_list.rs @@ -31,12 +31,14 @@ where bounds: Rectangle, cursor_position: Point, selected: Option<String>, + placeholder: Option<&str>, padding: Padding, text_size: u16, font: Font, style: &Box<dyn StyleSheet>, ) -> Self::Output { let is_mouse_over = bounds.contains(cursor_position); + let is_selected = selected.is_some(); let style = if is_mouse_over { style.hovered() @@ -68,12 +70,16 @@ where ( Primitive::Group { - primitives: if let Some(label) = selected { + primitives: if let Some(label) = + selected.or_else(|| placeholder.map(str::to_string)) + { let label = Primitive::Text { content: label, size: f32::from(text_size), font, - color: style.text_color, + color: is_selected + .then(|| style.text_color) + .unwrap_or(style.placeholder_color), bounds: Rectangle { x: bounds.x + f32::from(padding.left), y: bounds.center_y(), |