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:
parent
b9435541df
commit
454abf705b
|
|
@ -68,12 +68,12 @@ impl Sides {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show(
|
pub fn show<RetL, RetR>(
|
||||||
self,
|
self,
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
add_left: impl FnOnce(&mut Ui),
|
add_left: impl FnOnce(&mut Ui) -> RetL,
|
||||||
add_right: impl FnOnce(&mut Ui),
|
add_right: impl FnOnce(&mut Ui) -> RetR,
|
||||||
) {
|
) -> (RetL, RetR) {
|
||||||
let Self { height, spacing } = self;
|
let Self { height, spacing } = self;
|
||||||
let height = height.unwrap_or_else(|| ui.spacing().interact_size.y);
|
let height = height.unwrap_or_else(|| ui.spacing().interact_size.y);
|
||||||
let spacing = spacing.unwrap_or_else(|| ui.spacing().item_spacing.x);
|
let spacing = spacing.unwrap_or_else(|| ui.spacing().item_spacing.x);
|
||||||
|
|
@ -81,6 +81,9 @@ impl Sides {
|
||||||
let mut top_rect = ui.max_rect();
|
let mut top_rect = ui.max_rect();
|
||||||
top_rect.max.y = top_rect.min.y + height;
|
top_rect.max.y = top_rect.min.y + height;
|
||||||
|
|
||||||
|
let result_left;
|
||||||
|
let result_right;
|
||||||
|
|
||||||
let left_rect = {
|
let left_rect = {
|
||||||
let left_max_rect = top_rect;
|
let left_max_rect = top_rect;
|
||||||
let mut left_ui = ui.new_child(
|
let mut left_ui = ui.new_child(
|
||||||
|
|
@ -88,7 +91,7 @@ impl Sides {
|
||||||
.max_rect(left_max_rect)
|
.max_rect(left_max_rect)
|
||||||
.layout(Layout::left_to_right(Align::Center)),
|
.layout(Layout::left_to_right(Align::Center)),
|
||||||
);
|
);
|
||||||
add_left(&mut left_ui);
|
result_left = add_left(&mut left_ui);
|
||||||
left_ui.min_rect()
|
left_ui.min_rect()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -99,7 +102,7 @@ impl Sides {
|
||||||
.max_rect(right_max_rect)
|
.max_rect(right_max_rect)
|
||||||
.layout(Layout::right_to_left(Align::Center)),
|
.layout(Layout::right_to_left(Align::Center)),
|
||||||
);
|
);
|
||||||
add_right(&mut right_ui);
|
result_right = add_right(&mut right_ui);
|
||||||
right_ui.min_rect()
|
right_ui.min_rect()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -116,5 +119,7 @@ impl Sides {
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.advance_cursor_after_rect(final_rect);
|
ui.advance_cursor_after_rect(final_rect);
|
||||||
|
|
||||||
|
(result_left, result_right)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue