diff options
Diffstat (limited to 'tiny_skia/src/geometry.rs')
-rw-r--r-- | tiny_skia/src/geometry.rs | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/tiny_skia/src/geometry.rs b/tiny_skia/src/geometry.rs index 9bd47556..1d14aa03 100644 --- a/tiny_skia/src/geometry.rs +++ b/tiny_skia/src/geometry.rs @@ -39,7 +39,9 @@ impl Frame { } pub fn fill(&mut self, path: &Path, fill: impl Into<Fill>) { - let Some(path) = convert_path(path) else { return }; + let Some(path) = convert_path(path) else { + return; + }; let fill = fill.into(); self.primitives @@ -57,7 +59,9 @@ impl Frame { size: Size, fill: impl Into<Fill>, ) { - let Some(path) = convert_path(&Path::rectangle(top_left, size)) else { return }; + let Some(path) = convert_path(&Path::rectangle(top_left, size)) else { + return; + }; let fill = fill.into(); self.primitives @@ -73,7 +77,9 @@ impl Frame { } pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) { - let Some(path) = convert_path(path) else { return }; + let Some(path) = convert_path(path) else { + return; + }; let stroke = stroke.into(); let skia_stroke = into_stroke(&stroke); @@ -148,8 +154,16 @@ impl Frame { .pre_concat(tiny_skia::Transform::from_rotate(angle.to_degrees())); } - pub fn scale(&mut self, scale: f32) { - self.transform = self.transform.pre_scale(scale, scale); + pub fn scale(&mut self, scale: impl Into<f32>) { + let scale = scale.into(); + + self.scale_nonuniform(Vector { x: scale, y: scale }); + } + + pub fn scale_nonuniform(&mut self, scale: impl Into<Vector>) { + let scale = scale.into(); + + self.transform = self.transform.pre_scale(scale.x, scale.y); } pub fn into_primitive(self) -> Primitive { @@ -166,9 +180,9 @@ fn convert_path(path: &Path) -> Option<tiny_skia::Path> { use iced_graphics::geometry::path::lyon_path; let mut builder = tiny_skia::PathBuilder::new(); - let mut last_point = Default::default(); + let mut last_point = lyon_path::math::Point::default(); - for event in path.raw().iter() { + for event in path.raw() { match event { lyon_path::Event::Begin { at } => { builder.move_to(at.x, at.y); @@ -289,7 +303,7 @@ pub fn into_fill_rule(rule: fill::Rule) -> tiny_skia::FillRule { } } -pub fn into_stroke(stroke: &Stroke) -> tiny_skia::Stroke { +pub fn into_stroke(stroke: &Stroke<'_>) -> tiny_skia::Stroke { tiny_skia::Stroke { width: stroke.width, line_cap: match stroke.line_cap { |