summaryrefslogtreecommitdiffstats
path: root/wgpu/src/widget/canvas/layer/cache.rs
diff options
context:
space:
mode:
authorLibravatar Artur Sapek <me@artur.co>2020-03-05 22:05:05 -0700
committerLibravatar Artur Sapek <artur@lich.io>2020-03-06 22:01:21 -0700
commit1bb85556915bb00057ef2ee66a596592c292b15b (patch)
tree4a624fb4bc225ecb72b434176da69096411efda7 /wgpu/src/widget/canvas/layer/cache.rs
parent29219500b7144f31dbf50fcc64653f7d2ce806d0 (diff)
downloadiced-1bb85556915bb00057ef2ee66a596592c292b15b.tar.gz
iced-1bb85556915bb00057ef2ee66a596592c292b15b.tar.bz2
iced-1bb85556915bb00057ef2ee66a596592c292b15b.zip
implement text support in canvas widget
Diffstat (limited to 'wgpu/src/widget/canvas/layer/cache.rs')
-rw-r--r--wgpu/src/widget/canvas/layer/cache.rs25
1 files changed, 10 insertions, 15 deletions
diff --git a/wgpu/src/widget/canvas/layer/cache.rs b/wgpu/src/widget/canvas/layer/cache.rs
index 3071cce0..f05028da 100644
--- a/wgpu/src/widget/canvas/layer/cache.rs
+++ b/wgpu/src/widget/canvas/layer/cache.rs
@@ -1,12 +1,10 @@
use crate::{
canvas::{Drawable, Frame, Layer},
- triangle,
+ Primitive,
};
-use iced_native::Size;
-use std::cell::RefCell;
-use std::marker::PhantomData;
-use std::sync::Arc;
+use iced_native::{Point, Size};
+use std::{cell::RefCell, marker::PhantomData};
/// A simple cache that stores generated geometry to avoid recomputation.
///
@@ -24,10 +22,7 @@ pub struct Cache<T: Drawable> {
#[derive(Debug)]
enum State {
Empty,
- Filled {
- mesh: Arc<triangle::Mesh2D>,
- bounds: Size,
- },
+ Filled { bounds: Size, primitive: Primitive },
}
impl<T> Cache<T>
@@ -75,27 +70,27 @@ impl<'a, T> Layer for Bind<'a, T>
where
T: Drawable + std::fmt::Debug,
{
- fn draw(&self, current_bounds: Size) -> Arc<triangle::Mesh2D> {
+ fn draw(&self, origin: Point, current_bounds: Size) -> Primitive {
use std::ops::Deref;
- if let State::Filled { mesh, bounds } =
+ if let State::Filled { bounds, primitive } =
self.cache.state.borrow().deref()
{
if *bounds == current_bounds {
- return mesh.clone();
+ return primitive.clone();
}
}
let mut frame = Frame::new(current_bounds.width, current_bounds.height);
self.input.draw(&mut frame);
- let mesh = Arc::new(frame.into_mesh());
+ let primitive = frame.into_primitive(origin);
*self.cache.state.borrow_mut() = State::Filled {
- mesh: mesh.clone(),
bounds: current_bounds,
+ primitive: primitive.clone(),
};
- mesh
+ primitive
}
}