summaryrefslogtreecommitdiffstats
path: root/wgpu/src/layer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src/layer.rs')
-rw-r--r--wgpu/src/layer.rs72
1 files changed, 31 insertions, 41 deletions
diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs
index e213c95f..fd5f2345 100644
--- a/wgpu/src/layer.rs
+++ b/wgpu/src/layer.rs
@@ -15,7 +15,7 @@ use crate::core::alignment;
use crate::core::{Color, Font, Pixels, Point, Rectangle, Size, Vector};
use crate::graphics;
use crate::graphics::color;
-use crate::graphics::Viewport;
+use crate::graphics::{Transformation, Viewport};
use crate::primitive::{self, Primitive};
use crate::quad::{self, Quad};
@@ -104,7 +104,7 @@ impl<'a> Layer<'a> {
for primitive in primitives {
Self::process_primitive(
&mut layers,
- Vector::new(0.0, 0.0),
+ Transformation::IDENTITY,
primitive,
0,
);
@@ -115,7 +115,7 @@ impl<'a> Layer<'a> {
fn process_primitive(
layers: &mut Vec<Self>,
- translation: Vector,
+ transformation: Transformation,
primitive: &'a Primitive,
current_layer: usize,
) {
@@ -130,9 +130,10 @@ impl<'a> Layer<'a> {
layer.text.push(Text::Paragraph {
paragraph: paragraph.clone(),
- position: *position + translation,
+ position: *position * transformation,
color: *color,
- clip_bounds: *clip_bounds + translation,
+ clip_bounds: *clip_bounds * transformation,
+ scale: transformation.scale_y(),
});
}
Primitive::Editor {
@@ -145,9 +146,10 @@ impl<'a> Layer<'a> {
layer.text.push(Text::Editor {
editor: editor.clone(),
- position: *position + translation,
+ position: *position * transformation,
color: *color,
- clip_bounds: *clip_bounds + translation,
+ clip_bounds: *clip_bounds * transformation,
+ scale: transformation.scale_y(),
});
}
Primitive::Text {
@@ -166,7 +168,7 @@ impl<'a> Layer<'a> {
layer.text.push(Text::Cached(text::Cached {
content,
- bounds: *bounds + translation,
+ bounds: *bounds * transformation,
size: *size,
line_height: *line_height,
color: *color,
@@ -174,7 +176,7 @@ impl<'a> Layer<'a> {
horizontal_alignment: *horizontal_alignment,
vertical_alignment: *vertical_alignment,
shaping: *shaping,
- clip_bounds: *clip_bounds + translation,
+ clip_bounds: *clip_bounds * transformation,
}));
}
graphics::Primitive::RawText(graphics::text::Raw {
@@ -187,9 +189,9 @@ impl<'a> Layer<'a> {
layer.text.push(Text::Raw(graphics::text::Raw {
buffer: buffer.clone(),
- position: *position + translation,
+ position: *position * transformation,
color: *color,
- clip_bounds: *clip_bounds + translation,
+ clip_bounds: *clip_bounds * transformation,
}));
}
Primitive::Quad {
@@ -199,12 +201,10 @@ impl<'a> Layer<'a> {
shadow,
} => {
let layer = &mut layers[current_layer];
+ let bounds = *bounds * transformation;
let quad = Quad {
- position: [
- bounds.x + translation.x,
- bounds.y + translation.y,
- ],
+ position: [bounds.x, bounds.y],
size: [bounds.width, bounds.height],
border_color: color::pack(border.color),
border_radius: border.radius.into(),
@@ -226,7 +226,7 @@ impl<'a> Layer<'a> {
layer.images.push(Image::Raster {
handle: handle.clone(),
filter_method: *filter_method,
- bounds: *bounds + translation,
+ bounds: *bounds * transformation,
});
}
Primitive::Svg {
@@ -239,7 +239,7 @@ impl<'a> Layer<'a> {
layer.images.push(Image::Vector {
handle: handle.clone(),
color: *color,
- bounds: *bounds + translation,
+ bounds: *bounds * transformation,
});
}
Primitive::Group { primitives } => {
@@ -247,7 +247,7 @@ impl<'a> Layer<'a> {
for primitive in primitives {
Self::process_primitive(
layers,
- translation,
+ transformation,
primitive,
current_layer,
);
@@ -255,7 +255,7 @@ impl<'a> Layer<'a> {
}
Primitive::Clip { bounds, content } => {
let layer = &mut layers[current_layer];
- let translated_bounds = *bounds + translation;
+ let translated_bounds = *bounds * transformation;
// Only draw visible content
if let Some(clip_bounds) =
@@ -266,19 +266,19 @@ impl<'a> Layer<'a> {
Self::process_primitive(
layers,
- translation,
+ transformation,
content,
layers.len() - 1,
);
}
}
- Primitive::Translate {
- translation: new_translation,
+ Primitive::Transform {
+ transformation: new_transformation,
content,
} => {
Self::process_primitive(
layers,
- translation + *new_translation,
+ transformation * *new_transformation,
content,
current_layer,
);
@@ -286,7 +286,7 @@ impl<'a> Layer<'a> {
Primitive::Cache { content } => {
Self::process_primitive(
layers,
- translation,
+ transformation,
content,
current_layer,
);
@@ -296,20 +296,15 @@ impl<'a> Layer<'a> {
graphics::Mesh::Solid { buffers, size } => {
let layer = &mut layers[current_layer];
- let bounds = Rectangle::new(
- Point::new(translation.x, translation.y),
- *size,
- );
+ let bounds =
+ Rectangle::with_size(*size) * transformation;
// Only draw visible content
if let Some(clip_bounds) =
layer.bounds.intersection(&bounds)
{
layer.meshes.push(Mesh::Solid {
- origin: Point::new(
- translation.x,
- translation.y,
- ),
+ transformation,
buffers,
clip_bounds,
});
@@ -318,20 +313,15 @@ impl<'a> Layer<'a> {
graphics::Mesh::Gradient { buffers, size } => {
let layer = &mut layers[current_layer];
- let bounds = Rectangle::new(
- Point::new(translation.x, translation.y),
- *size,
- );
+ let bounds =
+ Rectangle::with_size(*size) * transformation;
// Only draw visible content
if let Some(clip_bounds) =
layer.bounds.intersection(&bounds)
{
layer.meshes.push(Mesh::Gradient {
- origin: Point::new(
- translation.x,
- translation.y,
- ),
+ transformation,
buffers,
clip_bounds,
});
@@ -340,7 +330,7 @@ impl<'a> Layer<'a> {
},
primitive::Custom::Pipeline(pipeline) => {
let layer = &mut layers[current_layer];
- let bounds = pipeline.bounds + translation;
+ let bounds = pipeline.bounds * transformation;
if let Some(clip_bounds) =
layer.bounds.intersection(&bounds)