summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-07-22 20:09:13 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-07-22 20:09:13 +0700
commit26b2a824a930b8f98f4510aa2d2f3aaef7b669b9 (patch)
tree400db39091ca959dcbdf1992fae0f579eaa19c63 /native
parent45bd685f7c12ccb4c03a756b3d694672948c1a03 (diff)
downloadiced-26b2a824a930b8f98f4510aa2d2f3aaef7b669b9.tar.gz
iced-26b2a824a930b8f98f4510aa2d2f3aaef7b669b9.tar.bz2
iced-26b2a824a930b8f98f4510aa2d2f3aaef7b669b9.zip
Remove duplication of measuring logic in `PickList`
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/pick_list.rs40
1 files changed, 17 insertions, 23 deletions
diff --git a/native/src/widget/pick_list.rs b/native/src/widget/pick_list.rs
index fbc091ad..21c0c153 100644
--- a/native/src/widget/pick_list.rs
+++ b/native/src/widget/pick_list.rs
@@ -162,37 +162,31 @@ where
.pad(self.padding);
let text_size = self.text_size.unwrap_or(renderer.default_size());
+ let font = self.font;
let max_width = match self.width {
Length::Shrink => {
+ let measure = |label: &str| -> u32 {
+ let (width, _) = renderer.measure(
+ label,
+ text_size,
+ font,
+ Size::new(f32::INFINITY, f32::INFINITY),
+ );
+
+ width.round() as u32
+ };
+
let labels = self.options.iter().map(ToString::to_string);
- let labels_width = labels
- .map(|label| {
- let (width, _) = renderer.measure(
- &label,
- text_size,
- self.font,
- Size::new(f32::INFINITY, f32::INFINITY),
- );
-
- width.round() as u32
- })
- .max()
- .unwrap_or(100);
+
+ let labels_width =
+ labels.map(|label| measure(&label)).max().unwrap_or(100);
let placeholder_width = self
.placeholder
.as_ref()
- .map(|placeholder| {
- let (width, _) = renderer.measure(
- placeholder,
- text_size,
- self.font,
- Size::new(f32::INFINITY, f32::INFINITY),
- );
-
- width.round() as u32
- })
+ .map(String::as_str)
+ .map(measure)
.unwrap_or(100);
labels_width.max(placeholder_width)