From 3aee52575523d86760403fdbe93b201588cbceca Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Tue, 5 Aug 2025 14:55:24 +0200 Subject: [PATCH] Add `ComboBox::popup_style` (#7360) * Closes #7349 * [x] I have followed the instructions in the PR template --- crates/egui/src/containers/combo_box.rs | 19 ++++++++++++++++++- crates/egui/src/containers/popup.rs | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index 6ef92884..8195024f 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -44,6 +44,7 @@ pub struct ComboBox { icon: Option, wrap_mode: Option, close_behavior: Option, + popup_style: StyleModifier, } impl ComboBox { @@ -58,6 +59,7 @@ impl ComboBox { icon: None, wrap_mode: None, close_behavior: None, + popup_style: StyleModifier::default(), } } @@ -73,6 +75,7 @@ impl ComboBox { icon: None, wrap_mode: None, close_behavior: None, + popup_style: StyleModifier::default(), } } @@ -87,6 +90,7 @@ impl ComboBox { icon: None, wrap_mode: None, close_behavior: None, + popup_style: StyleModifier::default(), } } @@ -191,6 +195,16 @@ impl ComboBox { self } + /// Set the style of the popup menu. + /// + /// Could for example be used with [`crate::containers::menu::menu_style`] to get the frame-less + /// menu button style. + #[inline] + pub fn popup_style(mut self, popup_style: StyleModifier) -> Self { + self.popup_style = popup_style; + self + } + /// Show the combo box, with the given ui code for the menu contents. /// /// Returns `InnerResponse { inner: None }` if the combo box is closed. @@ -216,6 +230,7 @@ impl ComboBox { icon, wrap_mode, close_behavior, + popup_style, } = self; let button_id = ui.make_persistent_id(id_salt); @@ -229,6 +244,7 @@ impl ComboBox { icon, wrap_mode, close_behavior, + popup_style, (width, height), ); if let Some(label) = label { @@ -311,6 +327,7 @@ fn combo_box_dyn<'c, R>( icon: Option, wrap_mode: Option, close_behavior: Option, + popup_style: StyleModifier, (width, height): (Option, Option), ) -> InnerResponse> { let popup_id = ComboBox::widget_to_popup_id(button_id); @@ -379,9 +396,9 @@ fn combo_box_dyn<'c, R>( let inner = Popup::menu(&button_response) .id(popup_id) - .style(StyleModifier::default()) .width(button_response.rect.width()) .close_behavior(close_behavior) + .style(popup_style) .show(|ui| { ui.set_min_width(ui.available_width()); diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 9c280413..520fb408 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -500,6 +500,7 @@ impl<'a> Popup<'a> { } /// Show the popup. + /// /// Returns `None` if the popup is not open or anchor is `PopupAnchor::Pointer` and there is /// no pointer. pub fn show(self, content: impl FnOnce(&mut Ui) -> R) -> Option> {