summaryrefslogtreecommitdiffstats
path: root/wgpu/src/text.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-05 00:40:39 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-05 00:40:39 +0200
commit394e599c3a096b036aabdd6f850c4a7c518d44fa (patch)
treebe925d4f26d7f1e30a289297ccf50ce968d6e86c /wgpu/src/text.rs
parentcc05cb9be4a1de5f0427f93ce64e658be0703f8b (diff)
downloadiced-394e599c3a096b036aabdd6f850c4a7c518d44fa.tar.gz
iced-394e599c3a096b036aabdd6f850c4a7c518d44fa.tar.bz2
iced-394e599c3a096b036aabdd6f850c4a7c518d44fa.zip
Fix layer transformations
Diffstat (limited to 'wgpu/src/text.rs')
-rw-r--r--wgpu/src/text.rs36
1 files changed, 19 insertions, 17 deletions
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index 016ac92a..e0a5355c 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -26,7 +26,7 @@ pub enum Cache {
renderer: glyphon::TextRenderer,
atlas: Option<glyphon::TextAtlas>,
buffer_cache: Option<BufferCache>,
- scale_factor: f32,
+ transformation: Transformation,
target_size: Size<u32>,
needs_reupload: bool,
},
@@ -95,7 +95,7 @@ impl Pipeline {
encoder: &mut wgpu::CommandEncoder,
sections: &Batch,
layer_bounds: Rectangle,
- scale_factor: f32,
+ layer_transformation: Transformation,
target_size: Size<u32>,
) {
if self.renderers.len() <= self.prepare_layer {
@@ -117,7 +117,7 @@ impl Pipeline {
&mut self.cache,
sections,
layer_bounds,
- scale_factor,
+ layer_transformation,
target_size,
);
@@ -140,7 +140,7 @@ impl Pipeline {
encoder: &mut wgpu::CommandEncoder,
cache: &mut Cache,
layer_bounds: Rectangle,
- new_scale_factor: f32,
+ new_transformation: Transformation,
new_target_size: Size<u32>,
) {
match cache {
@@ -186,7 +186,7 @@ impl Pipeline {
buffer_cache.as_mut().unwrap_or(&mut self.cache),
&batch,
layer_bounds,
- new_scale_factor,
+ new_transformation,
new_target_size,
);
@@ -196,7 +196,7 @@ impl Pipeline {
renderer,
atlas,
buffer_cache,
- scale_factor: new_scale_factor,
+ transformation: new_transformation,
target_size: new_target_size,
}
}
@@ -206,13 +206,13 @@ impl Pipeline {
renderer,
atlas,
buffer_cache,
- scale_factor,
+ transformation,
target_size,
} => {
if *needs_reupload
|| atlas.is_none()
|| buffer_cache.is_none()
- || new_scale_factor != *scale_factor
+ || new_transformation != *transformation
|| new_target_size != *target_size
{
let _ = prepare(
@@ -224,11 +224,11 @@ impl Pipeline {
buffer_cache.as_mut().unwrap_or(&mut self.cache),
batch,
layer_bounds,
- *scale_factor,
- *target_size,
+ new_transformation,
+ new_target_size,
);
- *scale_factor = new_scale_factor;
+ *transformation = new_transformation;
*target_size = new_target_size;
}
}
@@ -297,7 +297,7 @@ fn prepare(
buffer_cache: &mut BufferCache,
sections: &Batch,
layer_bounds: Rectangle,
- scale_factor: f32,
+ layer_transformation: Transformation,
target_size: Size<u32>,
) -> Result<(), glyphon::PrepareError> {
let mut font_system = font_system().write().expect("Write font system");
@@ -349,7 +349,7 @@ fn prepare(
})
.collect();
- let layer_bounds = layer_bounds * scale_factor;
+ let layer_bounds = layer_bounds * layer_transformation;
let text_areas = sections.iter().zip(allocations.iter()).filter_map(
|(section, allocation)| {
@@ -456,7 +456,7 @@ fn prepare(
}
};
- let bounds = bounds * transformation * scale_factor;
+ let bounds = bounds * transformation * layer_transformation;
let left = match horizontal_alignment {
alignment::Horizontal::Left => bounds.x,
@@ -470,14 +470,16 @@ fn prepare(
alignment::Vertical::Bottom => bounds.y - bounds.height,
};
- let clip_bounds = layer_bounds
- .intersection(&(clip_bounds * transformation * scale_factor))?;
+ let clip_bounds = layer_bounds.intersection(
+ &(clip_bounds * transformation * layer_transformation),
+ )?;
Some(glyphon::TextArea {
buffer,
left,
top,
- scale: scale_factor * transformation.scale_factor(),
+ scale: transformation.scale_factor()
+ * layer_transformation.scale_factor(),
bounds: glyphon::TextBounds {
left: clip_bounds.x as i32,
top: clip_bounds.y as i32,