From bb424e54c5083402225a0fdda6130de575592dca Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 19 Apr 2020 18:48:30 +0200 Subject: Add interactivity to `solar_system` example --- wgpu/src/widget/canvas/layer/cache.rs | 50 +++++++++-------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) (limited to 'wgpu') diff --git a/wgpu/src/widget/canvas/layer/cache.rs b/wgpu/src/widget/canvas/layer/cache.rs index e8d62b63..4ecebb48 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, Program}, + canvas::{Drawable, Frame, Layer}, Primitive, }; @@ -26,34 +26,17 @@ impl Default for State { /// /// [`Layer`]: ../trait.Layer.html /// [`Cache`]: struct.Cache.html -#[derive(Debug)] -pub struct Cache { - input: PhantomData, +#[derive(Debug, Default)] +pub struct Cache { state: RefCell, } -impl Default for Cache -where - T: Drawable, -{ - fn default() -> Self { - Self { - input: PhantomData, - state: Default::default(), - } - } -} - -impl Cache -where - T: Drawable + std::fmt::Debug, -{ +impl Cache { /// Creates a new empty [`Cache`]. /// /// [`Cache`]: struct.Cache.html pub fn new() -> Self { Cache { - input: PhantomData, state: Default::default(), } } @@ -71,35 +54,26 @@ where /// [`Cache`]: struct.Cache.html /// [`Layer`]: ../trait.Layer.html /// [`Canvas`]: ../../struct.Canvas.html - pub fn with<'a>( + pub fn with<'a, T>( &'a self, input: impl Borrow + std::fmt::Debug + 'a, - ) -> impl Layer + 'a { + ) -> impl Layer + 'a + where + T: Drawable + std::fmt::Debug + 'a, + { Bind { cache: self, input: input, + drawable: PhantomData, } } } -impl Program for Cache -where - T: Drawable + std::fmt::Debug, -{ - type Input = T; - - fn layers<'a>( - &'a self, - input: &'a Self::Input, - ) -> Vec> { - vec![Box::new(self.with(input))] - } -} - #[derive(Debug)] struct Bind<'a, T: Drawable, I: Borrow + 'a> { - cache: &'a Cache, + cache: &'a Cache, input: I, + drawable: PhantomData, } impl<'a, T, I> Layer for Bind<'a, T, I> -- cgit