diff options
Diffstat (limited to 'graphics/src/shader.rs')
-rw-r--r-- | graphics/src/shader.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/graphics/src/shader.rs b/graphics/src/shader.rs new file mode 100644 index 00000000..b9071c74 --- /dev/null +++ b/graphics/src/shader.rs @@ -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)) + } + } + } +}
\ No newline at end of file |