Remove duplication of measuring logic in PickList
This commit is contained in:
parent
45bd685f7c
commit
26b2a824a9
1 changed files with 17 additions and 23 deletions
|
|
@ -162,37 +162,31 @@ where
|
||||||
.pad(self.padding);
|
.pad(self.padding);
|
||||||
|
|
||||||
let text_size = self.text_size.unwrap_or(renderer.default_size());
|
let text_size = self.text_size.unwrap_or(renderer.default_size());
|
||||||
|
let font = self.font;
|
||||||
|
|
||||||
let max_width = match self.width {
|
let max_width = match self.width {
|
||||||
Length::Shrink => {
|
Length::Shrink => {
|
||||||
let labels = self.options.iter().map(ToString::to_string);
|
let measure = |label: &str| -> u32 {
|
||||||
let labels_width = labels
|
let (width, _) = renderer.measure(
|
||||||
.map(|label| {
|
label,
|
||||||
let (width, _) = renderer.measure(
|
text_size,
|
||||||
&label,
|
font,
|
||||||
text_size,
|
Size::new(f32::INFINITY, f32::INFINITY),
|
||||||
self.font,
|
);
|
||||||
Size::new(f32::INFINITY, f32::INFINITY),
|
|
||||||
);
|
|
||||||
|
|
||||||
width.round() as u32
|
width.round() as u32
|
||||||
})
|
};
|
||||||
.max()
|
|
||||||
.unwrap_or(100);
|
let labels = self.options.iter().map(ToString::to_string);
|
||||||
|
|
||||||
|
let labels_width =
|
||||||
|
labels.map(|label| measure(&label)).max().unwrap_or(100);
|
||||||
|
|
||||||
let placeholder_width = self
|
let placeholder_width = self
|
||||||
.placeholder
|
.placeholder
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|placeholder| {
|
.map(String::as_str)
|
||||||
let (width, _) = renderer.measure(
|
.map(measure)
|
||||||
placeholder,
|
|
||||||
text_size,
|
|
||||||
self.font,
|
|
||||||
Size::new(f32::INFINITY, f32::INFINITY),
|
|
||||||
);
|
|
||||||
|
|
||||||
width.round() as u32
|
|
||||||
})
|
|
||||||
.unwrap_or(100);
|
.unwrap_or(100);
|
||||||
|
|
||||||
labels_width.max(placeholder_width)
|
labels_width.max(placeholder_width)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue