Skip to content

Commit

Permalink
Add generic return values to egui::Sides::show() (#5065)
Browse files Browse the repository at this point in the history
This addresses this comment:
- rerun-io/rerun#7344 (comment)


* [x] I have followed the instructions in the PR template
  • Loading branch information
abey79 authored Sep 3, 2024
1 parent b943554 commit 454abf7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions crates/egui/src/containers/sides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,30 @@ 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);

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(
UiBuilder::new()
.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()
};

Expand All @@ -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()
};

Expand All @@ -116,5 +119,7 @@ impl Sides {
}

ui.advance_cursor_after_rect(final_rect);

(result_left, result_right)
}
}

0 comments on commit 454abf7

Please sign in to comment.