Fix ComboBox widget not displaying selection text

This commit is contained in:
Héctor Ramón Jiménez 2023-09-10 03:36:31 +02:00
parent 6d379b7fce
commit bc1bde0d5c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 50 additions and 3 deletions

View file

@ -311,7 +311,20 @@ where
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
self.text_input.layout(tree, renderer, limits)
let is_focused = {
let text_input_state = tree.children[0]
.state
.downcast_ref::<text_input::State<Renderer::Paragraph>>();
text_input_state.is_focused()
};
self.text_input.layout(
&mut tree.children[0],
renderer,
limits,
(!is_focused).then_some(&self.selection),
)
}
fn tag(&self) -> widget::tree::Tag {
@ -665,7 +678,15 @@ where
menu,
&filtered_options.options,
hovered_option,
|x| (self.on_selected)(x),
|x| {
tree.children[0]
.state
.downcast_mut::<text_input::State<Renderer::Paragraph>>(
)
.unfocus();
(self.on_selected)(x)
},
self.on_option_hovered.as_deref(),
)
.width(bounds.width)