Align text in iced_wgpu on a case-by-case basis

This commit is contained in:
Héctor Ramón Jiménez 2020-04-10 01:34:22 +02:00
parent 19f6a5e2fd
commit b549b509c9
5 changed files with 49 additions and 23 deletions

View file

@ -38,7 +38,11 @@ impl checkbox::Renderer for Renderer {
content: crate::text::CHECKMARK_ICON.to_string(),
font: crate::text::BUILTIN_ICONS,
size: bounds.height * 0.7,
bounds,
bounds: Rectangle {
x: bounds.center_x(),
y: bounds.center_y(),
..bounds
},
color: style.checkmark_color,
horizontal_alignment: HorizontalAlignment::Center,
vertical_alignment: VerticalAlignment::Center,

View file

@ -31,11 +31,23 @@ impl text::Renderer for Renderer {
horizontal_alignment: HorizontalAlignment,
vertical_alignment: VerticalAlignment,
) -> Self::Output {
let x = match horizontal_alignment {
iced_native::HorizontalAlignment::Left => bounds.x,
iced_native::HorizontalAlignment::Center => bounds.center_x(),
iced_native::HorizontalAlignment::Right => bounds.x + bounds.width,
};
let y = match vertical_alignment {
iced_native::VerticalAlignment::Top => bounds.y,
iced_native::VerticalAlignment::Center => bounds.center_y(),
iced_native::VerticalAlignment::Bottom => bounds.y + bounds.height,
};
(
Primitive::Text {
content: content.to_string(),
size: f32::from(size),
bounds,
bounds: Rectangle { x, y, ..bounds },
color: color.unwrap_or(defaults.text.color),
font,
horizontal_alignment,

View file

@ -109,6 +109,7 @@ impl text_input::Renderer for Renderer {
},
font,
bounds: Rectangle {
y: text_bounds.center_y(),
width: f32::INFINITY,
..text_bounds
},