Add `ComboBox::popup_style` (#7360)
* Closes #7349 * [x] I have followed the instructions in the PR template
This commit is contained in:
parent
a1e5501db8
commit
3aee525755
|
|
@ -44,6 +44,7 @@ pub struct ComboBox {
|
|||
icon: Option<IconPainter>,
|
||||
wrap_mode: Option<TextWrapMode>,
|
||||
close_behavior: Option<PopupCloseBehavior>,
|
||||
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<IconPainter>,
|
||||
wrap_mode: Option<TextWrapMode>,
|
||||
close_behavior: Option<PopupCloseBehavior>,
|
||||
popup_style: StyleModifier,
|
||||
(width, height): (Option<f32>, Option<f32>),
|
||||
) -> InnerResponse<Option<R>> {
|
||||
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());
|
||||
|
||||
|
|
|
|||
|
|
@ -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<R>(self, content: impl FnOnce(&mut Ui) -> R) -> Option<InnerResponse<R>> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue