summaryrefslogtreecommitdiffstats
path: root/wgpu/src/widget/canvas
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src/widget/canvas')
-rw-r--r--wgpu/src/widget/canvas/drawable.rs6
-rw-r--r--wgpu/src/widget/canvas/event.rs6
-rw-r--r--wgpu/src/widget/canvas/layer/cache.rs16
-rw-r--r--wgpu/src/widget/canvas/program.rs16
4 files changed, 43 insertions, 1 deletions
diff --git a/wgpu/src/widget/canvas/drawable.rs b/wgpu/src/widget/canvas/drawable.rs
index 6c74071c..48ba6b4c 100644
--- a/wgpu/src/widget/canvas/drawable.rs
+++ b/wgpu/src/widget/canvas/drawable.rs
@@ -10,3 +10,9 @@ pub trait Drawable {
/// [`Frame`]: struct.Frame.html
fn draw(&self, frame: &mut Frame);
}
+
+impl<'a> Drawable for dyn Fn(&mut Frame) + 'a {
+ fn draw(&self, frame: &mut Frame) {
+ self(frame)
+ }
+}
diff --git a/wgpu/src/widget/canvas/event.rs b/wgpu/src/widget/canvas/event.rs
new file mode 100644
index 00000000..7a8b0829
--- /dev/null
+++ b/wgpu/src/widget/canvas/event.rs
@@ -0,0 +1,6 @@
+use iced_native::input::mouse;
+
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum Event {
+ Mouse(mouse::Event),
+}
diff --git a/wgpu/src/widget/canvas/layer/cache.rs b/wgpu/src/widget/canvas/layer/cache.rs
index 4f8c2bec..2e87297c 100644
--- a/wgpu/src/widget/canvas/layer/cache.rs
+++ b/wgpu/src/widget/canvas/layer/cache.rs
@@ -1,5 +1,5 @@
use crate::{
- canvas::{Drawable, Frame, Layer},
+ canvas::{Drawable, Frame, Layer, Program},
Primitive,
};
@@ -79,6 +79,20 @@ where
}
}
+impl<T> Program for Cache<T>
+where
+ T: Drawable + std::fmt::Debug,
+{
+ type Input = T;
+
+ fn layers<'a>(
+ &'a self,
+ input: &'a Self::Input,
+ ) -> Vec<Box<dyn Layer + 'a>> {
+ vec![Box::new(self.with(input))]
+ }
+}
+
#[derive(Debug)]
struct Bind<'a, T: Drawable> {
cache: &'a Cache<T>,
diff --git a/wgpu/src/widget/canvas/program.rs b/wgpu/src/widget/canvas/program.rs
new file mode 100644
index 00000000..c65a078b
--- /dev/null
+++ b/wgpu/src/widget/canvas/program.rs
@@ -0,0 +1,16 @@
+use crate::canvas::{Event, Layer, Size};
+
+pub trait Program {
+ type Input;
+
+ fn layers<'a>(&'a self, input: &'a Self::Input)
+ -> Vec<Box<dyn Layer + 'a>>;
+
+ fn update<'a>(
+ &'a mut self,
+ _event: Event,
+ _bounds: Size,
+ _input: &'a Self::Input,
+ ) {
+ }
+}