Draft Canvas types and clock example
This commit is contained in:
parent
8daf798e57
commit
f436f20eb8
9 changed files with 494 additions and 2 deletions
41
wgpu/src/widget/canvas/layer.rs
Normal file
41
wgpu/src/widget/canvas/layer.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use crate::canvas::Frame;
|
||||
|
||||
pub trait Layer: std::fmt::Debug {}
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::{Arc, Weak};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Cached<T: Drawable> {
|
||||
input: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> Cached<T>
|
||||
where
|
||||
T: Drawable + std::fmt::Debug,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Cached { input: PhantomData }
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {}
|
||||
|
||||
pub fn with<'a>(&'a self, input: &'a T) -> impl Layer + 'a {
|
||||
Bind {
|
||||
cache: self,
|
||||
input: input,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Bind<'a, T: Drawable> {
|
||||
cache: &'a Cached<T>,
|
||||
input: &'a T,
|
||||
}
|
||||
|
||||
impl<'a, T> Layer for Bind<'a, T> where T: Drawable + std::fmt::Debug {}
|
||||
|
||||
pub trait Drawable {
|
||||
fn draw(&self, frame: &mut Frame);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue