Fix missing spaces between labels in horizontal layouts

This commit is contained in:
Emil Ernerfeldt 2021-10-12 22:23:53 +02:00
parent 1c4237097f
commit c42afd3941
3 changed files with 16 additions and 2 deletions

View file

@ -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()])
}

View file

@ -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(),
)
};

View file

@ -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