1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 22:30:03 -04:00

Layout::left_to_right/right_to_left now takes the valign as argument

Previous default was `Align::Center`.

Closes https://github.com/emilk/egui/issues/1040
Closes https://github.com/emilk/egui/issues/1836
Closes https://github.com/emilk/egui/pull/1837
This commit is contained in:
Emil Ernerfeldt
2022-07-22 11:02:26 +02:00
parent 9f1f0a9038
commit 41f31116ce
8 changed files with 29 additions and 29 deletions

View File

@@ -108,7 +108,7 @@ impl Direction {
///
/// ```
/// # egui::__run_test_ui(|ui| {
/// ui.with_layout(egui::Layout::right_to_left(), |ui| {
/// ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
/// ui.label("world!");
/// ui.label("Hello");
/// });
@@ -153,30 +153,30 @@ impl Default for Layout {
impl Layout {
/// Place elements horizontally, left to right.
///
/// Elements will be centered vertically.
/// The `valign` parameter controls how to align elements vertically.
#[inline(always)]
pub fn left_to_right() -> Self {
pub fn left_to_right(valing: Align) -> Self {
Self {
main_dir: Direction::LeftToRight,
main_wrap: false,
main_align: Align::Center, // looks best to e.g. center text within a button
main_justify: false,
cross_align: Align::Center,
cross_align: valing,
cross_justify: false,
}
}
/// Place elements horizontally, right to left.
///
/// Elements will be centered vertically.
/// The `valign` parameter controls how to align elements vertically.
#[inline(always)]
pub fn right_to_left() -> Self {
pub fn right_to_left(valing: Align) -> Self {
Self {
main_dir: Direction::RightToLeft,
main_wrap: false,
main_align: Align::Center, // looks best to e.g. center text within a button
main_justify: false,
cross_align: Align::Center,
cross_align: valing,
cross_justify: false,
}
}
@@ -185,34 +185,34 @@ impl Layout {
///
/// Use the provided horizontal alignmen.
#[inline(always)]
pub fn top_down(cross_align: Align) -> Self {
pub fn top_down(halign: Align) -> Self {
Self {
main_dir: Direction::TopDown,
main_wrap: false,
main_align: Align::Center, // looks best to e.g. center text within a button
main_justify: false,
cross_align,
cross_align: halign,
cross_justify: false,
}
}
/// Top-down layout justifed so that buttons etc fill the full available width.
#[inline(always)]
pub fn top_down_justified(cross_align: Align) -> Self {
Self::top_down(cross_align).with_cross_justify(true)
pub fn top_down_justified(halign: Align) -> Self {
Self::top_down(halign).with_cross_justify(true)
}
/// Place elements vertically, bottom up.
///
/// Use the provided horizontal alignmen.
#[inline(always)]
pub fn bottom_up(cross_align: Align) -> Self {
pub fn bottom_up(halign: Align) -> Self {
Self {
main_dir: Direction::BottomUp,
main_wrap: false,
main_align: Align::Center, // looks best to e.g. center text within a button
main_justify: false,
cross_align,
cross_align: halign,
cross_justify: false,
}
}

View File

@@ -1817,9 +1817,9 @@ impl Ui {
) -> InnerResponse<R> {
let initial_size = self.available_size_before_wrap();
let layout = if self.placer.prefer_right_to_left() {
Layout::right_to_left()
Layout::right_to_left(Align::Center)
} else {
Layout::left_to_right()
Layout::left_to_right(Align::Center)
}
.with_cross_align(Align::Center);
self.allocate_ui_with_layout_dyn(initial_size, layout, Box::new(add_contents))
@@ -1832,9 +1832,9 @@ impl Ui {
) -> InnerResponse<R> {
let initial_size = self.available_size_before_wrap();
let layout = if self.placer.prefer_right_to_left() {
Layout::right_to_left()
Layout::right_to_left(Align::Center)
} else {
Layout::left_to_right()
Layout::left_to_right(Align::Center)
}
.with_cross_align(Align::Min);
self.allocate_ui_with_layout_dyn(initial_size, layout, Box::new(add_contents))
@@ -1873,9 +1873,9 @@ impl Ui {
);
let layout = if self.placer.prefer_right_to_left() {
Layout::right_to_left()
Layout::right_to_left(Align::Center)
} else {
Layout::left_to_right()
Layout::left_to_right(Align::Center)
}
.with_main_wrap(main_wrap);
@@ -1944,15 +1944,16 @@ impl Ui {
///
/// ```
/// # egui::__run_test_ui(|ui| {
/// ui.with_layout(egui::Layout::right_to_left(), |ui| {
/// ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
/// ui.label("world!");
/// ui.label("Hello");
/// });
/// # });
/// ```
///
/// See also [`Self::allocate_ui_with_layout`],
/// and the helpers [`Self::horizontal`], [`Self::vertical`], etc.
/// If you don't want to use up all available space, use [`Self::allocate_ui_with_layout`].
///
/// See also the helpers [`Self::horizontal`], [`Self::vertical`], etc.
#[inline]
pub fn with_layout<R>(
&mut self,