mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-01 21:18:12 +08:00
Allow transforming layers (#244)
* Allow transforming layers * Add document_layer function to return non mut
This commit is contained in:
committed by
Keavon Chambers
parent
2d2954d045
commit
764c0fe0f2
@@ -140,6 +140,24 @@ impl Document {
|
|||||||
Ok(root)
|
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`.
|
/// Returns a reference to the layer struct at the specified `path`.
|
||||||
pub fn layer(&self, path: &[LayerId]) -> Result<&Layer, DocumentError> {
|
pub fn layer(&self, path: &[LayerId]) -> Result<&Layer, DocumentError> {
|
||||||
let (path, id) = split_path(path)?;
|
let (path, id) = split_path(path)?;
|
||||||
@@ -291,10 +309,11 @@ impl Document {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
Operation::TransformLayer { path, transform } => {
|
Operation::TransformLayer { path, transform } => {
|
||||||
let transform = self.root.transform * DAffine2::from_cols_array(&transform);
|
let layer = self.document_layer_mut(path).unwrap();
|
||||||
let layer = self.document_folder_mut(path).unwrap();
|
let transform = DAffine2::from_cols_array(&transform) * layer.transform;
|
||||||
layer.transform = transform;
|
layer.transform = transform;
|
||||||
layer.cache_dirty = true;
|
layer.cache_dirty = true;
|
||||||
|
self.root.cache_dirty = true;
|
||||||
Some(vec![DocumentResponse::DocumentChanged])
|
Some(vec![DocumentResponse::DocumentChanged])
|
||||||
}
|
}
|
||||||
Operation::DiscardWorkingFolder => {
|
Operation::DiscardWorkingFolder => {
|
||||||
|
|||||||
Reference in New Issue
Block a user