summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer/widget/text.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-04-10 23:16:21 +0200
committerLibravatar GitHub <noreply@github.com>2020-04-10 23:16:21 +0200
commite941eab4ab58da4473dd4473215bc4f36684dafb (patch)
treeeae9d2bd0880e46c9f7c5fe93282951c8ecd36d3 /wgpu/src/renderer/widget/text.rs
parent19f6a5e2fd685c76a06576e45c64e7c9e3b3a57f (diff)
parent47d44af348db79735233e408b1560661b9f96960 (diff)
downloadiced-e941eab4ab58da4473dd4473215bc4f36684dafb.tar.gz
iced-e941eab4ab58da4473dd4473215bc4f36684dafb.tar.bz2
iced-e941eab4ab58da4473dd4473215bc4f36684dafb.zip
Merge pull request #281 from hecrj/fix/canvas-text-alignment
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,