From 32d60619356d5a842389f29b2dc2f3155c63b6ad Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Thu, 18 May 2023 18:28:01 -0400 Subject: [PATCH 01/10] combo_box: add optional height --- crates/egui/src/containers/combo_box.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index 7bc12c7de77..6e2c8d816cf 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -35,6 +35,7 @@ pub struct ComboBox { label: Option, selected_text: WidgetText, width: Option, + height: Option, icon: Option, wrap_enabled: bool, } @@ -47,6 +48,7 @@ impl ComboBox { label: Some(label.into()), selected_text: Default::default(), width: None, + height: None, icon: None, wrap_enabled: false, } @@ -60,6 +62,7 @@ impl ComboBox { label: Some(label), selected_text: Default::default(), width: None, + height: None, icon: None, wrap_enabled: false, } @@ -72,6 +75,7 @@ impl ComboBox { label: Default::default(), selected_text: Default::default(), width: None, + height: None, icon: None, wrap_enabled: false, } @@ -83,6 +87,12 @@ impl ComboBox { self } + /// Set the outer height of the button and menu. + 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) -> Self { self.selected_text = selected_text.into(); @@ -155,6 +165,7 @@ impl ComboBox { label, selected_text, width, + height, icon, wrap_enabled, } = self; @@ -170,6 +181,7 @@ impl ComboBox { icon, wrap_enabled, width, + height, ); if let Some(label) = label { ir.response @@ -239,6 +251,7 @@ fn combo_box_dyn<'c, R>( icon: Option, wrap_enabled: bool, width: Option, + height: Option, ) -> InnerResponse> { let popup_id = button_id.with("popup"); @@ -331,6 +344,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, @@ -338,7 +354,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 }, From 5d067484e1aaeb312dfaf6441021d9975a5e85ea Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Thu, 18 May 2023 18:33:31 -0400 Subject: [PATCH 02/10] update `CHANGELOG.md` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 008bcda06c7..373166341fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)): From 225cf7e5d0a0077c1961b731aa6983ac62349ff1 Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Mon, 22 May 2023 23:27:14 +0000 Subject: [PATCH 03/10] Update crates/egui/src/containers/combo_box.rs Co-authored-by: Emil Ernerfeldt --- crates/egui/src/containers/combo_box.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index 6e2c8d816cf..f3d9a5aafcd 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -88,6 +88,8 @@ impl ComboBox { } /// Set the outer height of the button and menu. + /// + /// Default is [`Spacing::combo_height`]. pub fn height(mut self, height: f32) -> Self { self.height = Some(height); self From f9d70068c905230a8b17c18c32e47ac2261f6ca1 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Fri, 12 Jan 2024 10:19:40 -0500 Subject: [PATCH 04/10] add matching doc for `width()` --- crates/egui/src/containers/combo_box.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index 4fe7cb7e200..a8d9c5b8452 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -82,6 +82,8 @@ impl ComboBox { } /// 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); From 17b983542b28d384b2cd4e9fb56cc72bf98e9851 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Fri, 12 Jan 2024 10:23:01 -0500 Subject: [PATCH 05/10] add `#[inline]` for CI --- crates/egui/src/containers/combo_box.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index a8d9c5b8452..7a1d4e5dd11 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -93,6 +93,7 @@ impl ComboBox { /// Set the outer height of the button and menu. /// /// Default is [`Spacing::combo_height`]. + #[inline] pub fn height(mut self, height: f32) -> Self { self.height = Some(height); self From 4c7f5898df60a53e49a10d937ac27f400e34c2ab Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Fri, 12 Jan 2024 10:27:58 -0500 Subject: [PATCH 06/10] ci: fix `error: this function has too many arguments (8/7)` --- crates/egui/src/containers/combo_box.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index 7a1d4e5dd11..0c63f41aab6 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -188,8 +188,7 @@ impl ComboBox { menu_contents, icon, wrap_enabled, - width, - height, + (width, height), ); if let Some(label) = label { ir.response @@ -258,9 +257,10 @@ fn combo_box_dyn<'c, R>( menu_contents: Box R + 'c>, icon: Option, wrap_enabled: bool, - width: Option, - height: Option, + width_and_height: (Option, Option), ) -> InnerResponse> { + let (width, height) = width_and_height; + let popup_id = button_id.with("popup"); let is_popup_open = ui.memory(|m| m.is_popup_open(popup_id)); From 5875296b0ef714daea27efe1a25f49dc3ad00a9d Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Fri, 12 Jan 2024 10:29:53 -0500 Subject: [PATCH 07/10] rustfmt --- crates/egui/src/containers/combo_box.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index 0c63f41aab6..bb6a30cb6f8 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -259,7 +259,7 @@ fn combo_box_dyn<'c, R>( wrap_enabled: bool, width_and_height: (Option, Option), ) -> InnerResponse> { - let (width, height) = width_and_height; + let (width, height) = width_and_height; let popup_id = button_id.with("popup"); From 0ce294a2e1af7fb70db99da6aa679e889d5f6368 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Fri, 12 Jan 2024 10:32:29 -0500 Subject: [PATCH 08/10] add `use` for documentation linking --- crates/egui/src/containers/combo_box.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index bb6a30cb6f8..35f04de9175 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 { From bf745443b885ac32dcd5b92ad1a1de6519ce8ca5 Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Sun, 14 Jan 2024 22:04:45 -0500 Subject: [PATCH 09/10] Update crates/egui/src/containers/combo_box.rs Co-authored-by: Emil Ernerfeldt --- crates/egui/src/containers/combo_box.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index 35f04de9175..4a87ce281dd 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -260,10 +260,8 @@ fn combo_box_dyn<'c, R>( menu_contents: Box R + 'c>, icon: Option, wrap_enabled: bool, - width_and_height: (Option, Option), + (width, height): (Option, Option), ) -> InnerResponse> { - let (width, height) = width_and_height; - let popup_id = button_id.with("popup"); let is_popup_open = ui.memory(|m| m.is_popup_open(popup_id)); From b587f3454b9dc44d598bb0fe8ae6edc24639cbc9 Mon Sep 17 00:00:00 2001 From: hinto-janai Date: Sun, 14 Jan 2024 22:04:51 -0500 Subject: [PATCH 10/10] Update crates/egui/src/containers/combo_box.rs Co-authored-by: Emil Ernerfeldt --- crates/egui/src/containers/combo_box.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index 4a87ce281dd..44950924724 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -93,7 +93,7 @@ impl ComboBox { self } - /// Set the outer height of the button and menu. + /// Set the maximum outer height of the menu. /// /// Default is [`Spacing::combo_height`]. #[inline]