diff options
author | 2023-09-10 03:36:31 +0200 | |
---|---|---|
committer | 2023-09-10 03:36:31 +0200 | |
commit | bc1bde0d5ca1ec291f13e108f1543daa75b97848 (patch) | |
tree | 7d428814f6077e4af9ca0a92c936840e3eaf8e77 /widget/src/combo_box.rs | |
parent | 6d379b7fcef817bee1b1cb367bd308f9c6655b0b (diff) | |
download | iced-bc1bde0d5ca1ec291f13e108f1543daa75b97848.tar.gz iced-bc1bde0d5ca1ec291f13e108f1543daa75b97848.tar.bz2 iced-bc1bde0d5ca1ec291f13e108f1543daa75b97848.zip |
Fix `ComboBox` widget not displaying selection text
Diffstat (limited to 'widget/src/combo_box.rs')
-rw-r--r-- | widget/src/combo_box.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index d6915281..044dc0ef 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -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) |