summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer/widget/text.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-10 01:34:22 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-10 01:39:36 +0200
commitb549b509c9454944dc629c4510b7f7e92ec21085 (patch)
tree898d585d046a0bfb509105ef648c4c5fef760d01 /wgpu/src/renderer/widget/text.rs
parent19f6a5e2fd685c76a06576e45c64e7c9e3b3a57f (diff)
downloadiced-b549b509c9454944dc629c4510b7f7e92ec21085.tar.gz
iced-b549b509c9454944dc629c4510b7f7e92ec21085.tar.bz2
iced-b549b509c9454944dc629c4510b7f7e92ec21085.zip
Align text in `iced_wgpu` on a case-by-case basis
Diffstat (limited to 'wgpu/src/renderer/widget/text.rs')
-rw-r--r--wgpu/src/renderer/widget/text.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/wgpu/src/renderer/widget/text.rs b/wgpu/src/renderer/widget/text.rs
index 33e549cd..80bff574 100644
--- a/wgpu/src/renderer/widget/text.rs
+++ b/wgpu/src/renderer/widget/text.rs
@@ -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,