mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 00:48:13 +08:00
Refactor the node macro and simply most of the node implementations (#1942)
* Add support structure for new node macro to gcore * Fix compile issues and code generation * Implement new node_fn macro * Implement property translation * Fix NodeIO type generation * Start translating math nodes * Move node implementation to outer scope to allow usage of local imports * Add expose attribute to allow controlling the parameter exposure * Add rust analyzer support for #[implementations] attribute * Migrate logic nodes * Handle where clause properly * Implement argument ident pattern preservation * Implement adjustment layer mapping * Fix node registry types * Fix module paths * Improve demo artwork comptibility * Improve macro error reporting * Fix handling of impl node implementations * Fix nodeio type computation * Fix opacity node and graph type resolution * Fix loading of demo artworks * Fix eslint * Fix typo in macro test * Remove node definitions for Adjustment Nodes * Fix type alias property generation and make adjustments footprint aware * Convert vector nodes * Implement path overrides * Fix stroke node * Fix painted dreams * Implement experimental type level specialization * Fix poisson disk sampling -> all demo artworks should work again * Port text node + make node macro more robust by implementing lifetime substitution * Fix vector node tests * Fix red dress demo + ci * Fix clippy warnings * Code review * Fix primary input issues * Improve math nodes and audit others * Set no_properties when no automatic properties are derived * Port vector generator nodes (could not derive all definitions yet) * Various QA changes and add min/max/mode_range to number parameters * Add min and max for f64 and u32 * Convert gpu nodes and clean up unused nodes * Partially port transform node * Allow implementations on call arg * Port path modify node * Start porting graphic element nodes * Transform nodes in graphic_element.rs * Port brush node * Port nodes in wasm_executior * Rename node macro * Fix formatting * Fix Mandelbrot node * Formatting * Fix Load Image and Load Resource nodes, add scope input to node macro * Remove unnecessary underscores * Begin attemping to make nodes resolution-aware * Infer a generic manual compositon type on generic call arg * Various fixes and work towards merging * Final changes for merge! * Fix tests, probably * More free line removals! --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
ca0d102296
commit
e352c7fa71
@@ -1,12 +1,11 @@
|
||||
use crate::application_io::TextureFrame;
|
||||
use crate::raster::{BlendMode, ImageFrame};
|
||||
use crate::transform::{Footprint, Transform, TransformMut};
|
||||
use crate::transform::{ApplyTransform, Footprint, Transform, TransformMut};
|
||||
use crate::uuid::NodeId;
|
||||
use crate::vector::VectorData;
|
||||
use crate::{Color, Node};
|
||||
use crate::Color;
|
||||
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
use node_macro::node_fn;
|
||||
use dyn_any::DynAny;
|
||||
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use glam::{DAffine2, IVec2};
|
||||
@@ -227,27 +226,20 @@ impl ArtboardGroup {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_artboard(&mut self, artboard: Artboard, node_id: Option<NodeId>) {
|
||||
fn append_artboard(&mut self, artboard: Artboard, node_id: Option<NodeId>) {
|
||||
self.artboards.push((artboard, node_id));
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ConstructLayerNode<Stack, GraphicElement, NodePath> {
|
||||
stack: Stack,
|
||||
graphic_element: GraphicElement,
|
||||
node_path: NodePath,
|
||||
}
|
||||
|
||||
#[node_fn(ConstructLayerNode)]
|
||||
async fn construct_layer<Data: Into<GraphicElement> + Send>(
|
||||
footprint: crate::transform::Footprint,
|
||||
mut stack: impl Node<crate::transform::Footprint, Output = GraphicGroup>,
|
||||
graphic_element: impl Node<crate::transform::Footprint, Output = Data>,
|
||||
#[node_macro::node(category(""))]
|
||||
async fn layer<F: 'n + Copy + Send>(
|
||||
#[implementations((), Footprint)] footprint: F,
|
||||
#[implementations(((), GraphicGroup), (Footprint, GraphicGroup))] stack: impl Node<F, Output = GraphicGroup>,
|
||||
#[implementations(((), GraphicElement), (Footprint, GraphicElement))] graphic_element: impl Node<F, Output = GraphicElement>,
|
||||
node_path: Vec<NodeId>,
|
||||
) -> GraphicGroup {
|
||||
let graphic_element = self.graphic_element.eval(footprint).await;
|
||||
let mut stack = self.stack.eval(footprint).await;
|
||||
let mut element: GraphicElement = graphic_element.into();
|
||||
let mut element = graphic_element.eval(footprint).await;
|
||||
let mut stack = stack.eval(footprint).await;
|
||||
if stack.transform.matrix2.determinant() != 0. {
|
||||
*element.transform_mut() = stack.transform.inverse() * element.transform();
|
||||
} else {
|
||||
@@ -261,41 +253,54 @@ async fn construct_layer<Data: Into<GraphicElement> + Send>(
|
||||
stack
|
||||
}
|
||||
|
||||
pub struct ToGraphicElementNode {}
|
||||
|
||||
#[node_fn(ToGraphicElementNode)]
|
||||
fn to_graphic_element<Data: Into<GraphicElement>>(data: Data) -> GraphicElement {
|
||||
data.into()
|
||||
#[node_macro::node(category("Debug"))]
|
||||
async fn to_element<F: 'n + Send, Data: Into<GraphicElement> + 'n>(
|
||||
#[implementations((), (), (), (), Footprint)] footprint: F,
|
||||
#[implementations(
|
||||
((), VectorData),
|
||||
((), ImageFrame<Color>),
|
||||
((), GraphicGroup),
|
||||
((), TextureFrame),
|
||||
(Footprint, VectorData),
|
||||
(Footprint, ImageFrame<Color>),
|
||||
(Footprint, GraphicGroup),
|
||||
(Footprint, TextureFrame),
|
||||
)]
|
||||
data: impl Node<F, Output = Data>,
|
||||
) -> GraphicElement {
|
||||
data.eval(footprint).await.into()
|
||||
}
|
||||
|
||||
pub struct ToGraphicGroupNode {}
|
||||
|
||||
#[node_fn(ToGraphicGroupNode)]
|
||||
fn to_graphic_group<Data: Into<GraphicGroup>>(data: Data) -> GraphicGroup {
|
||||
data.into()
|
||||
#[node_macro::node(category("General"))]
|
||||
async fn to_group<F: 'n + Send, Data: Into<GraphicGroup> + 'n>(
|
||||
#[implementations((), (), (), (), Footprint)] footprint: F,
|
||||
#[implementations(
|
||||
((), VectorData),
|
||||
((), ImageFrame<Color>),
|
||||
((), GraphicGroup),
|
||||
((), TextureFrame),
|
||||
(Footprint, VectorData),
|
||||
(Footprint, ImageFrame<Color>),
|
||||
(Footprint, GraphicGroup),
|
||||
(Footprint, TextureFrame),
|
||||
)]
|
||||
element: impl Node<F, Output = Data>,
|
||||
) -> GraphicGroup {
|
||||
element.eval(footprint).await.into()
|
||||
}
|
||||
|
||||
pub struct ConstructArtboardNode<Contents, Label, Location, Dimensions, Background, Clip> {
|
||||
contents: Contents,
|
||||
label: Label,
|
||||
location: Location,
|
||||
dimensions: Dimensions,
|
||||
background: Background,
|
||||
clip: Clip,
|
||||
}
|
||||
|
||||
#[node_fn(ConstructArtboardNode)]
|
||||
async fn construct_artboard(
|
||||
mut footprint: Footprint,
|
||||
contents: impl Node<Footprint, Output = GraphicGroup>,
|
||||
#[node_macro::node(category(""))]
|
||||
async fn to_artboard<F: 'n + Copy + Send + ApplyTransform>(
|
||||
#[implementations((), Footprint)] mut footprint: F,
|
||||
#[implementations(((), GraphicGroup), (Footprint, GraphicGroup))] contents: impl Node<F, Output = GraphicGroup>,
|
||||
label: String,
|
||||
location: IVec2,
|
||||
dimensions: IVec2,
|
||||
background: Color,
|
||||
clip: bool,
|
||||
) -> Artboard {
|
||||
footprint.transform *= DAffine2::from_translation(location.as_dvec2());
|
||||
let graphic_group = self.contents.eval(footprint).await;
|
||||
footprint.apply_transform(&DAffine2::from_translation(location.as_dvec2()));
|
||||
let graphic_group = contents.eval(footprint).await;
|
||||
|
||||
Artboard {
|
||||
graphic_group,
|
||||
@@ -306,25 +311,19 @@ async fn construct_artboard(
|
||||
clip,
|
||||
}
|
||||
}
|
||||
pub struct AddArtboardNode<ArtboardGroup, Artboard, NodePath> {
|
||||
artboards: ArtboardGroup,
|
||||
artboard: Artboard,
|
||||
node_path: NodePath,
|
||||
}
|
||||
|
||||
#[node_fn(AddArtboardNode)]
|
||||
async fn add_artboard<Data: Into<Artboard> + Send>(
|
||||
footprint: Footprint,
|
||||
artboards: impl Node<Footprint, Output = ArtboardGroup>,
|
||||
artboard: impl Node<Footprint, Output = Data>,
|
||||
#[node_macro::node(category(""))]
|
||||
async fn append_artboard<F: 'n + Copy + Send>(
|
||||
#[implementations((), Footprint)] footprint: F,
|
||||
#[implementations(((), ArtboardGroup), (Footprint, ArtboardGroup))] artboards: impl Node<F, Output = ArtboardGroup>,
|
||||
#[implementations(((), Artboard), (Footprint, Artboard))] artboard: impl Node<F, Output = Artboard>,
|
||||
node_path: Vec<NodeId>,
|
||||
) -> ArtboardGroup {
|
||||
let artboard = self.artboard.eval(footprint).await;
|
||||
let mut artboards = self.artboards.eval(footprint).await;
|
||||
let artboard = artboard.eval(footprint).await;
|
||||
let mut artboards = artboards.eval(footprint).await;
|
||||
|
||||
// Get the penultimate element of the node path, or None if the path is too short
|
||||
let encapsulating_node_id = node_path.get(node_path.len().wrapping_sub(2)).copied();
|
||||
artboards.add_artboard(artboard.into(), encapsulating_node_id);
|
||||
artboards.append_artboard(artboard, encapsulating_node_id);
|
||||
|
||||
artboards
|
||||
}
|
||||
@@ -369,6 +368,7 @@ trait ToGraphicElement: Into<GraphicElement> {}
|
||||
|
||||
impl ToGraphicElement for VectorData {}
|
||||
impl ToGraphicElement for ImageFrame<Color> {}
|
||||
impl ToGraphicElement for TextureFrame {}
|
||||
|
||||
impl<T> From<T> for GraphicGroup
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user