Skip to content

Allow transforming layers #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions core/document/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ impl Document {
Ok(root)
}

/// Returns a reference to the layer or folder at the path. Does not return an error for root
pub fn document_layer(&mut self, path: &[LayerId]) -> Result<&Layer, DocumentError> {
if path.is_empty() {
return Ok(&self.root);
}
let (path, id) = split_path(path)?;
self.document_folder(path)?.as_folder()?.layer(id).ok_or(DocumentError::LayerNotFound)
}

/// Returns a mutable reference to the layer or folder at the path. Does not return an error for root
pub fn document_layer_mut(&mut self, path: &[LayerId]) -> Result<&mut Layer, DocumentError> {
if path.is_empty() {
return Ok(&mut self.root);
}
let (path, id) = split_path(path)?;
self.document_folder_mut(path)?.as_folder_mut()?.layer_mut(id).ok_or(DocumentError::LayerNotFound)
}

/// Returns a reference to the layer struct at the specified `path`.
pub fn layer(&self, path: &[LayerId]) -> Result<&Layer, DocumentError> {
let (path, id) = split_path(path)?;
Expand Down Expand Up @@ -291,10 +309,11 @@ impl Document {
None
}
Operation::TransformLayer { path, transform } => {
let transform = self.root.transform * DAffine2::from_cols_array(&transform);
let layer = self.document_folder_mut(path).unwrap();
let layer = self.document_layer_mut(path).unwrap();
let transform = DAffine2::from_cols_array(&transform) * layer.transform;
layer.transform = transform;
layer.cache_dirty = true;
self.root.cache_dirty = true;
Some(vec![DocumentResponse::DocumentChanged])
}
Operation::DiscardWorkingFolder => {
Expand Down