Skip to content

Commit 1afbb97

Browse files
lucasmerlinemilk
authored andcommitted
Add ComboBox::popup_style (#7360)
* Closes #7349 * [x] I have followed the instructions in the PR template
1 parent 85c4b1d commit 1afbb97

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

crates/egui/src/containers/combo_box.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct ComboBox {
4444
icon: Option<IconPainter>,
4545
wrap_mode: Option<TextWrapMode>,
4646
close_behavior: Option<PopupCloseBehavior>,
47+
popup_style: StyleModifier,
4748
}
4849

4950
impl ComboBox {
@@ -58,6 +59,7 @@ impl ComboBox {
5859
icon: None,
5960
wrap_mode: None,
6061
close_behavior: None,
62+
popup_style: StyleModifier::default(),
6163
}
6264
}
6365

@@ -73,6 +75,7 @@ impl ComboBox {
7375
icon: None,
7476
wrap_mode: None,
7577
close_behavior: None,
78+
popup_style: StyleModifier::default(),
7679
}
7780
}
7881

@@ -87,6 +90,7 @@ impl ComboBox {
8790
icon: None,
8891
wrap_mode: None,
8992
close_behavior: None,
93+
popup_style: StyleModifier::default(),
9094
}
9195
}
9296

@@ -191,6 +195,16 @@ impl ComboBox {
191195
self
192196
}
193197

198+
/// Set the style of the popup menu.
199+
///
200+
/// Could for example be used with [`crate::containers::menu::menu_style`] to get the frame-less
201+
/// menu button style.
202+
#[inline]
203+
pub fn popup_style(mut self, popup_style: StyleModifier) -> Self {
204+
self.popup_style = popup_style;
205+
self
206+
}
207+
194208
/// Show the combo box, with the given ui code for the menu contents.
195209
///
196210
/// Returns `InnerResponse { inner: None }` if the combo box is closed.
@@ -216,6 +230,7 @@ impl ComboBox {
216230
icon,
217231
wrap_mode,
218232
close_behavior,
233+
popup_style,
219234
} = self;
220235

221236
let button_id = ui.make_persistent_id(id_salt);
@@ -229,6 +244,7 @@ impl ComboBox {
229244
icon,
230245
wrap_mode,
231246
close_behavior,
247+
popup_style,
232248
(width, height),
233249
);
234250
if let Some(label) = label {
@@ -311,6 +327,7 @@ fn combo_box_dyn<'c, R>(
311327
icon: Option<IconPainter>,
312328
wrap_mode: Option<TextWrapMode>,
313329
close_behavior: Option<PopupCloseBehavior>,
330+
popup_style: StyleModifier,
314331
(width, height): (Option<f32>, Option<f32>),
315332
) -> InnerResponse<Option<R>> {
316333
let popup_id = ComboBox::widget_to_popup_id(button_id);
@@ -379,9 +396,9 @@ fn combo_box_dyn<'c, R>(
379396

380397
let inner = Popup::menu(&button_response)
381398
.id(popup_id)
382-
.style(StyleModifier::default())
383399
.width(button_response.rect.width())
384400
.close_behavior(close_behavior)
401+
.style(popup_style)
385402
.show(|ui| {
386403
ui.set_min_width(ui.available_width());
387404

crates/egui/src/containers/popup.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ impl<'a> Popup<'a> {
500500
}
501501

502502
/// Show the popup.
503+
///
503504
/// Returns `None` if the popup is not open or anchor is `PopupAnchor::Pointer` and there is
504505
/// no pointer.
505506
pub fn show<R>(self, content: impl FnOnce(&mut Ui) -> R) -> Option<InnerResponse<R>> {

0 commit comments

Comments
 (0)