Skip to content

Commit

Permalink
fix(drawable/text): alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
technobaboo committed Mar 10, 2024
1 parent 302a647 commit 15f771f
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/nodes/drawable/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ use super::{TextAspect, TextStyle};
static TEXT_REGISTRY: Registry<Text> = Registry::new();

fn convert_align(x_align: super::XAlign, y_align: super::YAlign) -> TextAlign {
let x_align = match x_align {
super::XAlign::Left => TextAlign::XLeft,
super::XAlign::Center => TextAlign::XCenter,
super::XAlign::Right => TextAlign::XRight,
} as u32;
let y_align = match y_align {
super::YAlign::Top => TextAlign::YTop,
super::YAlign::Center => TextAlign::YCenter,
super::YAlign::Bottom => TextAlign::YBottom,
} as u32;

unsafe { std::mem::transmute(x_align | y_align) }
match (x_align, y_align) {
(super::XAlign::Left, super::YAlign::Top) => TextAlign::Left,
(super::XAlign::Left, super::YAlign::Center) => TextAlign::CenterLeft,
(super::XAlign::Left, super::YAlign::Bottom) => TextAlign::BottomLeft,
(super::XAlign::Center, super::YAlign::Top) => TextAlign::Center,
(super::XAlign::Center, super::YAlign::Center) => TextAlign::Center,
(super::XAlign::Center, super::YAlign::Bottom) => TextAlign::BottomCenter,
(super::XAlign::Right, super::YAlign::Top) => TextAlign::Right,
(super::XAlign::Right, super::YAlign::Center) => TextAlign::CenterRight,
(super::XAlign::Right, super::YAlign::Bottom) => TextAlign::BottomRight,
}
}

pub struct Text {
Expand Down Expand Up @@ -94,8 +93,8 @@ impl Text {
super::TextFit::Overflow => TextFit::Overflow,
},
*style,
convert_align(bounds.anchor_align_x.clone(), bounds.anchor_align_y.clone()),
convert_align(data.text_align_x.clone(), data.text_align_y.clone()),
convert_align(bounds.anchor_align_x, bounds.anchor_align_y),
convert_align(data.text_align_x, data.text_align_y),
vec3(0.0, 0.0, 0.0),
Color128::from([data.color.c.r, data.color.c.g, data.color.c.b, data.color.a]),
);
Expand All @@ -105,7 +104,7 @@ impl Text {
transform,
*style,
TextAlign::Center,
convert_align(data.text_align_x.clone(), data.text_align_y.clone()),
convert_align(data.text_align_x, data.text_align_y),
vec3(0.0, 0.0, 0.0),
Color128::from([data.color.c.r, data.color.c.g, data.color.c.b, data.color.a]),
);
Expand Down

0 comments on commit 15f771f

Please sign in to comment.