From 092e187304c596f35b8ef9d7ca71850418d8a05d Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 25 Apr 2021 10:14:41 +0530 Subject: cache entire brush info --- src/app.rs | 7 ++++--- src/cache.rs | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index 66a27e3..23458f4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -86,7 +86,7 @@ impl<'ctx> AppState<'ctx> { pub fn cache(&self) { let mut cache = self.cache.borrow_mut(); *cache = Some(Cache { - last_brush_size: self.brush.size().unwrap_or(0), + last_brush: self.brush, }); } @@ -228,6 +228,7 @@ impl<'ctx> AppState<'ctx> { } } ModifyRecord::Invert => self.pixmap.invert(), + // TODO: use this kind of modify record on brush change ModifyRecord::Brush { old, new } => { match op_kind { OpKind::Undo => self.brush = old, @@ -765,7 +766,7 @@ impl<'ctx> AppState<'ctx> { self.cache .borrow() .as_ref() - .map(|c| c.last_brush_size) + .map(|c| c.last_brush.size().unwrap_or(0)) .unwrap_or(0), true, ); @@ -780,7 +781,7 @@ impl<'ctx> AppState<'ctx> { self.cache .borrow() .as_ref() - .map(|c| c.last_brush_size) + .map(|c| c.last_brush.size().unwrap_or(0)) .unwrap_or(0), ); } diff --git a/src/cache.rs b/src/cache.rs index 249eca9..f25d274 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,3 +1,5 @@ +use crate::brush::Brush; + pub struct Cache { - pub last_brush_size: u8, + pub last_brush: Brush, } -- cgit v1.2.3