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
This commit is contained in:
Antoine Beyeler 2024-09-03 16:25:22 +02:00 committed by GitHub
parent b9435541df
commit 454abf705b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 6 deletions

View File

@ -68,12 +68,12 @@ impl Sides {
self
}
pub fn show(
pub fn show<RetL, RetR>(
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)
}
}