Add `ComboBox::popup_style` (#7360)

* Closes #7349  
* [x] I have followed the instructions in the PR template
This commit is contained in:
Lucas Meurer 2025-08-05 14:55:24 +02:00 committed by GitHub
parent a1e5501db8
commit 3aee525755
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -44,6 +44,7 @@ pub struct ComboBox {
icon: Option<IconPainter>, icon: Option<IconPainter>,
wrap_mode: Option<TextWrapMode>, wrap_mode: Option<TextWrapMode>,
close_behavior: Option<PopupCloseBehavior>, close_behavior: Option<PopupCloseBehavior>,
popup_style: StyleModifier,
} }
impl ComboBox { impl ComboBox {
@ -58,6 +59,7 @@ impl ComboBox {
icon: None, icon: None,
wrap_mode: None, wrap_mode: None,
close_behavior: None, close_behavior: None,
popup_style: StyleModifier::default(),
} }
} }
@ -73,6 +75,7 @@ impl ComboBox {
icon: None, icon: None,
wrap_mode: None, wrap_mode: None,
close_behavior: None, close_behavior: None,
popup_style: StyleModifier::default(),
} }
} }
@ -87,6 +90,7 @@ impl ComboBox {
icon: None, icon: None,
wrap_mode: None, wrap_mode: None,
close_behavior: None, close_behavior: None,
popup_style: StyleModifier::default(),
} }
} }
@ -191,6 +195,16 @@ impl ComboBox {
self 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. /// Show the combo box, with the given ui code for the menu contents.
/// ///
/// Returns `InnerResponse { inner: None }` if the combo box is closed. /// Returns `InnerResponse { inner: None }` if the combo box is closed.
@ -216,6 +230,7 @@ impl ComboBox {
icon, icon,
wrap_mode, wrap_mode,
close_behavior, close_behavior,
popup_style,
} = self; } = self;
let button_id = ui.make_persistent_id(id_salt); let button_id = ui.make_persistent_id(id_salt);
@ -229,6 +244,7 @@ impl ComboBox {
icon, icon,
wrap_mode, wrap_mode,
close_behavior, close_behavior,
popup_style,
(width, height), (width, height),
); );
if let Some(label) = label { if let Some(label) = label {
@ -311,6 +327,7 @@ fn combo_box_dyn<'c, R>(
icon: Option<IconPainter>, icon: Option<IconPainter>,
wrap_mode: Option<TextWrapMode>, wrap_mode: Option<TextWrapMode>,
close_behavior: Option<PopupCloseBehavior>, close_behavior: Option<PopupCloseBehavior>,
popup_style: StyleModifier,
(width, height): (Option<f32>, Option<f32>), (width, height): (Option<f32>, Option<f32>),
) -> InnerResponse<Option<R>> { ) -> InnerResponse<Option<R>> {
let popup_id = ComboBox::widget_to_popup_id(button_id); 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) let inner = Popup::menu(&button_response)
.id(popup_id) .id(popup_id)
.style(StyleModifier::default())
.width(button_response.rect.width()) .width(button_response.rect.width())
.close_behavior(close_behavior) .close_behavior(close_behavior)
.style(popup_style)
.show(|ui| { .show(|ui| {
ui.set_min_width(ui.available_width()); ui.set_min_width(ui.available_width());

View File

@ -500,6 +500,7 @@ impl<'a> Popup<'a> {
} }
/// Show the popup. /// Show the popup.
///
/// Returns `None` if the popup is not open or anchor is `PopupAnchor::Pointer` and there is /// Returns `None` if the popup is not open or anchor is `PopupAnchor::Pointer` and there is
/// no pointer. /// no pointer.
pub fn show<R>(self, content: impl FnOnce(&mut Ui) -> R) -> Option<InnerResponse<R>> { pub fn show<R>(self, content: impl FnOnce(&mut Ui) -> R) -> Option<InnerResponse<R>> {