From 454abf705b87aba70cef582d6ce80f74aa398906 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler <49431240+abey79@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:25:22 +0200 Subject: [PATCH] Add generic return values to `egui::Sides::show()` (#5065) This addresses this comment: - https://github.com/rerun-io/rerun/pull/7344#discussion_r1742140870 * [x] I have followed the instructions in the PR template --- crates/egui/src/containers/sides.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/egui/src/containers/sides.rs b/crates/egui/src/containers/sides.rs index 4dd517f8751..3bc353380d0 100644 --- a/crates/egui/src/containers/sides.rs +++ b/crates/egui/src/containers/sides.rs @@ -68,12 +68,12 @@ impl Sides { self } - pub fn show( + pub fn show( self, ui: &mut Ui, - add_left: impl FnOnce(&mut Ui), - add_right: impl FnOnce(&mut Ui), - ) { + add_left: impl FnOnce(&mut Ui) -> RetL, + add_right: impl FnOnce(&mut Ui) -> RetR, + ) -> (RetL, RetR) { let Self { height, spacing } = self; let height = height.unwrap_or_else(|| ui.spacing().interact_size.y); let spacing = spacing.unwrap_or_else(|| ui.spacing().item_spacing.x); @@ -81,6 +81,9 @@ impl Sides { let mut top_rect = ui.max_rect(); top_rect.max.y = top_rect.min.y + height; + let result_left; + let result_right; + let left_rect = { let left_max_rect = top_rect; let mut left_ui = ui.new_child( @@ -88,7 +91,7 @@ impl Sides { .max_rect(left_max_rect) .layout(Layout::left_to_right(Align::Center)), ); - add_left(&mut left_ui); + result_left = add_left(&mut left_ui); left_ui.min_rect() }; @@ -99,7 +102,7 @@ impl Sides { .max_rect(right_max_rect) .layout(Layout::right_to_left(Align::Center)), ); - add_right(&mut right_ui); + result_right = add_right(&mut right_ui); right_ui.min_rect() }; @@ -116,5 +119,7 @@ impl Sides { } ui.advance_cursor_after_rect(final_rect); + + (result_left, result_right) } }