diff --git a/egui/src/layout.rs b/egui/src/layout.rs index 3678d392..c438739f 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -288,6 +288,18 @@ impl Layout { || self.main_dir.is_vertical() && self.cross_align == Align::Max } + /// e.g. for adjusting the placement of something. + /// * in horizontal layout: left or right? + /// * in vertical layout: same as [`Self::horizontal_align`]. + pub fn horizontal_placement(&self) -> Align { + match self.main_dir { + Direction::LeftToRight => Align::LEFT, + Direction::RightToLeft => Align::RIGHT, + Direction::TopDown | Direction::BottomUp => self.cross_align, + } + } + + /// e.g. for when aligning text within a button. pub fn horizontal_align(&self) -> Align { if self.is_horizontal() { self.main_align @@ -296,6 +308,7 @@ impl Layout { } } + /// e.g. for when aligning text within a button. pub fn vertical_align(&self) -> Align { if self.is_vertical() { self.main_align @@ -304,6 +317,7 @@ impl Layout { } } + /// e.g. for when aligning text within a button. fn align2(&self) -> Align2 { Align2([self.horizontal_align(), self.vertical_align()]) } diff --git a/egui/src/widgets/label.rs b/egui/src/widgets/label.rs index 69102b7a..6ccc3e6c 100644 --- a/egui/src/widgets/label.rs +++ b/egui/src/widgets/label.rs @@ -175,7 +175,7 @@ impl Label { (Align::LEFT, false) // TODO: remove special Grid hacks like these } else { ( - ui.layout().horizontal_align(), + ui.layout().horizontal_placement(), ui.layout().horizontal_justify(), ) }; diff --git a/egui/src/widgets/plot/legend.rs b/egui/src/widgets/plot/legend.rs index 67648049..3f41c400 100644 --- a/egui/src/widgets/plot/legend.rs +++ b/egui/src/widgets/plot/legend.rs @@ -104,7 +104,7 @@ impl LegendEntry { .widget_info(|| WidgetInfo::selected(WidgetType::Checkbox, *checked, galley.text())); let visuals = ui.style().interact(&response); - let label_on_the_left = ui.layout().horizontal_align() == Align::RIGHT; + let label_on_the_left = ui.layout().horizontal_placement() == Align::RIGHT; let icon_position_x = if label_on_the_left { rect.right() - icon_size / 2.0