From bc1bde0d5ca1ec291f13e108f1543daa75b97848 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 10 Sep 2023 03:36:31 +0200 Subject: Fix `ComboBox` widget not displaying selection text --- widget/src/combo_box.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'widget/src/combo_box.rs') 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.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::>( + ) + .unfocus(); + + (self.on_selected)(x) + }, self.on_option_hovered.as_deref(), ) .width(bounds.width) -- cgit