Add ui.vertical_centered and ui.vertical_centered_justified

This commit is contained in:
Emil Ernerfeldt 2020-12-15 14:26:28 +01:00
parent 273d466f19
commit b508f931c2
2 changed files with 24 additions and 0 deletions

View file

@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased ## Unreleased
### Added ⭐
* `ui.vertical_centered` and `ui.vertical_centered_justified`
### Changed 🔧 ### Changed 🔧
* `ui.image` now takes `impl Into<Vec2>` as a `size` argument * `ui.image` now takes `impl Into<Vec2>` as a `size` argument

View file

@ -963,6 +963,26 @@ impl Ui {
self.with_layout(Layout::top_down(Align::Min), add_contents) self.with_layout(Layout::top_down(Align::Min), add_contents)
} }
/// Start a ui with vertical layout.
/// Widgets will be centered.
pub fn vertical_centered<R>(
&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<R>(
&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<R>( pub fn with_layout<R>(
&mut self, &mut self,
layout: Layout, layout: Layout,