From 829455b347684a3c59af113f5322f1d4ae933272 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 3 Feb 2021 00:25:07 +0100 Subject: [PATCH] =?UTF-8?q?Add=20`ui.group(|ui|=20{=20=E2=80=A6=20})`=20to?= =?UTF-8?q?=20visually=20group=20some=20widgets=20within=20a=20frame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++- egui/src/containers/frame.rs | 2 +- egui/src/ui.rs | 5 +++++ egui_demo_lib/src/apps/demo/widgets.rs | 4 +--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b0883cf..2231efa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,9 +13,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Add support for secondary and middle mouse buttons. * Add `Label` methods for code, strong, strikethrough, underline and italics. +* Add `ui.group(|ui| { … })` to visually group some widgets within a frame +* Text will now wrap at newlines, spaces, dashes, punctuation or in the middle of a words if necessary, in that order of priority. * `egui::popup::popup_below_widget`: show a popup area below another widget. * Add `Slider::clamp_to_range(bool)`: if set, clamp the incoming and outgoing values to the slider range. -* Text will now wrap at newlines, spaces, dashes, punctuation or in the middle of a words if necessary, in that order of priority. * Add: `ui.spacing()`, `ui.spacing_mut()`, `ui.visuals()`, `ui.visuals_mut()`. ### Changed 🔧 diff --git a/egui/src/containers/frame.rs b/egui/src/containers/frame.rs index 2f3f25a8..a0833879 100644 --- a/egui/src/containers/frame.rs +++ b/egui/src/containers/frame.rs @@ -21,7 +21,7 @@ impl Frame { /// For when you want to group a few widgets together within a frame. pub fn group(style: &Style) -> Self { Self { - margin: Vec2::new(8.0, 8.0), + margin: Vec2::new(8.0, 6.0), corner_radius: 4.0, stroke: style.visuals.widgets.noninteractive.bg_stroke, ..Default::default() diff --git a/egui/src/ui.rs b/egui/src/ui.rs index ce71b00c..8bb8ea55 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -902,6 +902,11 @@ impl Ui { /// # Adding Containers / Sub-uis: impl Ui { + /// Put into a `Frame::group`, visually grouping the contents together + pub fn group(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> R { + crate::Frame::group(self.style()).show(self, add_contents) + } + /// Create a child ui. You can use this to temporarily change the Style of a sub-region, for instance. pub fn wrap(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Response) { let child_rect = self.available_rect_before_wrap(); diff --git a/egui_demo_lib/src/apps/demo/widgets.rs b/egui_demo_lib/src/apps/demo/widgets.rs index f077d435..2f08ac8a 100644 --- a/egui_demo_lib/src/apps/demo/widgets.rs +++ b/egui_demo_lib/src/apps/demo/widgets.rs @@ -77,9 +77,7 @@ impl Widgets { ui.label("Tooltips can be more than just simple text.") .on_hover_ui(tooltip_ui); - egui::Frame::group(ui.style()).show(ui, |ui| { - ui.label("This is a group of widgets"); - + ui.group(|ui| { ui.horizontal(|ui| { ui.radio_value(&mut self.radio, Enum::First, "First"); ui.radio_value(&mut self.radio, Enum::Second, "Second");