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