diff options
author | 2024-04-02 09:49:36 +0200 | |
---|---|---|
committer | 2024-04-02 09:49:36 +0200 | |
commit | 27312187f36773ffbe20c0b3daddc93eaffa730e (patch) | |
tree | 451e7bc327bc6557d14e1380d38bdd858c8da4d2 /widget | |
parent | 6c75836f123eba909154ce517299c3ffcd21b25b (diff) | |
parent | 8c08cce6ffb2214307bb79213896f5cb4ea5ea3f (diff) | |
download | iced-27312187f36773ffbe20c0b3daddc93eaffa730e.tar.gz iced-27312187f36773ffbe20c0b3daddc93eaffa730e.tar.bz2 iced-27312187f36773ffbe20c0b3daddc93eaffa730e.zip |
Merge pull request #2364 from blazra/combobox-menu-fix
combo_box: Do not draw empty menu overlay
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/combo_box.rs | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index e4f4a41f..253850df 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -700,38 +700,47 @@ where .. } = tree.state.downcast_mut::<Menu<T>>(); - let bounds = layout.bounds(); - self.state.sync_filtered_options(filtered_options); - let mut menu = menu::Menu::new( - menu, - &filtered_options.options, - hovered_option, - |x| { - tree.children[0] - .state - .downcast_mut::<text_input::State<Renderer::Paragraph>>( - ) - .unfocus(); - - (self.on_selected)(x) - }, - self.on_option_hovered.as_deref(), - &self.menu_class, - ) - .width(bounds.width) - .padding(self.padding); - - if let Some(font) = self.font { - menu = menu.font(font); - } + if filtered_options.options.is_empty() { + None + } else { + let bounds = layout.bounds(); + + let mut menu = menu::Menu::new( + menu, + &filtered_options.options, + hovered_option, + |x| { + tree.children[0] + .state + .downcast_mut::<text_input::State<Renderer::Paragraph>>( + ) + .unfocus(); + + (self.on_selected)(x) + }, + self.on_option_hovered.as_deref(), + &self.menu_class, + ) + .width(bounds.width) + .padding(self.padding); + + if let Some(font) = self.font { + menu = menu.font(font); + } - if let Some(size) = self.size { - menu = menu.text_size(size); - } + if let Some(size) = self.size { + menu = menu.text_size(size); + } - Some(menu.overlay(layout.position() + translation, bounds.height)) + Some( + menu.overlay( + layout.position() + translation, + bounds.height, + ), + ) + } } else { None } |