From 355934ddc1dae9d29a786ace430e01f149714e2e Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 25 Dec 2020 15:29:00 +0100 Subject: [PATCH] Add helpers ui.set_width and ui.set_width_range --- egui/src/containers/combo_box.rs | 4 +--- egui/src/ui.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/egui/src/containers/combo_box.rs b/egui/src/containers/combo_box.rs index 5d34e7d7..248f723f 100644 --- a/egui/src/containers/combo_box.rs +++ b/egui/src/containers/combo_box.rs @@ -63,9 +63,7 @@ pub fn combo_box( let frame_margin = frame.margin; frame.show(ui, |ui| { ui.with_layout(Layout::top_down_justified(Align::left()), |ui| { - let width = button_response.rect.width() - 2.0 * frame_margin.x; - ui.set_min_width(width); - ui.set_max_width(width); + ui.set_width(button_response.rect.width() - 2.0 * frame_margin.x); ScrollArea::from_max_height(MAX_COMBO_HEIGHT).show(ui, menu_contents); }); }); diff --git a/egui/src/ui.rs b/egui/src/ui.rs index be4da4c2..3968191a 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -301,6 +301,18 @@ impl Ui { self.region.expand_to_include_rect(rect); } + /// `ui.set_width_range(min..=max);` is equivalent to `ui.set_min_width(min); ui.set_max_width(max);`. + pub fn set_width_range(&mut self, width: std::ops::RangeInclusive) { + self.set_min_width(*width.start()); + self.set_max_width(*width.end()); + } + + /// `ui.set_width_range(width);` is equivalent to `ui.set_min_width(width); ui.set_max_width(width);`. + pub fn set_width(&mut self, width: f32) { + self.set_min_width(width); + self.set_max_width(width); + } + // ------------------------------------------------------------------------ // Layout related measures: