impl default for canvas cache
This commit is contained in:
parent
ad0a6c4c10
commit
6e7769b65d
@ -29,7 +29,7 @@ impl Application for Clock {
|
|||||||
(
|
(
|
||||||
Clock {
|
Clock {
|
||||||
now: chrono::Local::now().into(),
|
now: chrono::Local::now().into(),
|
||||||
clock: canvas::layer::Cache::new(),
|
clock: Default::default(),
|
||||||
},
|
},
|
||||||
Command::none(),
|
Command::none(),
|
||||||
)
|
)
|
||||||
|
@ -39,7 +39,7 @@ impl Application for SolarSystem {
|
|||||||
(
|
(
|
||||||
SolarSystem {
|
SolarSystem {
|
||||||
state: State::new(),
|
state: State::new(),
|
||||||
solar_system: canvas::layer::Cache::new(),
|
solar_system: Default::default(),
|
||||||
},
|
},
|
||||||
Command::none(),
|
Command::none(),
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,19 @@ use crate::{
|
|||||||
use iced_native::Size;
|
use iced_native::Size;
|
||||||
use std::{cell::RefCell, marker::PhantomData, sync::Arc};
|
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 simple cache that stores generated geometry to avoid recomputation.
|
||||||
///
|
///
|
||||||
/// A [`Cache`] will not redraw its geometry unless the dimensions of its layer
|
/// A [`Cache`] will not redraw its geometry unless the dimensions of its layer
|
||||||
@ -19,12 +32,16 @@ pub struct Cache<T: Drawable> {
|
|||||||
state: RefCell<State>,
|
state: RefCell<State>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum State {
|
impl<T> Default for Cache<T>
|
||||||
Empty,
|
where
|
||||||
Filled {
|
T: Drawable,
|
||||||
bounds: Size,
|
{
|
||||||
primitive: Arc<Primitive>,
|
fn default() -> Self {
|
||||||
},
|
Self {
|
||||||
|
input: PhantomData,
|
||||||
|
state: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Cache<T>
|
impl<T> Cache<T>
|
||||||
@ -37,7 +54,7 @@ where
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Cache {
|
Cache {
|
||||||
input: PhantomData,
|
input: PhantomData,
|
||||||
state: RefCell::new(State::Empty),
|
state: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user