mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 05:58:12 +08:00
Add the document graph (#1217)
* Thumbnails for the layer node * Raster node graph frames * Downscale to a random resolution * Cleanup and bug fixes * Generate paths before duplicating outputs * Fix stable id test * Add a document node graph * Fix merge conflict --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
d45e7cb755
commit
44d16c42f5
@@ -26,6 +26,8 @@ pub struct Document {
|
||||
/// This identifier is not a hash and is not guaranteed to be equal for equivalent documents.
|
||||
#[serde(skip)]
|
||||
pub state_identifier: DefaultHasher,
|
||||
#[serde(default)]
|
||||
pub document_network: graph_craft::document::NodeNetwork,
|
||||
}
|
||||
|
||||
impl PartialEq for Document {
|
||||
@@ -39,6 +41,19 @@ impl Default for Document {
|
||||
Self {
|
||||
root: Layer::new(LayerDataType::Folder(FolderLayer::default()), DAffine2::IDENTITY.to_cols_array()),
|
||||
state_identifier: DefaultHasher::new(),
|
||||
document_network: {
|
||||
use graph_craft::document::{value::TaggedValue, NodeInput, NodeNetwork};
|
||||
let mut network = NodeNetwork::default();
|
||||
let node = graph_craft::document::DocumentNode {
|
||||
name: "Output".into(),
|
||||
inputs: vec![NodeInput::value(TaggedValue::GraphicGroup(Default::default()), true)],
|
||||
implementation: graph_craft::document::DocumentNodeImplementation::Unresolved("graphene_core::ops::IdNode".into()),
|
||||
metadata: graph_craft::document::DocumentNodeMetadata::position((8, 4)),
|
||||
..Default::default()
|
||||
};
|
||||
network.push_node(node, false);
|
||||
network
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,6 +253,24 @@ impl Layer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a child layer of this layer, by a path. If the layer with id 1 is inside a folder with id 0, the path will be [0, 1].
|
||||
pub fn child(&self, path: &[LayerId]) -> Option<&Layer> {
|
||||
let mut layer = self;
|
||||
for id in path {
|
||||
layer = layer.as_folder().ok()?.layer(*id)?;
|
||||
}
|
||||
Some(layer)
|
||||
}
|
||||
|
||||
/// Gets a child layer of this layer, by a path. If the layer with id 1 is inside a folder with id 0, the path will be [0, 1].
|
||||
pub fn child_mut(&mut self, path: &[LayerId]) -> Option<&mut Layer> {
|
||||
let mut layer = self;
|
||||
for id in path {
|
||||
layer = layer.as_folder_mut().ok()?.layer_mut(*id)?;
|
||||
}
|
||||
Some(layer)
|
||||
}
|
||||
|
||||
/// Iterate over the layers encapsulated by this layer.
|
||||
/// If the [Layer type](Layer::data) is not a folder, the only item in the iterator will be the layer itself.
|
||||
/// If the [Layer type](Layer::data) wraps a [Folder](LayerDataType::Folder), the iterator will recursively yield all the layers contained in the folder as well as potential sub-folders.
|
||||
|
||||
Reference in New Issue
Block a user