Merge branch 'master' into feature/panes-widget
This commit is contained in:
commit
e4fbca59b4
15 changed files with 231 additions and 94 deletions
|
|
@ -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.
|
||||
///
|
||||
|
|
@ -24,8 +22,8 @@ pub struct Cache<T: Drawable> {
|
|||
enum State {
|
||||
Empty,
|
||||
Filled {
|
||||
mesh: Arc<triangle::Mesh2D>,
|
||||
bounds: Size,
|
||||
primitive: Arc<Primitive>,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -74,28 +72,28 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue