summaryrefslogtreecommitdiffstats
path: root/graphics/src/shader.rs
diff options
context:
space:
mode:
authorLibravatar shan <shankern@protonmail.com>2022-09-29 10:52:58 -0700
committerLibravatar shan <shankern@protonmail.com>2022-09-29 10:52:58 -0700
commit00a8a167122301983753a2f4b43d136c79a7d5cb (patch)
tree99596e40da4150eab2d9e862d84373fcf02a548d /graphics/src/shader.rs
parent97f385e093711c269df315b28f76e66e0220e22a (diff)
downloadiced-00a8a167122301983753a2f4b43d136c79a7d5cb.tar.gz
iced-00a8a167122301983753a2f4b43d136c79a7d5cb.tar.bz2
iced-00a8a167122301983753a2f4b43d136c79a7d5cb.zip
Adds linear gradient support to 2D meshes in the canvas widget.
Diffstat (limited to '')
-rw-r--r--graphics/src/shader.rs42
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