From 84d1b79fefc88534835fdfbe79bc0eb3b43627cf Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Nov 2022 05:50:53 +0100 Subject: Move `mesh::Style` to `triangle` and reuse it in `fill` and `stroke` --- graphics/src/widget/canvas/stroke.rs | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'graphics/src/widget/canvas/stroke.rs') diff --git a/graphics/src/widget/canvas/stroke.rs b/graphics/src/widget/canvas/stroke.rs index 2f02a2f3..f9b8e447 100644 --- a/graphics/src/widget/canvas/stroke.rs +++ b/graphics/src/widget/canvas/stroke.rs @@ -1,8 +1,6 @@ //! Create lines from a [crate::widget::canvas::Path] and assigns them various attributes/styles. +pub use crate::triangle::Style; -use crate::gradient::Gradient; -use crate::layer::mesh; -use crate::widget::canvas::frame::Transform; use iced_native::Color; /// The style of a stroke. @@ -11,7 +9,7 @@ pub struct Stroke<'a> { /// The color or gradient of the stroke. /// /// By default, it is set to [`StrokeStyle::Solid`] `BLACK`. - pub style: Style<'a>, + pub style: Style, /// The distance between the two edges of the stroke. pub width: f32, /// The shape to be used at the end of open subpaths when they are stroked. @@ -60,27 +58,6 @@ impl<'a> Default for Stroke<'a> { } } -/// The style of a [`Stroke`]. -#[derive(Debug, Clone, Copy)] -pub enum Style<'a> { - /// A solid color - Solid(Color), - /// A color gradient - Gradient(&'a Gradient), -} - -impl<'a> Style<'a> { - /// Converts a fill's [Style] to a [mesh::Style] for use in the renderer's shader. - pub(crate) fn as_mesh_style(&self, transform: &Transform) -> mesh::Style { - match self { - Style::Solid(color) => mesh::Style::Solid(*color), - Style::Gradient(gradient) => mesh::Style::Gradient( - transform.transform_gradient((*gradient).clone()), - ), - } - } -} - /// The shape used at the end of open subpaths when they are stroked. #[derive(Debug, Clone, Copy)] pub enum LineCap { -- cgit