Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComboBox: add builder method for height #3001

Merged
merged 11 commits into from
Jan 15, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG
* Add `char_limit` to `TextEdit` singleline mode to limit the amount of characters
* ⚠️ BREAKING: `Plot::link_axis` and `Plot::link_cursor` now take the name of the group ([#2410](https://github.com/emilk/egui/pull/2410)).
* Update `Plot::allow_zoom` and `Plot::allow_drag` to allow setting those values for X and Y axes independently ([#2901](https://github.com/emilk/egui/pull/2901)).
* Add `ComboBox::height` to allow setting the outer height of the pop-up ui ([#3001](https://github.com/emilk/egui/pull/3001)).

## 0.21.0 - 2023-02-08 - Deadlock fix and style customizability
* ⚠️ BREAKING: `egui::Context` now use closures for locking ([#2625](https://github.com/emilk/egui/pull/2625)):
Expand Down
18 changes: 17 additions & 1 deletion crates/egui/src/containers/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct ComboBox {
label: Option<WidgetText>,
selected_text: WidgetText,
width: Option<f32>,
height: Option<f32>,
icon: Option<IconPainter>,
wrap_enabled: bool,
}
Expand All @@ -47,6 +48,7 @@ impl ComboBox {
label: Some(label.into()),
selected_text: Default::default(),
width: None,
height: None,
icon: None,
wrap_enabled: false,
}
Expand All @@ -60,6 +62,7 @@ impl ComboBox {
label: Some(label),
selected_text: Default::default(),
width: None,
height: None,
icon: None,
wrap_enabled: false,
}
Expand All @@ -72,6 +75,7 @@ impl ComboBox {
label: Default::default(),
selected_text: Default::default(),
width: None,
height: None,
icon: None,
wrap_enabled: false,
}
Expand All @@ -83,6 +87,12 @@ impl ComboBox {
self
}

/// Set the outer height of the button and menu.
hinto-janai marked this conversation as resolved.
Show resolved Hide resolved
hinto-janai marked this conversation as resolved.
Show resolved Hide resolved
pub fn height(mut self, height: f32) -> Self {
self.height = Some(height);
self
}

/// What we show as the currently selected value
pub fn selected_text(mut self, selected_text: impl Into<WidgetText>) -> Self {
self.selected_text = selected_text.into();
Expand Down Expand Up @@ -155,6 +165,7 @@ impl ComboBox {
label,
selected_text,
width,
height,
icon,
wrap_enabled,
} = self;
Expand All @@ -170,6 +181,7 @@ impl ComboBox {
icon,
wrap_enabled,
width,
height,
);
if let Some(label) = label {
ir.response
Expand Down Expand Up @@ -239,6 +251,7 @@ fn combo_box_dyn<'c, R>(
icon: Option<IconPainter>,
wrap_enabled: bool,
width: Option<f32>,
height: Option<f32>,
) -> InnerResponse<Option<R>> {
let popup_id = button_id.with("popup");

Expand Down Expand Up @@ -331,14 +344,17 @@ 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,
&button_response,
above_or_below,
|ui| {
ScrollArea::vertical()
.max_height(ui.spacing().combo_height)
.max_height(height)
.show(ui, menu_contents)
.inner
},
Expand Down