Skip to content

Commit

Permalink
Add fill function
Browse files Browse the repository at this point in the history
  • Loading branch information
giannissc committed Aug 24, 2023
1 parent e625593 commit ecfdf03
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/widget/piet_scene_helpers.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -8,21 +8,6 @@ pub struct UnitPoint {
v: f64,
}

pub fn stroke<'b>(
builder: &mut SceneBuilder,
path: &impl Shape,
brush: impl Into<BrushRef<'b>>,
stroke_width: f64,
) {
builder.stroke(
&Stroke::new(stroke_width as f32),
Affine::IDENTITY,
brush,
None,
path,
)
}

// Note: copied from piet
#[allow(unused)]
impl UnitPoint {
Expand Down Expand Up @@ -62,6 +47,21 @@ impl UnitPoint {
}
}

pub fn stroke<'b>(
builder: &mut SceneBuilder,
path: &impl Shape,
brush: impl Into<BrushRef<'b>>,
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,
Expand All @@ -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)
}

0 comments on commit ecfdf03

Please sign in to comment.