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/cache.rs37
-rw-r--r--wgpu/src/widget/canvas/drawable.rs36
-rw-r--r--wgpu/src/widget/canvas/program.rs (renamed from wgpu/src/widget/canvas/state.rs)6
3 files changed, 10 insertions, 69 deletions
diff --git a/wgpu/src/widget/canvas/cache.rs b/wgpu/src/widget/canvas/cache.rs
index 2beed0f7..03643f74 100644
--- a/wgpu/src/widget/canvas/cache.rs
+++ b/wgpu/src/widget/canvas/cache.rs
@@ -1,5 +1,5 @@
use crate::{
- canvas::{Drawable, Frame, Geometry},
+ canvas::{Frame, Geometry},
Primitive,
};
@@ -48,10 +48,11 @@ impl Cache {
*self.state.borrow_mut() = State::Empty;
}
- pub fn draw<T>(&self, new_bounds: Size, input: T) -> Geometry
- where
- T: Drawable + std::fmt::Debug,
- {
+ pub fn draw(
+ &self,
+ new_bounds: Size,
+ draw_fn: impl Fn(&mut Frame),
+ ) -> Geometry {
use std::ops::Deref;
if let State::Filled { bounds, primitive } = self.state.borrow().deref()
@@ -64,7 +65,7 @@ impl Cache {
}
let mut frame = Frame::new(new_bounds);
- input.draw(&mut frame);
+ draw_fn(&mut frame);
let primitive = {
let geometry = frame.into_geometry();
@@ -79,30 +80,6 @@ impl Cache {
Geometry::from_primitive(Primitive::Cached { cache: primitive })
}
-
- pub fn with<'a, T, Message>(
- &'a self,
- input: T,
- ) -> impl crate::canvas::State<Message> + 'a
- where
- T: Drawable + std::fmt::Debug + 'a,
- {
- Bind { cache: self, input }
- }
-}
-
-struct Bind<'a, T> {
- cache: &'a Cache,
- input: T,
-}
-
-impl<'a, T, Message> crate::canvas::State<Message> for Bind<'a, T>
-where
- T: Drawable + std::fmt::Debug + 'a,
-{
- fn draw(&self, bounds: Size) -> Vec<Geometry> {
- vec![self.cache.draw(bounds, &self.input)]
- }
}
impl std::fmt::Debug for State {
diff --git a/wgpu/src/widget/canvas/drawable.rs b/wgpu/src/widget/canvas/drawable.rs
deleted file mode 100644
index 5209fa6f..00000000
--- a/wgpu/src/widget/canvas/drawable.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-use crate::canvas::Frame;
-
-/// A type that can be drawn on a [`Frame`].
-///
-/// [`Frame`]: struct.Frame.html
-pub trait Drawable {
- /// Draws the [`Drawable`] on the given [`Frame`].
- ///
- /// [`Drawable`]: trait.Drawable.html
- /// [`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)
- }
-}
-
-impl<T> Drawable for &T
-where
- T: Drawable,
-{
- fn draw(&self, frame: &mut Frame) {
- T::draw(self, frame)
- }
-}
-
-impl<T> Drawable for &[T]
-where
- T: Drawable,
-{
- fn draw(&self, frame: &mut Frame) {
- self.iter().for_each(|drawable| drawable.draw(frame));
- }
-}
diff --git a/wgpu/src/widget/canvas/state.rs b/wgpu/src/widget/canvas/program.rs
index ab433dd1..8e35fdfb 100644
--- a/wgpu/src/widget/canvas/state.rs
+++ b/wgpu/src/widget/canvas/program.rs
@@ -1,6 +1,6 @@
use crate::canvas::{Event, Geometry, Size};
-pub trait State<Message> {
+pub trait Program<Message> {
fn update(&mut self, _event: Event, _bounds: Size) -> Option<Message> {
None
}
@@ -8,9 +8,9 @@ pub trait State<Message> {
fn draw(&self, bounds: Size) -> Vec<Geometry>;
}
-impl<T, Message> State<Message> for &mut T
+impl<T, Message> Program<Message> for &mut T
where
- T: State<Message>,
+ T: Program<Message>,
{
fn update(&mut self, event: Event, bounds: Size) -> Option<Message> {
T::update(self, event, bounds)