summaryrefslogtreecommitdiffstats
path: root/tiny_skia/src/backend.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-01 21:34:26 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-01 21:34:26 +0100
commit5fd5d1cdf8e5354788dc40729c4565ef377d3bba (patch)
tree0921efc7dc13a3050e03482147a791f85515f1f2 /tiny_skia/src/backend.rs
parent3f6e28fa9b1b8d911f765c9efb5249a9e0c942d5 (diff)
downloadiced-5fd5d1cdf8e5354788dc40729c4565ef377d3bba.tar.gz
iced-5fd5d1cdf8e5354788dc40729c4565ef377d3bba.tar.bz2
iced-5fd5d1cdf8e5354788dc40729c4565ef377d3bba.zip
Implement `Canvas` support for `iced_tiny_skia`
Diffstat (limited to 'tiny_skia/src/backend.rs')
-rw-r--r--tiny_skia/src/backend.rs48
1 files changed, 42 insertions, 6 deletions
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs
index 66d83221..e08cede7 100644
--- a/tiny_skia/src/backend.rs
+++ b/tiny_skia/src/backend.rs
@@ -1,9 +1,9 @@
-use crate::{Color, Font, Settings, Size, Viewport};
+use crate::{Color, Font, Primitive, Settings, Size, Viewport};
use iced_graphics::alignment;
use iced_graphics::backend;
use iced_graphics::text;
-use iced_graphics::{Background, Primitive, Rectangle, Vector};
+use iced_graphics::{Background, Rectangle, Vector};
use std::borrow::Cow;
@@ -81,7 +81,6 @@ impl Backend {
translation: Vector,
) {
match primitive {
- Primitive::None => {}
Primitive::Quad {
bounds,
background,
@@ -161,6 +160,38 @@ impl Backend {
Primitive::Svg { .. } => {
// TODO
}
+ Primitive::Fill {
+ path,
+ paint,
+ rule,
+ transform,
+ } => {
+ pixels.fill_path(
+ path,
+ paint,
+ *rule,
+ transform
+ .post_translate(translation.x, translation.y)
+ .post_scale(scale_factor, scale_factor),
+ clip_mask,
+ );
+ }
+ Primitive::Stroke {
+ path,
+ paint,
+ stroke,
+ transform,
+ } => {
+ pixels.stroke_path(
+ path,
+ paint,
+ stroke,
+ transform
+ .post_translate(translation.x, translation.y)
+ .post_scale(scale_factor, scale_factor),
+ clip_mask,
+ );
+ }
Primitive::Group { primitives } => {
for primitive in primitives {
self.draw_primitive(
@@ -196,16 +227,19 @@ impl Backend {
translation,
);
}
- Primitive::Cached { cache } => {
+ Primitive::Cache { content } => {
self.draw_primitive(
- cache,
+ content,
pixels,
clip_mask,
scale_factor,
translation,
);
}
- Primitive::SolidMesh { .. } | Primitive::GradientMesh { .. } => {}
+ Primitive::SolidMesh { .. } | Primitive::GradientMesh { .. } => {
+ // Not supported!
+ // TODO: Draw a placeholder (?) / Log it (?)
+ }
}
}
}
@@ -386,6 +420,8 @@ fn rectangular_clip_mask(
}
impl iced_graphics::Backend for Backend {
+ type Geometry = ();
+
fn trim_measurements(&mut self) {
self.text_pipeline.trim_measurement_cache();
}