From aa41d7656e734b5dae3c19dff87afbc74617a67f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 24 Oct 2023 02:51:02 +0200 Subject: Apply `Transform` scaling to text primitives --- core/src/pixels.rs | 8 ++++++++ wgpu/src/layer.rs | 2 +- wgpu/src/text.rs | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/src/pixels.rs b/core/src/pixels.rs index 6a9e5c88..425c0028 100644 --- a/core/src/pixels.rs +++ b/core/src/pixels.rs @@ -26,3 +26,11 @@ impl From for f32 { pixels.0 } } + +impl std::ops::Mul for Pixels { + type Output = Pixels; + + fn mul(self, rhs: f32) -> Self { + Pixels(self.0 * rhs) + } +} diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index fd5f2345..82e8ba02 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -169,7 +169,7 @@ impl<'a> Layer<'a> { layer.text.push(Text::Cached(text::Cached { content, bounds: *bounds * transformation, - size: *size, + size: *size * transformation.scale_y(), line_height: *line_height, color: *color, font: *font, diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index dca09cb8..4a151073 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -124,11 +124,13 @@ impl Pipeline { vertical_alignment, color, clip_bounds, + scale, ) = match section { Text::Paragraph { position, color, clip_bounds, + scale, .. } => { use crate::core::text::Paragraph as _; @@ -145,12 +147,14 @@ impl Pipeline { paragraph.vertical_alignment(), *color, *clip_bounds, + *scale, ) } Text::Editor { position, color, clip_bounds, + scale, .. } => { use crate::core::text::Editor as _; @@ -167,6 +171,7 @@ impl Pipeline { alignment::Vertical::Top, *color, *clip_bounds, + *scale, ) } Text::Cached(text) => { @@ -186,6 +191,7 @@ impl Pipeline { text.vertical_alignment, text.color, text.clip_bounds, + 1.0, ) } Text::Raw(text) => { @@ -205,6 +211,7 @@ impl Pipeline { alignment::Vertical::Top, text.color, text.clip_bounds, + 1.0, ) } }; @@ -234,7 +241,7 @@ impl Pipeline { buffer, left, top, - scale: scale_factor, + scale: scale * scale_factor, bounds: glyphon::TextBounds { left: clip_bounds.x as i32, top: clip_bounds.y as i32, -- cgit