diff --git a/egui/src/containers/frame.rs b/egui/src/containers/frame.rs index 4a725f4f..e655c0ea 100644 --- a/egui/src/containers/frame.rs +++ b/egui/src/containers/frame.rs @@ -134,11 +134,11 @@ impl Frame { } } - pub fn show(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> R { + pub fn show(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse { let mut prepared = self.begin(ui); let ret = add_contents(&mut prepared.content_ui); - prepared.end(ui); - ret + let response = prepared.end(ui); + InnerResponse::new(ret, response) } pub fn paint(&self, outer_rect: Rect) -> Shape { @@ -175,7 +175,7 @@ impl Prepared { ) } - pub fn end(self, ui: &mut Ui) -> Rect { + pub fn end(self, ui: &mut Ui) -> Response { let outer_rect = self.outer_rect(); let Prepared { @@ -186,7 +186,6 @@ impl Prepared { let shape = frame.paint(outer_rect); ui.painter().set(where_to_put_background, shape); - ui.advance_cursor_after_rect(outer_rect); - outer_rect + ui.allocate_rect(outer_rect, Sense::hover()) } } diff --git a/egui/src/containers/panel.rs b/egui/src/containers/panel.rs index e08744e8..cb7070ac 100644 --- a/egui/src/containers/panel.rs +++ b/egui/src/containers/panel.rs @@ -51,21 +51,16 @@ impl SidePanel { let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect); let frame = Frame::side_top_panel(&ctx.style()); - let (r, used_space) = frame.show(&mut panel_ui, |ui| { - let r = add_contents(ui); - let used_space = ui.min_rect(); + let inner_response = frame.show(&mut panel_ui, |ui| { ui.set_min_height(ui.max_rect_finite().height()); // Make sure the frame fills the full height - (r, used_space) + add_contents(ui) }); - let panel_rect = panel_ui.min_rect(); - let response = panel_ui.interact(panel_rect, id, Sense::hover()); - // Only inform ctx about what we actually used, so we can shrink the native window to fit. ctx.frame_state() - .allocate_left_panel(used_space.expand2(frame.margin)); + .allocate_left_panel(inner_response.response.rect); - InnerResponse::new(r, response) + inner_response } } @@ -118,21 +113,16 @@ impl TopPanel { let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect); let frame = Frame::side_top_panel(&ctx.style()); - let (r, used_space) = frame.show(&mut panel_ui, |ui| { - let r = add_contents(ui); - let used_space = ui.min_rect(); + let inner_response = frame.show(&mut panel_ui, |ui| { ui.set_min_width(ui.max_rect_finite().width()); // Make the frame fill full width - (r, used_space) + add_contents(ui) }); - let panel_rect = panel_ui.min_rect(); - let response = panel_ui.interact(panel_rect, id, Sense::hover()); - // Only inform ctx about what we actually used, so we can shrink the native window to fit. ctx.frame_state() - .allocate_top_panel(used_space.expand2(frame.margin)); + .allocate_top_panel(inner_response.response.rect); - InnerResponse::new(r, response) + inner_response } } @@ -182,21 +172,15 @@ impl CentralPanel { let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect); let frame = frame.unwrap_or_else(|| Frame::central_panel(&ctx.style())); - let (r, used_space) = frame.show(&mut panel_ui, |ui| { - let r = add_contents(ui); - let used_space = ui.min_rect(); + let inner_response = frame.show(&mut panel_ui, |ui| { ui.expand_to_include_rect(ui.max_rect()); // Expand frame to include it all - (r, used_space) + add_contents(ui) }); - let panel_rect = panel_ui.min_rect(); - let id = Id::new("central_panel"); - let response = panel_ui.interact(panel_rect, id, Sense::hover()); - // Only inform ctx about what we actually used, so we can shrink the native window to fit. ctx.frame_state() - .allocate_central_panel(used_space.expand2(frame.margin)); + .allocate_central_panel(inner_response.response.rect); - InnerResponse::new(r, response) + inner_response } } diff --git a/egui/src/containers/popup.rs b/egui/src/containers/popup.rs index 036d1a60..96c46a0f 100644 --- a/egui/src/containers/popup.rs +++ b/egui/src/containers/popup.rs @@ -139,7 +139,7 @@ fn show_tooltip_area( Frame::popup(&ctx.style()).show(ui, |ui| { ui.set_max_width(ui.spacing().tooltip_width); add_contents(ui); - }) + }); }) } diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index 32374814..496ed213 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -343,7 +343,7 @@ impl<'open> Window<'open> { }) .map(|ir| ir.response); - let outer_rect = frame.end(&mut area_content_ui); + let outer_rect = frame.end(&mut area_content_ui).rect; if possible.resizable { paint_resize_corner(&mut area_content_ui, outer_rect, frame_stroke); diff --git a/egui/src/grid.rs b/egui/src/grid.rs index 060171d8..213bd6c7 100644 --- a/egui/src/grid.rs +++ b/egui/src/grid.rs @@ -305,7 +305,7 @@ impl Grid { } impl Grid { - pub fn show(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> R { + pub fn show(self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse { let Self { id_source, striped, @@ -337,6 +337,5 @@ impl Grid { ui.save_grid(); r }) - .inner } } diff --git a/egui/src/menu.rs b/egui/src/menu.rs index d169b4dd..5b5bbecc 100644 --- a/egui/src/menu.rs +++ b/egui/src/menu.rs @@ -113,7 +113,7 @@ fn menu_impl<'c>( style.visuals.widgets.inactive.bg_stroke = Stroke::none(); ui.set_style(style); ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents); - }) + }); }); // TODO: this prevents sub-menus in menus. We should fix that. diff --git a/egui/src/ui.rs b/egui/src/ui.rs index c0c22843..dc7253c5 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -1121,7 +1121,7 @@ impl Ui { /// ui.label("Within a frame"); /// }); /// ``` - pub fn group(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> R { + pub fn group(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse { crate::Frame::group(self.style()).show(self, add_contents) } diff --git a/egui/src/widgets/color_picker.rs b/egui/src/widgets/color_picker.rs index 1c87035d..9796cabc 100644 --- a/egui/src/widgets/color_picker.rs +++ b/egui/src/widgets/color_picker.rs @@ -347,7 +347,7 @@ pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> Res if color_picker_hsva_2d(ui, hsva, alpha) { button_response.mark_changed(); } - }) + }); }); if !button_response.clicked()