diff options
Diffstat (limited to 'tiny_skia/src/backend.rs')
| -rw-r--r-- | tiny_skia/src/backend.rs | 50 | 
1 files changed, 44 insertions, 6 deletions
| diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs index 87738174..ba038052 100644 --- a/tiny_skia/src/backend.rs +++ b/tiny_skia/src/backend.rs @@ -1,4 +1,5 @@  use crate::core::text; +use crate::core::Gradient;  use crate::core::{Background, Color, Font, Point, Rectangle, Size, Vector};  use crate::graphics::backend;  use crate::graphics::{Primitive, Viewport}; @@ -91,6 +92,7 @@ impl Backend {                          background_color,                      )),                      anti_alias: false, +                    blend_mode: tiny_skia::BlendMode::Source,                      ..Default::default()                  },                  tiny_skia::FillRule::default(), @@ -194,6 +196,48 @@ impl Backend {                                      *color,                                  ))                              } +                            Background::Gradient(Gradient::Linear(linear)) => { +                                let (start, end) = +                                    linear.angle.to_distance(bounds); + +                                let stops: Vec<tiny_skia::GradientStop> = +                                    linear +                                        .stops +                                        .into_iter() +                                        .flatten() +                                        .map(|stop| { +                                            tiny_skia::GradientStop::new( +                                                stop.offset, +                                                tiny_skia::Color::from_rgba( +                                                    stop.color.b, +                                                    stop.color.g, +                                                    stop.color.r, +                                                    stop.color.a, +                                                ) +                                                .expect("Create color"), +                                            ) +                                        }) +                                        .collect(); + +                                tiny_skia::LinearGradient::new( +                                    tiny_skia::Point { +                                        x: start.x, +                                        y: start.y, +                                    }, +                                    tiny_skia::Point { x: end.x, y: end.y }, +                                    if stops.is_empty() { +                                        vec![tiny_skia::GradientStop::new( +                                            0.0, +                                            tiny_skia::Color::BLACK, +                                        )] +                                    } else { +                                        stops +                                    }, +                                    tiny_skia::SpreadMode::Pad, +                                    tiny_skia::Transform::identity(), +                                ) +                                .expect("Create linear gradient") +                            }                          },                          anti_alias: true,                          ..tiny_skia::Paint::default() @@ -722,12 +766,6 @@ fn adjust_clip_mask(clip_mask: &mut tiny_skia::Mask, bounds: Rectangle) {      );  } -impl iced_graphics::Backend for Backend { -    fn trim_measurements(&mut self) { -        self.text_pipeline.trim_measurement_cache(); -    } -} -  impl backend::Text for Backend {      const ICON_FONT: Font = Font::with_name("Iced-Icons");      const CHECKMARK_ICON: char = '\u{f00c}'; | 
