1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 14:50:03 -04:00

Add ui.centered

This commit is contained in:
Emil Ernerfeldt
2022-11-08 01:07:51 +01:00
parent c3edc1b88e
commit 5515d2db77
3 changed files with 21 additions and 1 deletions

View File

@@ -196,7 +196,7 @@ impl Layout {
}
}
/// Top-down layout justifed so that buttons etc fill the full available width.
/// Top-down layout justified so that buttons etc fill the full available width.
#[inline(always)]
pub fn top_down_justified(halign: Align) -> Self {
Self::top_down(halign).with_cross_justify(true)
@@ -229,6 +229,20 @@ impl Layout {
}
}
/// For when you want to add a single widget to a layout, and that widget
/// should be centered horizontally and vertically.
#[inline(always)]
pub fn centered(main_dir: Direction) -> Self {
Self {
main_dir,
main_wrap: false,
main_align: Align::Center,
main_justify: false,
cross_align: Align::Center,
cross_justify: false,
}
}
/// For when you want to add a single widget to a layout, and that widget
/// should use up all available space.
#[inline(always)]

View File

@@ -2007,6 +2007,11 @@ impl Ui {
InnerResponse::new(inner, self.interact(rect, child_ui.id, Sense::hover()))
}
/// This will make the next added widget centered in the available space.
pub fn centered<R>(&mut self, add_contents: impl FnOnce(&mut Self) -> R) -> InnerResponse<R> {
self.with_layout_dyn(Layout::centered(Direction::TopDown), Box::new(add_contents))
}
/// This will make the next added widget centered and justified in the available space.
pub fn centered_and_justified<R>(
&mut self,