Skip to content

Commit

Permalink
impl default for canvas cache
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Apr 8, 2020
1 parent ad0a6c4 commit 6e7769b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/clock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Application for Clock {
(
Clock {
now: chrono::Local::now().into(),
clock: canvas::layer::Cache::new(),
clock: Default::default(),
},
Command::none(),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/solar_system/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Application for SolarSystem {
(
SolarSystem {
state: State::new(),
solar_system: canvas::layer::Cache::new(),
solar_system: Default::default(),
},
Command::none(),
)
Expand Down
31 changes: 24 additions & 7 deletions wgpu/src/widget/canvas/layer/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ use crate::{
use iced_native::Size;
use std::{cell::RefCell, marker::PhantomData, sync::Arc};

enum State {
Empty,
Filled {
bounds: Size,
primitive: Arc<Primitive>,
},
}

impl Default for State {
fn default() -> Self {
State::Empty
}
}
/// A simple cache that stores generated geometry to avoid recomputation.
///
/// A [`Cache`] will not redraw its geometry unless the dimensions of its layer
Expand All @@ -19,12 +32,16 @@ pub struct Cache<T: Drawable> {
state: RefCell<State>,
}

enum State {
Empty,
Filled {
bounds: Size,
primitive: Arc<Primitive>,
},
impl<T> Default for Cache<T>
where
T: Drawable,
{
fn default() -> Self {
Self {
input: PhantomData,
state: Default::default(),
}
}
}

impl<T> Cache<T>
Expand All @@ -37,7 +54,7 @@ where
pub fn new() -> Self {
Cache {
input: PhantomData,
state: RefCell::new(State::Empty),
state: Default::default(),
}
}

Expand Down

0 comments on commit 6e7769b

Please sign in to comment.