diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index 70ed046b396..44950924724 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -2,6 +2,9 @@ use epaint::Shape; use crate::{style::WidgetVisuals, *}; +#[allow(unused_imports)] // Documentation +use crate::style::Spacing; + /// Indicate whether or not a popup will be shown above or below the box. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum AboveOrBelow { @@ -35,6 +38,7 @@ pub struct ComboBox { label: Option, selected_text: WidgetText, width: Option, + height: Option, icon: Option, wrap_enabled: bool, } @@ -47,6 +51,7 @@ impl ComboBox { label: Some(label.into()), selected_text: Default::default(), width: None, + height: None, icon: None, wrap_enabled: false, } @@ -60,6 +65,7 @@ impl ComboBox { label: Some(label), selected_text: Default::default(), width: None, + height: None, icon: None, wrap_enabled: false, } @@ -72,18 +78,30 @@ impl ComboBox { label: Default::default(), selected_text: Default::default(), width: None, + height: None, icon: None, wrap_enabled: false, } } /// Set the outer width of the button and menu. + /// + /// Default is [`Spacing::combo_width`]. #[inline] pub fn width(mut self, width: f32) -> Self { self.width = Some(width); self } + /// Set the maximum outer height of the menu. + /// + /// Default is [`Spacing::combo_height`]. + #[inline] + pub fn height(mut self, height: f32) -> Self { + self.height = Some(height); + self + } + /// What we show as the currently selected value #[inline] pub fn selected_text(mut self, selected_text: impl Into) -> Self { @@ -158,6 +176,7 @@ impl ComboBox { label, selected_text, width, + height, icon, wrap_enabled, } = self; @@ -172,7 +191,7 @@ impl ComboBox { menu_contents, icon, wrap_enabled, - width, + (width, height), ); if let Some(label) = label { ir.response @@ -241,7 +260,7 @@ fn combo_box_dyn<'c, R>( menu_contents: Box R + 'c>, icon: Option, wrap_enabled: bool, - width: Option, + (width, height): (Option, Option), ) -> InnerResponse> { let popup_id = button_id.with("popup"); @@ -335,6 +354,9 @@ fn combo_box_dyn<'c, R>( if button_response.clicked() { ui.memory_mut(|mem| mem.toggle_popup(popup_id)); } + + let height = height.unwrap_or_else(|| ui.spacing().combo_height); + let inner = crate::popup::popup_above_or_below_widget( ui, popup_id, @@ -342,7 +364,7 @@ fn combo_box_dyn<'c, R>( above_or_below, |ui| { ScrollArea::vertical() - .max_height(ui.spacing().combo_height) + .max_height(height) .show(ui, menu_contents) .inner },