Skip to content

Commit

Permalink
Add ui.horizontal_centered
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Apr 11, 2022
1 parent 772ef84 commit 0e0eedf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,21 @@ impl Ui {
self.horizontal_with_main_wrap_dyn(false, Box::new(add_contents))
}

/// Like [`Self::horizontal`], but allocates the full vertical height and then centers elements vertically.
pub fn horizontal_centered<R>(
&mut self,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
let initial_size = self.available_size_before_wrap();
let layout = if self.placer.prefer_right_to_left() {
Layout::right_to_left()
} else {
Layout::left_to_right()
}
.with_cross_align(Align::Center);
self.allocate_ui_with_layout_dyn(initial_size, layout, Box::new(add_contents))
}

/// Like [`Self::horizontal`], but aligns content with top.
pub fn horizontal_top<R>(
&mut self,
Expand Down

0 comments on commit 0e0eedf

Please sign in to comment.