From a5bea53db29970b2aeb42ff7b23f151b13b6f9b3 Mon Sep 17 00:00:00 2001 From: akshay1992kalbhor Date: Tue, 18 May 2021 22:25:05 +0530 Subject: [PATCH] Make the show/hide layer buttons work (#118) (#127) --- core/document/src/document.rs | 8 ++++++++ core/document/src/operation.rs | 3 +++ core/editor/src/dispatcher/mod.rs | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/document/src/document.rs b/core/document/src/document.rs index d5dcc4a2..0216f0b0 100644 --- a/core/document/src/document.rs +++ b/core/document/src/document.rs @@ -300,6 +300,14 @@ impl Document { let children = self.layer_panel(path.as_slice())?; Some(vec![DocumentResponse::DocumentChanged, DocumentResponse::ExpandFolder { path, children }]) } + Operation::ToggleVisibility { path } => { + let _ = self.layer_mut(&path).map(|layer| { + layer.visible = !layer.visible; + layer.cache_dirty = true; + }); + let children = self.layer_panel(&path.as_slice()[..path.len() - 1])?; + Some(vec![DocumentResponse::ExpandFolder { path: vec![], children }]) + } }; Ok(responses) } diff --git a/core/document/src/operation.rs b/core/document/src/operation.rs index 01cc3479..725127d5 100644 --- a/core/document/src/operation.rs +++ b/core/document/src/operation.rs @@ -68,4 +68,7 @@ pub enum Operation { DiscardWorkingFolder, ClearWorkingFolder, CommitTransaction, + ToggleVisibility { + path: Vec, + }, } diff --git a/core/editor/src/dispatcher/mod.rs b/core/editor/src/dispatcher/mod.rs index 83485c19..6483b106 100644 --- a/core/editor/src/dispatcher/mod.rs +++ b/core/editor/src/dispatcher/mod.rs @@ -37,7 +37,11 @@ impl Dispatcher { editor_state.tool_state.document_tool_data.mouse_state.position = *pos; } Event::ToggleLayerVisibility(path) => { - log::debug!("Toggling layer visibility not yet implemented in the Editor Library"); + let document_responses = self.dispatch_operations(&mut editor_state.document, vec![Operation::ToggleVisibility { path: path.clone() }]); + self.dispatch_response(ToolResponse::UpdateCanvas { + document: editor_state.document.render_root(), + }); + self.dispatch_responses(document_responses); } Event::KeyUp(_key) => (), Event::KeyDown(key) => {