add ui.horizontal_centered helper
This commit is contained in:
parent
7b75bd2d09
commit
d4c0197752
5 changed files with 9 additions and 4 deletions
|
@ -596,7 +596,7 @@ fn show_title_bar(
|
||||||
collapsing: &mut collapsing_header::State,
|
collapsing: &mut collapsing_header::State,
|
||||||
collapsible: bool,
|
collapsible: bool,
|
||||||
) -> TitleBar {
|
) -> TitleBar {
|
||||||
let title_bar_and_rect = ui.inner_layout(Layout::horizontal(Align::Center), |ui| {
|
let title_bar_and_rect = ui.horizontal_centered(|ui| {
|
||||||
ui.set_desired_height(title_label.font_height(ui.fonts()));
|
ui.set_desired_height(title_label.font_height(ui.fonts()));
|
||||||
|
|
||||||
let item_spacing = ui.style().item_spacing;
|
let item_spacing = ui.style().item_spacing;
|
||||||
|
|
|
@ -452,7 +452,7 @@ impl Widgets {
|
||||||
|
|
||||||
ui.add(Checkbox::new(&mut self.button_enabled, "Button enabled"));
|
ui.add(Checkbox::new(&mut self.button_enabled, "Button enabled"));
|
||||||
|
|
||||||
ui.inner_layout(Layout::horizontal(Align::Center), |ui| {
|
ui.horizontal_centered(|ui| {
|
||||||
if ui
|
if ui
|
||||||
.add(Button::new("Click me").enabled(self.button_enabled))
|
.add(Button::new("Click me").enabled(self.button_enabled))
|
||||||
.tooltip_text("This will just increase a counter.")
|
.tooltip_text("This will just increase a counter.")
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl BarState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
|
pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
|
||||||
ui.inner_layout(Layout::horizontal(Align::Center), |ui| {
|
ui.horizontal_centered(|ui| {
|
||||||
Frame::menu_bar(ui.style()).show(ui, |ui| {
|
Frame::menu_bar(ui.style()).show(ui, |ui| {
|
||||||
let mut style = ui.style().clone();
|
let mut style = ui.style().clone();
|
||||||
style.button_padding = vec2(2.0, 0.0);
|
style.button_padding = vec2(2.0, 0.0);
|
||||||
|
|
|
@ -604,6 +604,11 @@ impl Ui {
|
||||||
self.inner_layout(Layout::horizontal(Align::Min), add_contents)
|
self.inner_layout(Layout::horizontal(Align::Min), add_contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Start a ui with horizontal layout where elements are centered on the Y axis.
|
||||||
|
pub fn horizontal_centered<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
|
||||||
|
self.inner_layout(Layout::horizontal(Align::Center), add_contents)
|
||||||
|
}
|
||||||
|
|
||||||
/// Start a ui with vertical layout
|
/// Start a ui with vertical layout
|
||||||
pub fn vertical<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
|
pub fn vertical<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) {
|
||||||
self.inner_layout(Layout::vertical(Align::Min), add_contents)
|
self.inner_layout(Layout::vertical(Align::Min), add_contents)
|
||||||
|
|
|
@ -271,7 +271,7 @@ impl<'a> Widget for Slider<'a> {
|
||||||
// Place the text in line with the slider on the left:
|
// Place the text in line with the slider on the left:
|
||||||
let text_ui = &mut columns[1];
|
let text_ui = &mut columns[1];
|
||||||
text_ui.set_desired_height(slider_interact.rect.height());
|
text_ui.set_desired_height(slider_interact.rect.height());
|
||||||
text_ui.inner_layout(Layout::horizontal(Align::Center), |ui| {
|
text_ui.horizontal_centered(|ui| {
|
||||||
self.text_ui(ui, x_range);
|
self.text_ui(ui, x_range);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue