Add ui.group(|ui| { … }) to visually group some widgets within a frame

This commit is contained in:
Emil Ernerfeldt 2021-02-03 00:25:07 +01:00
parent ca886ea998
commit 829455b347
4 changed files with 9 additions and 5 deletions

View file

@ -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 🔧

View file

@ -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()

View file

@ -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<R>(&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<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Response) {
let child_rect = self.available_rect_before_wrap();

View file

@ -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");