summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-19 18:48:30 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-19 18:48:30 +0200
commitbb424e54c5083402225a0fdda6130de575592dca (patch)
treee86a38e11c9d431668a342443d91b7fcf73d89da /wgpu
parenta97acd8fa854a470f26e7c39a62b90f2e2c2c664 (diff)
downloadiced-bb424e54c5083402225a0fdda6130de575592dca.tar.gz
iced-bb424e54c5083402225a0fdda6130de575592dca.tar.bz2
iced-bb424e54c5083402225a0fdda6130de575592dca.zip
Add interactivity to `solar_system` example
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/widget/canvas/layer/cache.rs50
1 files changed, 12 insertions, 38 deletions
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<T: Drawable> {
- input: PhantomData<T>,
+#[derive(Debug, Default)]
+pub struct Cache {
state: RefCell<State>,
}
-impl<T> Default for Cache<T>
-where
- T: Drawable,
-{
- fn default() -> Self {
- Self {
- input: PhantomData,
- state: Default::default(),
- }
- }
-}
-
-impl<T> Cache<T>
-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<T> + 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<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, I: Borrow<T> + 'a> {
- cache: &'a Cache<T>,
+ cache: &'a Cache,
input: I,
+ drawable: PhantomData<T>,
}
impl<'a, T, I> Layer for Bind<'a, T, I>