Adds linear gradient support to 2D meshes in the canvas widget.
This commit is contained in:
parent
97f385e093
commit
40f45d7b7e
40 changed files with 2041 additions and 655 deletions
|
|
@ -1,10 +1,14 @@
|
|||
use iced_native::Color;
|
||||
|
||||
use crate::widget::canvas::Gradient;
|
||||
|
||||
/// The style of a stroke.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Stroke<'a> {
|
||||
/// The color of the stroke.
|
||||
pub color: Color,
|
||||
/// The color or gradient of the stroke.
|
||||
///
|
||||
/// By default, it is set to [`StrokeStyle::Solid`] `BLACK`.
|
||||
pub style: StrokeStyle<'a>,
|
||||
/// 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.
|
||||
|
|
@ -19,7 +23,10 @@ pub struct Stroke<'a> {
|
|||
impl<'a> Stroke<'a> {
|
||||
/// Sets the color of the [`Stroke`].
|
||||
pub fn with_color(self, color: Color) -> Self {
|
||||
Stroke { color, ..self }
|
||||
Stroke {
|
||||
style: StrokeStyle::Solid(color),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the width of the [`Stroke`].
|
||||
|
|
@ -41,7 +48,7 @@ impl<'a> Stroke<'a> {
|
|||
impl<'a> Default for Stroke<'a> {
|
||||
fn default() -> Self {
|
||||
Stroke {
|
||||
color: Color::BLACK,
|
||||
style: StrokeStyle::Solid(Color::BLACK),
|
||||
width: 1.0,
|
||||
line_cap: LineCap::default(),
|
||||
line_join: LineJoin::default(),
|
||||
|
|
@ -50,6 +57,15 @@ impl<'a> Default for Stroke<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// The color or gradient of a [`Stroke`].
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum StrokeStyle<'a> {
|
||||
/// A solid color
|
||||
Solid(Color),
|
||||
/// A color gradient
|
||||
Gradient(&'a Gradient),
|
||||
}
|
||||
|
||||
/// The shape used at the end of open subpaths when they are stroked.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum LineCap {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue