summaryrefslogtreecommitdiffstats
path: root/wgpu/src/widget/canvas/layer/cache.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-03-09 00:48:51 +0100
committerLibravatar GitHub <noreply@github.com>2020-03-09 00:48:51 +0100
commit5a91b52ef4066701d82a897b44a3f90412f210d2 (patch)
tree13d58d144c3ddf05e44c72557bf2af2194207bf3 /wgpu/src/widget/canvas/layer/cache.rs
parent29219500b7144f31dbf50fcc64653f7d2ce806d0 (diff)
parentb4f970ee7317297615848cd12f422c0cd2889f60 (diff)
downloadiced-5a91b52ef4066701d82a897b44a3f90412f210d2.tar.gz
iced-5a91b52ef4066701d82a897b44a3f90412f210d2.tar.bz2
iced-5a91b52ef4066701d82a897b44a3f90412f210d2.zip
Merge pull request #214 from artursapek/artur/canvas-text
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.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/wgpu/src/widget/canvas/layer/cache.rs b/wgpu/src/widget/canvas/layer/cache.rs
index 3071cce0..6b69f01e 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 std::{cell::RefCell, marker::PhantomData, sync::Arc};
/// A simple cache that stores generated geometry to avoid recomputation.
///
@@ -25,8 +23,8 @@ pub struct Cache<T: Drawable> {
enum State {
Empty,
Filled {
- mesh: Arc<triangle::Mesh2D>,
bounds: Size,
+ primitive: Arc<Primitive>,
},
}
@@ -75,27 +73,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, current_bounds: Size) -> Arc<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 = Arc::new(frame.into_primitive());
*self.cache.state.borrow_mut() = State::Filled {
- mesh: mesh.clone(),
bounds: current_bounds,
+ primitive: primitive.clone(),
};
- mesh
+ primitive
}
}