Draft Program interactivity for Canvas
This commit is contained in:
parent
90c3a183d5
commit
0b5028b1ab
9 changed files with 112 additions and 36 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
wgpu/src/widget/canvas/event.rs
Normal file
6
wgpu/src/widget/canvas/event.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use iced_native::input::mouse;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum Event {
|
||||
Mouse(mouse::Event),
|
||||
}
|
||||
|
|
@ -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>,
|
||||
|
|
|
|||
16
wgpu/src/widget/canvas/program.rs
Normal file
16
wgpu/src/widget/canvas/program.rs
Normal file
|
|
@ -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,
|
||||
) {
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue