Skip to content

Commit

Permalink
ui: Labels should always use middle positioning unless overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Dec 6, 2023
1 parent 0381618 commit 389af04
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions all-is-cubes-ui/src/vui/widgets/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Label {
self.text.clone(),
self.font.clone(),
self.positioning
.unwrap_or_else(|| gravity_to_positioning(gravity)),
.unwrap_or_else(|| gravity_to_positioning(gravity, true)),
)
}
}
Expand Down Expand Up @@ -167,17 +167,21 @@ fn text_for_widget(text: ArcStr, font: text::Font, positioning: text::Positionin
text
}

fn gravity_to_positioning(gravity: vui::Gravity) -> text::Positioning {
fn gravity_to_positioning(gravity: vui::Gravity, ignore_y: bool) -> text::Positioning {
text::Positioning {
x: match gravity.x {
vui::Align::Low => text::PositioningX::Left,
vui::Align::Center => text::PositioningX::Center,
vui::Align::High => text::PositioningX::Right,
},
line_y: match gravity.y {
vui::Align::Low => text::PositioningY::BodyBottom,
vui::Align::Center => text::PositioningY::BodyMiddle,
vui::Align::High => text::PositioningY::BodyTop,
line_y: if ignore_y {
text::PositioningY::BodyMiddle
} else {
match gravity.y {
vui::Align::Low => text::PositioningY::BodyBottom,
vui::Align::Center => text::PositioningY::BodyMiddle,
vui::Align::High => text::PositioningY::BodyTop,
}
},
z: match gravity.z {
vui::Align::Low | vui::Align::Center => text::PositioningZ::Back,
Expand Down

0 comments on commit 389af04

Please sign in to comment.