Adjusted gradient transform function to be more readable.
This commit is contained in:
parent
a4a1262fa2
commit
fd5e1e5ab0
4 changed files with 25 additions and 28 deletions
|
|
@ -2,7 +2,7 @@
|
|||
mod linear;
|
||||
|
||||
pub use crate::gradient::linear::{Linear, Location, Position};
|
||||
use crate::{Color, Point};
|
||||
use crate::Color;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
/// A fill which transitions colors progressively along a direction, either linearly, radially (TBD),
|
||||
|
|
@ -27,10 +27,4 @@ impl Gradient {
|
|||
pub fn linear(position: impl Into<Position>) -> linear::Builder {
|
||||
linear::Builder::new(position.into())
|
||||
}
|
||||
|
||||
pub(crate) fn coords(&mut self) -> (&mut Point, &mut Point) {
|
||||
match self {
|
||||
Gradient::Linear(gradient) => (&mut gradient.start, &mut gradient.end)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,13 +67,9 @@ impl<'a> Style<'a> {
|
|||
Style::Solid(color) => {
|
||||
mesh::Style::Solid(*color)
|
||||
},
|
||||
Style::Gradient(gradient) => {
|
||||
let mut gradient = (*gradient).clone();
|
||||
let coordinates = gradient.coords();
|
||||
transform.transform_point(coordinates.0);
|
||||
transform.transform_point(coordinates.1);
|
||||
mesh::Style::Gradient(gradient)
|
||||
}
|
||||
Style::Gradient(gradient) => mesh::Style::Gradient(
|
||||
transform.transform_gradient((*gradient).clone()),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@ use std::borrow::Cow;
|
|||
|
||||
use iced_native::{Point, Rectangle, Size, Vector};
|
||||
|
||||
use crate::gradient::Gradient;
|
||||
use crate::layer::mesh;
|
||||
use crate::triangle;
|
||||
use crate::triangle::Vertex2D;
|
||||
use crate::widget::canvas::{path, Fill, Geometry, Path, Stroke, Text};
|
||||
use crate::Primitive;
|
||||
|
||||
use crate::layer::mesh;
|
||||
use crate::triangle::Vertex2D;
|
||||
use lyon::tessellation;
|
||||
|
||||
/// The frame of a [`Canvas`].
|
||||
|
|
@ -38,12 +39,24 @@ pub(crate) struct Transform {
|
|||
|
||||
impl Transform {
|
||||
/// Transforms the given [Point] by the transformation matrix.
|
||||
pub(crate) fn transform_point(&self, point: &mut Point) {
|
||||
fn transform_point(&self, point: &mut Point) {
|
||||
let transformed =
|
||||
self.raw.transform_point(Point2D::new(point.x, point.y));
|
||||
point.x = transformed.x;
|
||||
point.y = transformed.y;
|
||||
}
|
||||
|
||||
pub(crate) fn transform_gradient(
|
||||
&self,
|
||||
mut gradient: Gradient,
|
||||
) -> Gradient {
|
||||
let coords = match &mut gradient {
|
||||
Gradient::Linear(linear) => (&mut linear.start, &mut linear.end),
|
||||
};
|
||||
self.transform_point(coords.0);
|
||||
self.transform_point(coords.1);
|
||||
gradient
|
||||
}
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
//! Create lines from a [crate::widget::canvas::Path] and assigns them various attributes/styles.
|
||||
|
||||
use iced_native::Color;
|
||||
use crate::gradient::Gradient;
|
||||
use crate::layer::mesh;
|
||||
use crate::widget::canvas::frame::Transform;
|
||||
use iced_native::Color;
|
||||
|
||||
/// The style of a stroke.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -73,16 +73,10 @@ 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) => {
|
||||
let mut gradient = (*gradient).clone();
|
||||
let coordinates = gradient.coords();
|
||||
transform.transform_point(coordinates.0);
|
||||
transform.transform_point(coordinates.1);
|
||||
mesh::Style::Gradient(gradient)
|
||||
}
|
||||
Style::Solid(color) => mesh::Style::Solid(*color),
|
||||
Style::Gradient(gradient) => mesh::Style::Gradient(
|
||||
transform.transform_gradient((*gradient).clone()),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue