From b508f931c267cb4c4435381826fdd45329d6238c Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 15 Dec 2020 14:26:28 +0100 Subject: [PATCH] Add ui.vertical_centered and ui.vertical_centered_justified --- CHANGELOG.md | 4 ++++ egui/src/ui.rs | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 435716bc..408402e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased +### Added ⭐ + +* `ui.vertical_centered` and `ui.vertical_centered_justified` + ### Changed 🔧 * `ui.image` now takes `impl Into` as a `size` argument diff --git a/egui/src/ui.rs b/egui/src/ui.rs index db4ded28..2fd7ab3c 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -963,6 +963,26 @@ impl Ui { self.with_layout(Layout::top_down(Align::Min), add_contents) } + /// Start a ui with vertical layout. + /// Widgets will be centered. + pub fn vertical_centered( + &mut self, + add_contents: impl FnOnce(&mut Ui) -> R, + ) -> (R, Response) { + self.with_layout(Layout::top_down(Align::Center), add_contents) + } + /// Start a ui with vertical layout. + /// Widgets will be centered and justified (fill full width). + pub fn vertical_centered_justified( + &mut self, + add_contents: impl FnOnce(&mut Ui) -> R, + ) -> (R, Response) { + self.with_layout( + Layout::top_down(Align::Center).with_cross_justify(true), + add_contents, + ) + } + pub fn with_layout( &mut self, layout: Layout,