fix(dropdown::multi): paragraphs missing in layout on first init

This commit is contained in:
Michael Aaron Murphy 2023-12-05 16:53:20 +01:00 committed by Michael Murphy
parent 2cffbaf3a7
commit 3608675358

View file

@ -94,14 +94,25 @@ impl<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static>
self.text_line_height, self.text_line_height,
self.font, self.font,
self.selections.selected.as_ref().and_then(|id| { self.selections.selected.as_ref().and_then(|id| {
self.selections.get(id).map(AsRef::as_ref).zip( self.selections.get(id).map(AsRef::as_ref).zip({
tree.state let state = tree.state.downcast_mut::<State<Item>>();
.downcast_mut::<State<Item>>()
if state.selections.is_empty() {
for list in &self.selections.lists {
for (_, item) in &list.options {
state
.selections
.push((item.clone(), crate::Paragraph::new()));
}
}
}
state
.selections .selections
.iter_mut() .iter_mut()
.find(|(i, _)| i == id) .find(|(i, _)| i == id)
.map(|(_, p)| p), .map(|(_, p)| p)
) })
}), }),
) )
} }
@ -432,16 +443,14 @@ pub fn overlay<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static
} }
super::menu::OptionElement::Option((option, item)) => { super::menu::OptionElement::Option((option, item)) => {
let paragraph = if let Some(index) = let selection_index = state
state.selections.iter().position(|(i, _)| i == item) .selections
{ .iter()
&mut state.selections[index].1 .position(|(i, _)| i == item)
} else { .expect("selection missing from state");
state
.selections let paragraph = &mut state.selections[selection_index].1;
.push((item.clone(), crate::Paragraph::new()));
&mut state.selections.last_mut().unwrap().1
};
measure(option.as_ref(), paragraph, text_line_height) measure(option.as_ref(), paragraph, text_line_height)
} }