Refactor naming to deprecate "node graph frame" terminology (#1187)

This commit is contained in:
Keavon Chambers
2023-04-28 01:30:47 -07:00
committed by GitHub
parent fce81d0dfc
commit 8ddaafc614
35 changed files with 286 additions and 313 deletions

View File

@@ -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),
}
}

View File

@@ -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,

View File

@@ -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;