mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 10:58:04 +08:00
Refactor naming to deprecate "node graph frame" terminology (#1187)
This commit is contained in:
@@ -2,7 +2,7 @@ use crate::boolean_ops::composite_boolean_operation;
|
||||
use crate::intersection::Quad;
|
||||
use crate::layers::folder_layer::FolderLayer;
|
||||
use crate::layers::layer_info::{Layer, LayerData, LayerDataType, LayerDataTypeDiscriminant};
|
||||
use crate::layers::nodegraph_layer::{CachedOutputData, NodeGraphFrameLayer};
|
||||
use crate::layers::layer_layer::{CachedOutputData, LayerLayer};
|
||||
use crate::layers::shape_layer::ShapeLayer;
|
||||
use crate::layers::style::RenderData;
|
||||
use crate::{DocumentError, DocumentResponse, Operation};
|
||||
@@ -514,13 +514,13 @@ impl Document {
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::AddNodeGraphFrame {
|
||||
Operation::AddFrame {
|
||||
path,
|
||||
insert_index,
|
||||
transform,
|
||||
network,
|
||||
} => {
|
||||
let layer = Layer::new(LayerDataType::NodeGraphFrame(NodeGraphFrameLayer { network, ..Default::default() }), transform);
|
||||
let layer = Layer::new(LayerDataType::Layer(LayerLayer { network, ..Default::default() }), transform);
|
||||
|
||||
self.set_layer(&path, layer, insert_index)?;
|
||||
|
||||
@@ -694,11 +694,11 @@ impl Document {
|
||||
Operation::SetLayerBlobUrl { layer_path, blob_url, resolution: _ } => {
|
||||
let layer = self.layer_mut(&layer_path).unwrap_or_else(|_| panic!("Blob URL for invalid layer with path '{:?}'", layer_path));
|
||||
|
||||
let LayerDataType::NodeGraphFrame(node_graph_frame) = &mut layer.data else {
|
||||
panic!("Incorrectly trying to set the image blob URL for a layer that is not a NodeGraphFrame layer type");
|
||||
let LayerDataType::Layer(layer) = &mut layer.data else {
|
||||
panic!("Incorrectly trying to set the image blob URL for a layer that is not a 'Layer' layer type");
|
||||
};
|
||||
|
||||
node_graph_frame.cached_output_data = CachedOutputData::BlobURL(blob_url);
|
||||
layer.cached_output_data = CachedOutputData::BlobURL(blob_url);
|
||||
|
||||
self.mark_as_dirty(&layer_path)?;
|
||||
Some([vec![DocumentChanged, LayerChanged { path: layer_path.clone() }], update_thumbnails_upstream(&layer_path)].concat())
|
||||
@@ -706,9 +706,9 @@ impl Document {
|
||||
Operation::ClearBlobURL { path } => {
|
||||
let layer = self.layer_mut(&path).expect("Clearing node graph image for invalid layer");
|
||||
match &mut layer.data {
|
||||
LayerDataType::NodeGraphFrame(node_graph) => {
|
||||
if matches!(node_graph.cached_output_data, CachedOutputData::BlobURL(_)) {
|
||||
node_graph.cached_output_data = CachedOutputData::None;
|
||||
LayerDataType::Layer(layer) => {
|
||||
if matches!(layer.cached_output_data, CachedOutputData::BlobURL(_)) {
|
||||
layer.cached_output_data = CachedOutputData::None;
|
||||
}
|
||||
}
|
||||
e => panic!("Incorrectly trying to clear the blob URL for layer of type {}", LayerDataTypeDiscriminant::from(&*e)),
|
||||
@@ -737,8 +737,8 @@ impl Document {
|
||||
Some(vec![DocumentChanged, LayerChanged { path }])
|
||||
}
|
||||
Operation::SetVectorData { path, vector_data } => {
|
||||
if let LayerDataType::NodeGraphFrame(graph) = &mut self.layer_mut(&path)?.data {
|
||||
graph.cached_output_data = CachedOutputData::VectorPath(Box::new(vector_data));
|
||||
if let LayerDataType::Layer(layer) = &mut self.layer_mut(&path)?.data {
|
||||
layer.cached_output_data = CachedOutputData::VectorPath(Box::new(vector_data));
|
||||
}
|
||||
Some(Vec::new())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::blend_mode::BlendMode;
|
||||
use super::folder_layer::FolderLayer;
|
||||
use super::nodegraph_layer::NodeGraphFrameLayer;
|
||||
use super::layer_layer::LayerLayer;
|
||||
use super::shape_layer::ShapeLayer;
|
||||
use super::style::{PathStyle, RenderData};
|
||||
use crate::intersection::Quad;
|
||||
@@ -22,24 +22,24 @@ pub enum LayerDataType {
|
||||
Folder(FolderLayer),
|
||||
/// A layer that wraps a [ShapeLayer] struct.
|
||||
Shape(ShapeLayer),
|
||||
/// A layer that wraps an [NodeGraphFrameLayer] struct.
|
||||
NodeGraphFrame(NodeGraphFrameLayer),
|
||||
/// A layer that wraps an [LayerLayer] struct.
|
||||
Layer(LayerLayer),
|
||||
}
|
||||
|
||||
impl LayerDataType {
|
||||
pub fn inner(&self) -> &dyn LayerData {
|
||||
match self {
|
||||
LayerDataType::Shape(s) => s,
|
||||
LayerDataType::Folder(f) => f,
|
||||
LayerDataType::NodeGraphFrame(n) => n,
|
||||
LayerDataType::Shape(shape) => shape,
|
||||
LayerDataType::Folder(folder) => folder,
|
||||
LayerDataType::Layer(layer) => layer,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inner_mut(&mut self) -> &mut dyn LayerData {
|
||||
match self {
|
||||
LayerDataType::Shape(s) => s,
|
||||
LayerDataType::Folder(f) => f,
|
||||
LayerDataType::NodeGraphFrame(n) => n,
|
||||
LayerDataType::Shape(shape) => shape,
|
||||
LayerDataType::Folder(folder) => folder,
|
||||
LayerDataType::Layer(layer) => layer,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,8 +48,7 @@ impl LayerDataType {
|
||||
pub enum LayerDataTypeDiscriminant {
|
||||
Folder,
|
||||
Shape,
|
||||
Text,
|
||||
NodeGraphFrame,
|
||||
Layer,
|
||||
}
|
||||
|
||||
impl fmt::Display for LayerDataTypeDiscriminant {
|
||||
@@ -57,8 +56,7 @@ impl fmt::Display for LayerDataTypeDiscriminant {
|
||||
match self {
|
||||
LayerDataTypeDiscriminant::Folder => write!(f, "Folder"),
|
||||
LayerDataTypeDiscriminant::Shape => write!(f, "Shape"),
|
||||
LayerDataTypeDiscriminant::Text => write!(f, "Text"),
|
||||
LayerDataTypeDiscriminant::NodeGraphFrame => write!(f, "Layer"),
|
||||
LayerDataTypeDiscriminant::Layer => write!(f, "Layer"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +68,7 @@ impl From<&LayerDataType> for LayerDataTypeDiscriminant {
|
||||
match data {
|
||||
Folder(_) => LayerDataTypeDiscriminant::Folder,
|
||||
Shape(_) => LayerDataTypeDiscriminant::Shape,
|
||||
NodeGraphFrame(_) => LayerDataTypeDiscriminant::NodeGraphFrame,
|
||||
Layer(_) => LayerDataTypeDiscriminant::Layer,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,8 +81,6 @@ impl<'a> TryFrom<&'a mut Layer> for &'a mut Subpath {
|
||||
fn try_from(layer: &'a mut Layer) -> Result<&'a mut Subpath, Self::Error> {
|
||||
match &mut layer.data {
|
||||
LayerDataType::Shape(layer) => Ok(&mut layer.shape),
|
||||
// TODO Resolve converting text into a Subpath at the layer level
|
||||
// LayerDataType::Text(text) => Some(Subpath::new(path_to_shape.to_vec(), viewport_transform, true)),
|
||||
_ => Err("Did not find any shape data in the layer"),
|
||||
}
|
||||
}
|
||||
@@ -96,8 +92,6 @@ impl<'a> TryFrom<&'a Layer> for &'a Subpath {
|
||||
fn try_from(layer: &'a Layer) -> Result<&'a Subpath, Self::Error> {
|
||||
match &layer.data {
|
||||
LayerDataType::Shape(layer) => Ok(&layer.shape),
|
||||
// TODO Resolve converting text into a Subpath at the layer level
|
||||
// LayerDataType::Text(text) => Some(Subpath::new(path_to_shape.to_vec(), viewport_transform, true)),
|
||||
_ => Err("Did not find any shape data in the layer"),
|
||||
}
|
||||
}
|
||||
@@ -432,7 +426,7 @@ impl Layer {
|
||||
|
||||
pub fn as_vector_data(&self) -> Option<&VectorData> {
|
||||
match &self.data {
|
||||
LayerDataType::NodeGraphFrame(frame) => frame.as_vector_data(),
|
||||
LayerDataType::Layer(layer) => layer.as_vector_data(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -454,34 +448,34 @@ impl Layer {
|
||||
}
|
||||
|
||||
/// Get a mutable reference to the NodeNetwork
|
||||
/// This operation will fail if the [Layer type](Layer::data) is not `LayerDataType::NodeGraphFrame`.
|
||||
/// This operation will fail if the [Layer type](Layer::data) is not `LayerDataType::Layer`.
|
||||
pub fn as_node_graph_mut(&mut self) -> Result<&mut graph_craft::document::NodeNetwork, DocumentError> {
|
||||
match &mut self.data {
|
||||
LayerDataType::NodeGraphFrame(frame) => Ok(&mut frame.network),
|
||||
LayerDataType::Layer(layer) => Ok(&mut layer.network),
|
||||
_ => Err(DocumentError::NotNodeGraph),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a reference to the NodeNetwork
|
||||
/// This operation will fail if the [Layer type](Layer::data) is not `LayerDataType::NodeGraphFrame`.
|
||||
/// This operation will fail if the [Layer type](Layer::data) is not `LayerDataType::Layer`.
|
||||
pub fn as_node_graph(&self) -> Result<&graph_craft::document::NodeNetwork, DocumentError> {
|
||||
match &self.data {
|
||||
LayerDataType::NodeGraphFrame(frame) => Ok(&frame.network),
|
||||
LayerDataType::Layer(layer) => Ok(&layer.network),
|
||||
_ => Err(DocumentError::NotNodeGraph),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_graph_frame(&self) -> Result<&NodeGraphFrameLayer, DocumentError> {
|
||||
pub fn as_graph_frame(&self) -> Result<&LayerLayer, DocumentError> {
|
||||
match &self.data {
|
||||
LayerDataType::NodeGraphFrame(frame) => Ok(frame),
|
||||
LayerDataType::Layer(layer) => Ok(layer),
|
||||
_ => Err(DocumentError::NotNodeGraph),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn style(&self) -> Result<&PathStyle, DocumentError> {
|
||||
match &self.data {
|
||||
LayerDataType::Shape(s) => Ok(&s.style),
|
||||
LayerDataType::NodeGraphFrame(t) => t.as_vector_data().map(|vector| &vector.style).ok_or(DocumentError::NotShape),
|
||||
LayerDataType::Shape(shape) => Ok(&shape.style),
|
||||
LayerDataType::Layer(layer) => layer.as_vector_data().map(|vector| &vector.style).ok_or(DocumentError::NotShape),
|
||||
_ => Err(DocumentError::NotShape),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ pub enum CachedOutputData {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
|
||||
pub struct NodeGraphFrameLayer {
|
||||
pub struct LayerLayer {
|
||||
/// The document node network that this layer contains
|
||||
pub network: graph_craft::document::NodeNetwork,
|
||||
|
||||
@@ -26,7 +26,7 @@ pub struct NodeGraphFrameLayer {
|
||||
pub cached_output_data: CachedOutputData,
|
||||
}
|
||||
|
||||
impl LayerData for NodeGraphFrameLayer {
|
||||
impl LayerData for LayerLayer {
|
||||
fn render(&mut self, svg: &mut String, svg_defs: &mut String, transforms: &mut Vec<DAffine2>, render_data: &RenderData) -> bool {
|
||||
let transform = self.transform(transforms, render_data.view_mode);
|
||||
let inverse = transform.inverse();
|
||||
@@ -121,7 +121,7 @@ impl LayerData for NodeGraphFrameLayer {
|
||||
}
|
||||
}
|
||||
|
||||
impl NodeGraphFrameLayer {
|
||||
impl LayerLayer {
|
||||
pub fn transform(&self, transforms: &[DAffine2], mode: ViewMode) -> DAffine2 {
|
||||
let start = match mode {
|
||||
ViewMode::Outline => 0,
|
||||
@@ -4,7 +4,7 @@
|
||||
//! There are currently these different types of layers:
|
||||
//! * [Folder layers](folder_layer::FolderLayer), which encapsulate sub-layers
|
||||
//! * [Shape layers](shape_layer::ShapeLayer), which contain generic SVG [`<path>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path)s
|
||||
//! * [Node Graph layers](nodegraph_layer::NodegraphLayer), which contain a node graph frame
|
||||
//! * [Layer layers](layer_layer::NodegraphLayer), which contain a node graph layer
|
||||
//!
|
||||
//! Refer to the module-level documentation for detailed information on each layer.
|
||||
//!
|
||||
@@ -21,7 +21,7 @@ pub mod folder_layer;
|
||||
/// Contains the base [Layer](layer_info::Layer) type, an abstraction over the different types of layers.
|
||||
pub mod layer_info;
|
||||
/// Contains the [NodegraphLayer](nodegraph_layer::NodegraphLayer) type that contains a node graph.
|
||||
pub mod nodegraph_layer;
|
||||
pub mod layer_layer;
|
||||
// TODO: Remove shape layers after rewriting the overlay system
|
||||
/// Contains the [ShapeLayer](shape_layer::ShapeLayer) type, a generic SVG element defined using Bezier paths.
|
||||
pub mod shape_layer;
|
||||
|
||||
@@ -36,7 +36,7 @@ pub enum Operation {
|
||||
transform: [f64; 6],
|
||||
style: style::PathStyle,
|
||||
},
|
||||
AddNodeGraphFrame {
|
||||
AddFrame {
|
||||
path: Vec<LayerId>,
|
||||
insert_index: isize,
|
||||
transform: [f64; 6],
|
||||
|
||||
Reference in New Issue
Block a user