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
42
graphics/src/shader.rs
Normal file
42
graphics/src/shader.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//! Supported shaders;
|
||||
|
||||
use crate::{Color, widget};
|
||||
use crate::gradient::Gradient;
|
||||
use crate::widget::canvas::{FillStyle, StrokeStyle};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/// Supported shaders for primitives.
|
||||
pub enum Shader {
|
||||
/// Fill a primitive with a solid color.
|
||||
Solid(Color),
|
||||
/// Fill a primitive with an interpolated color.
|
||||
Gradient(Gradient)
|
||||
}
|
||||
|
||||
impl <'a> Into<Shader> for StrokeStyle<'a> {
|
||||
fn into(self) -> Shader {
|
||||
match self {
|
||||
StrokeStyle::Solid(color) => Shader::Solid(color),
|
||||
StrokeStyle::Gradient(gradient) => gradient.clone().into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl <'a> Into<Shader> for FillStyle<'a> {
|
||||
fn into(self) -> Shader {
|
||||
match self {
|
||||
FillStyle::Solid(color) => Shader::Solid(color),
|
||||
FillStyle::Gradient(gradient) => gradient.clone().into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl <'a> Into<Shader> for widget::canvas::Gradient {
|
||||
fn into(self) -> Shader {
|
||||
match self {
|
||||
widget::canvas::Gradient::Linear(linear) => {
|
||||
Shader::Gradient(Gradient::Linear(linear))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue