From fa433743b352f9a27e0669d4da41f645db8b04cb Mon Sep 17 00:00:00 2001 From: Jon Pacheco Date: Sat, 22 May 2021 19:28:17 +0100 Subject: feat: add placeholders to pick_list see issue #726 --- graphics/src/widget/pick_list.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'graphics/src') diff --git a/graphics/src/widget/pick_list.rs b/graphics/src/widget/pick_list.rs index 32dfbdf9..a7fe3e93 100644 --- a/graphics/src/widget/pick_list.rs +++ b/graphics/src/widget/pick_list.rs @@ -31,6 +31,7 @@ where bounds: Rectangle, cursor_position: Point, selected: Option, + placeholder: Option, padding: Padding, text_size: u16, font: Font, @@ -68,7 +69,7 @@ where ( Primitive::Group { - primitives: if let Some(label) = selected { + primitives: if let Some(label) = selected.or(placeholder) { let label = Primitive::Text { content: label, size: f32::from(text_size), -- cgit From 1b3606884747374f1e5599e3c783f36a2f2cac6f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 22 Jul 2021 20:13:14 +0700 Subject: Introduce `placeholder_color` to `pick_list::Style` --- graphics/src/widget/pick_list.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'graphics/src') diff --git a/graphics/src/widget/pick_list.rs b/graphics/src/widget/pick_list.rs index a7fe3e93..01283bd5 100644 --- a/graphics/src/widget/pick_list.rs +++ b/graphics/src/widget/pick_list.rs @@ -38,6 +38,7 @@ where style: &Box, ) -> Self::Output { let is_mouse_over = bounds.contains(cursor_position); + let is_selected = selected.is_some(); let style = if is_mouse_over { style.hovered() @@ -74,7 +75,9 @@ where 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(), -- cgit From a866f8742e4ddf5714455519790fed0f961fad66 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 22 Jul 2021 20:16:53 +0700 Subject: Avoid cloning `placeholder` for `PickList` unnecessarily during `draw` --- graphics/src/widget/pick_list.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'graphics/src') diff --git a/graphics/src/widget/pick_list.rs b/graphics/src/widget/pick_list.rs index 01283bd5..88a590b5 100644 --- a/graphics/src/widget/pick_list.rs +++ b/graphics/src/widget/pick_list.rs @@ -31,7 +31,7 @@ where bounds: Rectangle, cursor_position: Point, selected: Option, - placeholder: Option, + placeholder: Option<&str>, padding: Padding, text_size: u16, font: Font, @@ -70,7 +70,9 @@ where ( Primitive::Group { - primitives: if let Some(label) = selected.or(placeholder) { + primitives: if let Some(label) = + selected.or_else(|| placeholder.map(str::to_string)) + { let label = Primitive::Text { content: label, size: f32::from(text_size), -- cgit