`ComboBox`: add builder method for height (#3001)
Matches the already existing `ComboBox::width()`. --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
parent
5d2e192927
commit
c3bc4e26b0
|
|
@ -2,6 +2,9 @@ use epaint::Shape;
|
||||||
|
|
||||||
use crate::{style::WidgetVisuals, *};
|
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.
|
/// Indicate whether or not a popup will be shown above or below the box.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum AboveOrBelow {
|
pub enum AboveOrBelow {
|
||||||
|
|
@ -35,6 +38,7 @@ pub struct ComboBox {
|
||||||
label: Option<WidgetText>,
|
label: Option<WidgetText>,
|
||||||
selected_text: WidgetText,
|
selected_text: WidgetText,
|
||||||
width: Option<f32>,
|
width: Option<f32>,
|
||||||
|
height: Option<f32>,
|
||||||
icon: Option<IconPainter>,
|
icon: Option<IconPainter>,
|
||||||
wrap_enabled: bool,
|
wrap_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
@ -47,6 +51,7 @@ impl ComboBox {
|
||||||
label: Some(label.into()),
|
label: Some(label.into()),
|
||||||
selected_text: Default::default(),
|
selected_text: Default::default(),
|
||||||
width: None,
|
width: None,
|
||||||
|
height: None,
|
||||||
icon: None,
|
icon: None,
|
||||||
wrap_enabled: false,
|
wrap_enabled: false,
|
||||||
}
|
}
|
||||||
|
|
@ -60,6 +65,7 @@ impl ComboBox {
|
||||||
label: Some(label),
|
label: Some(label),
|
||||||
selected_text: Default::default(),
|
selected_text: Default::default(),
|
||||||
width: None,
|
width: None,
|
||||||
|
height: None,
|
||||||
icon: None,
|
icon: None,
|
||||||
wrap_enabled: false,
|
wrap_enabled: false,
|
||||||
}
|
}
|
||||||
|
|
@ -72,18 +78,30 @@ impl ComboBox {
|
||||||
label: Default::default(),
|
label: Default::default(),
|
||||||
selected_text: Default::default(),
|
selected_text: Default::default(),
|
||||||
width: None,
|
width: None,
|
||||||
|
height: None,
|
||||||
icon: None,
|
icon: None,
|
||||||
wrap_enabled: false,
|
wrap_enabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the outer width of the button and menu.
|
/// Set the outer width of the button and menu.
|
||||||
|
///
|
||||||
|
/// Default is [`Spacing::combo_width`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn width(mut self, width: f32) -> Self {
|
pub fn width(mut self, width: f32) -> Self {
|
||||||
self.width = Some(width);
|
self.width = Some(width);
|
||||||
self
|
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
|
/// What we show as the currently selected value
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn selected_text(mut self, selected_text: impl Into<WidgetText>) -> Self {
|
pub fn selected_text(mut self, selected_text: impl Into<WidgetText>) -> Self {
|
||||||
|
|
@ -158,6 +176,7 @@ impl ComboBox {
|
||||||
label,
|
label,
|
||||||
selected_text,
|
selected_text,
|
||||||
width,
|
width,
|
||||||
|
height,
|
||||||
icon,
|
icon,
|
||||||
wrap_enabled,
|
wrap_enabled,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
@ -172,7 +191,7 @@ impl ComboBox {
|
||||||
menu_contents,
|
menu_contents,
|
||||||
icon,
|
icon,
|
||||||
wrap_enabled,
|
wrap_enabled,
|
||||||
width,
|
(width, height),
|
||||||
);
|
);
|
||||||
if let Some(label) = label {
|
if let Some(label) = label {
|
||||||
ir.response
|
ir.response
|
||||||
|
|
@ -241,7 +260,7 @@ fn combo_box_dyn<'c, R>(
|
||||||
menu_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
menu_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||||
icon: Option<IconPainter>,
|
icon: Option<IconPainter>,
|
||||||
wrap_enabled: bool,
|
wrap_enabled: bool,
|
||||||
width: Option<f32>,
|
(width, height): (Option<f32>, Option<f32>),
|
||||||
) -> InnerResponse<Option<R>> {
|
) -> InnerResponse<Option<R>> {
|
||||||
let popup_id = button_id.with("popup");
|
let popup_id = button_id.with("popup");
|
||||||
|
|
||||||
|
|
@ -335,6 +354,9 @@ fn combo_box_dyn<'c, R>(
|
||||||
if button_response.clicked() {
|
if button_response.clicked() {
|
||||||
ui.memory_mut(|mem| mem.toggle_popup(popup_id));
|
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(
|
let inner = crate::popup::popup_above_or_below_widget(
|
||||||
ui,
|
ui,
|
||||||
popup_id,
|
popup_id,
|
||||||
|
|
@ -342,7 +364,7 @@ fn combo_box_dyn<'c, R>(
|
||||||
above_or_below,
|
above_or_below,
|
||||||
|ui| {
|
|ui| {
|
||||||
ScrollArea::vertical()
|
ScrollArea::vertical()
|
||||||
.max_height(ui.spacing().combo_height)
|
.max_height(height)
|
||||||
.show(ui, menu_contents)
|
.show(ui, menu_contents)
|
||||||
.inner
|
.inner
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue