Avoid cloning placeholder for PickList unnecessarily during draw

This commit is contained in:
Héctor Ramón Jiménez 2021-07-22 20:16:53 +07:00
parent 1b36068847
commit a866f8742e
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 6 additions and 4 deletions

View file

@ -31,7 +31,7 @@ where
bounds: Rectangle,
cursor_position: Point,
selected: Option<String>,
placeholder: Option<String>,
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),

View file

@ -285,7 +285,7 @@ where
layout.bounds(),
cursor_position,
self.selected.as_ref().map(ToString::to_string),
self.placeholder.clone(),
self.placeholder.as_ref().map(String::as_str),
self.padding,
self.text_size.unwrap_or(renderer.default_size()),
self.font,
@ -346,7 +346,7 @@ pub trait Renderer: text::Renderer + menu::Renderer {
bounds: Rectangle,
cursor_position: Point,
selected: Option<String>,
placeholder: Option<String>,
placeholder: Option<&str>,
padding: Padding,
text_size: u16,
font: Self::Font,