mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 14:48:12 +08:00
Populate layer entry cache (#437)
* Populate layer entry cache * Serialize the DocumentMessageHandler * Fix restoring of collapsed/expanded state, add iter impl for Layer, and clean up layer_data() functions * Fixed bug with CreateEmptyLayer revealed by test Co-authored-by: Keavon Chambers <keavon@keavon.com> Co-authored-by: otdavies <oliver@psyfer.io>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
otdavies
parent
3eb915eaee
commit
fd1ddfc41e
@@ -105,6 +105,10 @@ impl Layer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> LayerIter<'_> {
|
||||
LayerIter { stack: vec![self] }
|
||||
}
|
||||
|
||||
pub fn render(&mut self, transforms: &mut Vec<DAffine2>, view_mode: ViewMode) -> &str {
|
||||
if !self.visible {
|
||||
return "";
|
||||
@@ -179,3 +183,40 @@ impl Clone for Layer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a Layer {
|
||||
type Item = &'a Layer;
|
||||
type IntoIter = LayerIter<'a>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LayerIter<'a> {
|
||||
pub stack: Vec<&'a Layer>,
|
||||
}
|
||||
|
||||
impl Default for LayerIter<'_> {
|
||||
fn default() -> Self {
|
||||
Self { stack: vec![] }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for LayerIter<'a> {
|
||||
type Item = &'a Layer;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.stack.pop() {
|
||||
Some(layer) => {
|
||||
if let LayerDataType::Folder(folder) = &layer.data {
|
||||
let layers = folder.layers();
|
||||
self.stack.extend(layers);
|
||||
};
|
||||
Some(layer)
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user