From ecfdf031e4e58a29364e49163bd5ff3a83c83417 Mon Sep 17 00:00:00 2001 From: Ioannis Skottis Date: Thu, 24 Aug 2023 19:04:46 +0100 Subject: [PATCH] Add fill function --- src/widget/piet_scene_helpers.rs | 36 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/widget/piet_scene_helpers.rs b/src/widget/piet_scene_helpers.rs index 64884e270..4e41d7412 100644 --- a/src/widget/piet_scene_helpers.rs +++ b/src/widget/piet_scene_helpers.rs @@ -1,5 +1,5 @@ use vello::kurbo::{self, Affine, Rect, Shape}; -use vello::peniko::{BrushRef, ColorStopsSource, Fill, Gradient, Stroke}; +use vello::peniko::{Brush, BrushRef, Color, ColorStopsSource, Fill, Gradient, Stroke}; use vello::SceneBuilder; #[derive(Debug, Clone, Copy)] @@ -8,21 +8,6 @@ pub struct UnitPoint { v: f64, } -pub fn stroke<'b>( - builder: &mut SceneBuilder, - path: &impl Shape, - brush: impl Into>, - stroke_width: f64, -) { - builder.stroke( - &Stroke::new(stroke_width as f32), - Affine::IDENTITY, - brush, - None, - path, - ) -} - // Note: copied from piet #[allow(unused)] impl UnitPoint { @@ -62,6 +47,21 @@ impl UnitPoint { } } +pub fn stroke<'b>( + builder: &mut SceneBuilder, + path: &impl Shape, + brush: impl Into>, + stroke_width: f64, +) { + builder.stroke( + &Stroke::new(stroke_width as f32), + Affine::IDENTITY, + brush, + None, + path, + ) +} + pub fn fill_lin_gradient( builder: &mut SceneBuilder, path: &impl Shape, @@ -73,3 +73,7 @@ pub fn fill_lin_gradient( let brush = Gradient::new_linear(start.resolve(rect), end.resolve(rect)).with_stops(stops); builder.fill(Fill::NonZero, Affine::IDENTITY, &brush, None, path); } + +pub fn fill_color(builder: &mut SceneBuilder, path: &impl Shape, color: Color) { + builder.fill(Fill::NonZero, Affine::IDENTITY, color, None, path) +}