Rename GraphicElement -> Graphic and trait GraphicElementRendered -> Render (#2987)

This commit is contained in:
Keavon Chambers
2025-08-03 16:15:02 -07:00
committed by GitHub
parent 9a4a7dee80
commit 5637f01845
30 changed files with 243 additions and 245 deletions

View File

@@ -6,7 +6,7 @@ use crate::table::{Table, TableRow};
use crate::transform::TransformMut;
use crate::uuid::NodeId;
use crate::vector::VectorData;
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicElement, OwnedContextImpl};
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, Graphic, OwnedContextImpl};
use dyn_any::DynAny;
use glam::{DAffine2, DVec2, IVec2};
use std::hash::Hash;
@@ -14,7 +14,7 @@ use std::hash::Hash;
/// Some [`ArtboardData`] with some optional clipping bounds that can be exported.
#[derive(Clone, Debug, Hash, PartialEq, DynAny, serde::Serialize, serde::Deserialize)]
pub struct Artboard {
pub graphic_group: Table<GraphicElement>,
pub graphic_group: Table<Graphic>,
pub label: String,
pub location: IVec2,
pub dimensions: IVec2,
@@ -95,10 +95,10 @@ impl BoundingBox for Table<Artboard> {
}
#[node_macro::node(category(""))]
async fn to_artboard<Data: Into<Table<GraphicElement>> + 'n>(
async fn to_artboard<Data: Into<Table<Graphic>> + 'n>(
ctx: impl ExtractAll + CloneVarArgs + Ctx,
#[implementations(
Context -> Table<GraphicElement>,
Context -> Table<Graphic>,
Context -> Table<VectorData>,
Context -> Table<Raster<CPU>>,
Context -> Table<Raster<GPU>>,

View File

@@ -2,7 +2,7 @@ use crate::raster_types::{CPU, Raster};
use crate::registry::types::Percentage;
use crate::table::Table;
use crate::vector::VectorData;
use crate::{BlendMode, Color, Ctx, GraphicElement};
use crate::{BlendMode, Color, Ctx, Graphic};
pub(super) trait MultiplyAlpha {
fn multiply_alpha(&mut self, factor: f64);
@@ -20,7 +20,7 @@ impl MultiplyAlpha for Table<VectorData> {
}
}
}
impl MultiplyAlpha for Table<GraphicElement> {
impl MultiplyAlpha for Table<Graphic> {
fn multiply_alpha(&mut self, factor: f64) {
for row in self.iter_mut() {
row.alpha_blending.opacity *= factor as f32;
@@ -50,7 +50,7 @@ impl MultiplyFill for Table<VectorData> {
}
}
}
impl MultiplyFill for Table<GraphicElement> {
impl MultiplyFill for Table<Graphic> {
fn multiply_fill(&mut self, factor: f64) {
for row in self.iter_mut() {
row.alpha_blending.fill *= factor as f32;
@@ -76,7 +76,7 @@ impl SetBlendMode for Table<VectorData> {
}
}
}
impl SetBlendMode for Table<GraphicElement> {
impl SetBlendMode for Table<Graphic> {
fn set_blend_mode(&mut self, blend_mode: BlendMode) {
for row in self.iter_mut() {
row.alpha_blending.blend_mode = blend_mode;
@@ -102,7 +102,7 @@ impl SetClip for Table<VectorData> {
}
}
}
impl SetClip for Table<GraphicElement> {
impl SetClip for Table<Graphic> {
fn set_clip(&mut self, clip: bool) {
for row in self.iter_mut() {
row.alpha_blending.clip = clip;
@@ -121,7 +121,7 @@ impl SetClip for Table<Raster<CPU>> {
fn blend_mode<T: SetBlendMode>(
_: impl Ctx,
#[implementations(
Table<GraphicElement>,
Table<Graphic>,
Table<VectorData>,
Table<Raster<CPU>>,
)]
@@ -137,7 +137,7 @@ fn blend_mode<T: SetBlendMode>(
fn opacity<T: MultiplyAlpha>(
_: impl Ctx,
#[implementations(
Table<GraphicElement>,
Table<Graphic>,
Table<VectorData>,
Table<Raster<CPU>>,
)]
@@ -153,7 +153,7 @@ fn opacity<T: MultiplyAlpha>(
fn blending<T: SetBlendMode + MultiplyAlpha + MultiplyFill + SetClip>(
_: impl Ctx,
#[implementations(
Table<GraphicElement>,
Table<Graphic>,
Table<VectorData>,
Table<Raster<CPU>>,
)]

View File

@@ -10,163 +10,163 @@ use dyn_any::DynAny;
use glam::{DAffine2, DVec2};
use std::hash::Hash;
/// The possible forms of graphical content held in a Vec by the `elements` field of [`GraphicElement`].
/// The possible forms of graphical content that can be rendered by the Render node into either an image or SVG syntax.
#[derive(Clone, Debug, Hash, PartialEq, DynAny, serde::Serialize, serde::Deserialize)]
pub enum GraphicElement {
pub enum Graphic {
/// Equivalent to the SVG <g> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g
GraphicGroup(Table<GraphicElement>),
GraphicGroup(Table<Graphic>),
/// A vector shape, equivalent to the SVG <path> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
VectorData(Table<VectorData>),
RasterDataCPU(Table<Raster<CPU>>),
RasterDataGPU(Table<Raster<GPU>>),
}
impl Default for GraphicElement {
impl Default for Graphic {
fn default() -> Self {
Self::GraphicGroup(Default::default())
}
}
// GraphicGroup
impl From<Table<GraphicElement>> for GraphicElement {
fn from(graphic_group: Table<GraphicElement>) -> Self {
GraphicElement::GraphicGroup(graphic_group)
impl From<Table<Graphic>> for Graphic {
fn from(graphic_group: Table<Graphic>) -> Self {
Graphic::GraphicGroup(graphic_group)
}
}
// VectorData
impl From<VectorData> for GraphicElement {
impl From<VectorData> for Graphic {
fn from(vector_data: VectorData) -> Self {
GraphicElement::VectorData(Table::new_from_element(vector_data))
Graphic::VectorData(Table::new_from_element(vector_data))
}
}
impl From<Table<VectorData>> for GraphicElement {
impl From<Table<VectorData>> for Graphic {
fn from(vector_data: Table<VectorData>) -> Self {
GraphicElement::VectorData(vector_data)
Graphic::VectorData(vector_data)
}
}
impl From<VectorData> for Table<GraphicElement> {
impl From<VectorData> for Table<Graphic> {
fn from(vector_data: VectorData) -> Self {
Table::new_from_element(GraphicElement::VectorData(Table::new_from_element(vector_data)))
Table::new_from_element(Graphic::VectorData(Table::new_from_element(vector_data)))
}
}
impl From<Table<VectorData>> for Table<GraphicElement> {
impl From<Table<VectorData>> for Table<Graphic> {
fn from(vector_data: Table<VectorData>) -> Self {
Table::new_from_element(GraphicElement::VectorData(vector_data))
Table::new_from_element(Graphic::VectorData(vector_data))
}
}
// Raster<CPU>
impl From<Raster<CPU>> for GraphicElement {
impl From<Raster<CPU>> for Graphic {
fn from(raster_data: Raster<CPU>) -> Self {
GraphicElement::RasterDataCPU(Table::new_from_element(raster_data))
Graphic::RasterDataCPU(Table::new_from_element(raster_data))
}
}
impl From<Table<Raster<CPU>>> for GraphicElement {
impl From<Table<Raster<CPU>>> for Graphic {
fn from(raster_data: Table<Raster<CPU>>) -> Self {
GraphicElement::RasterDataCPU(raster_data)
Graphic::RasterDataCPU(raster_data)
}
}
impl From<Raster<CPU>> for Table<GraphicElement> {
impl From<Raster<CPU>> for Table<Graphic> {
fn from(raster_data: Raster<CPU>) -> Self {
Table::new_from_element(GraphicElement::RasterDataCPU(Table::new_from_element(raster_data)))
Table::new_from_element(Graphic::RasterDataCPU(Table::new_from_element(raster_data)))
}
}
impl From<Table<Raster<CPU>>> for Table<GraphicElement> {
impl From<Table<Raster<CPU>>> for Table<Graphic> {
fn from(raster_data_table: Table<Raster<CPU>>) -> Self {
Table::new_from_element(GraphicElement::RasterDataCPU(raster_data_table))
Table::new_from_element(Graphic::RasterDataCPU(raster_data_table))
}
}
// Raster<GPU>
impl From<Raster<GPU>> for GraphicElement {
impl From<Raster<GPU>> for Graphic {
fn from(raster_data: Raster<GPU>) -> Self {
GraphicElement::RasterDataGPU(Table::new_from_element(raster_data))
Graphic::RasterDataGPU(Table::new_from_element(raster_data))
}
}
impl From<Table<Raster<GPU>>> for GraphicElement {
impl From<Table<Raster<GPU>>> for Graphic {
fn from(raster_data: Table<Raster<GPU>>) -> Self {
GraphicElement::RasterDataGPU(raster_data)
Graphic::RasterDataGPU(raster_data)
}
}
impl From<Raster<GPU>> for Table<GraphicElement> {
impl From<Raster<GPU>> for Table<Graphic> {
fn from(raster_data: Raster<GPU>) -> Self {
Table::new_from_element(GraphicElement::RasterDataGPU(Table::new_from_element(raster_data)))
Table::new_from_element(Graphic::RasterDataGPU(Table::new_from_element(raster_data)))
}
}
impl From<Table<Raster<GPU>>> for Table<GraphicElement> {
impl From<Table<Raster<GPU>>> for Table<Graphic> {
fn from(raster_data_table: Table<Raster<GPU>>) -> Self {
Table::new_from_element(GraphicElement::RasterDataGPU(raster_data_table))
Table::new_from_element(Graphic::RasterDataGPU(raster_data_table))
}
}
// DAffine2
impl From<DAffine2> for GraphicElement {
impl From<DAffine2> for Graphic {
fn from(_: DAffine2) -> Self {
GraphicElement::default()
Graphic::default()
}
}
impl From<DAffine2> for Table<GraphicElement> {
impl From<DAffine2> for Table<Graphic> {
fn from(_: DAffine2) -> Self {
Table::new()
}
}
impl GraphicElement {
pub fn as_group(&self) -> Option<&Table<GraphicElement>> {
impl Graphic {
pub fn as_group(&self) -> Option<&Table<Graphic>> {
match self {
GraphicElement::GraphicGroup(group) => Some(group),
Graphic::GraphicGroup(group) => Some(group),
_ => None,
}
}
pub fn as_group_mut(&mut self) -> Option<&mut Table<GraphicElement>> {
pub fn as_group_mut(&mut self) -> Option<&mut Table<Graphic>> {
match self {
GraphicElement::GraphicGroup(group) => Some(group),
Graphic::GraphicGroup(group) => Some(group),
_ => None,
}
}
pub fn as_vector_data(&self) -> Option<&Table<VectorData>> {
match self {
GraphicElement::VectorData(data) => Some(data),
Graphic::VectorData(data) => Some(data),
_ => None,
}
}
pub fn as_vector_data_mut(&mut self) -> Option<&mut Table<VectorData>> {
match self {
GraphicElement::VectorData(data) => Some(data),
Graphic::VectorData(data) => Some(data),
_ => None,
}
}
pub fn as_raster(&self) -> Option<&Table<Raster<CPU>>> {
match self {
GraphicElement::RasterDataCPU(raster) => Some(raster),
Graphic::RasterDataCPU(raster) => Some(raster),
_ => None,
}
}
pub fn as_raster_mut(&mut self) -> Option<&mut Table<Raster<CPU>>> {
match self {
GraphicElement::RasterDataCPU(raster) => Some(raster),
Graphic::RasterDataCPU(raster) => Some(raster),
_ => None,
}
}
pub fn had_clip_enabled(&self) -> bool {
match self {
GraphicElement::VectorData(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
GraphicElement::GraphicGroup(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
GraphicElement::RasterDataCPU(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
GraphicElement::RasterDataGPU(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
Graphic::VectorData(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
Graphic::GraphicGroup(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
Graphic::RasterDataCPU(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
Graphic::RasterDataGPU(data) => data.iter_ref().all(|row| row.alpha_blending.clip),
}
}
pub fn can_reduce_to_clip_path(&self) -> bool {
match self {
GraphicElement::VectorData(vector_data_table) => vector_data_table.iter_ref().all(|row| {
Graphic::VectorData(vector_data_table) => vector_data_table.iter_ref().all(|row| {
let style = &row.element.style;
let alpha_blending = &row.alpha_blending;
(alpha_blending.opacity > 1. - f32::EPSILON) && style.fill().is_opaque() && style.stroke().is_none_or(|stroke| !stroke.has_renderable_stroke())
@@ -176,18 +176,18 @@ impl GraphicElement {
}
}
impl BoundingBox for GraphicElement {
impl BoundingBox for Graphic {
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
match self {
GraphicElement::VectorData(vector_data) => vector_data.bounding_box(transform, include_stroke),
GraphicElement::RasterDataCPU(raster) => raster.bounding_box(transform, include_stroke),
GraphicElement::RasterDataGPU(raster) => raster.bounding_box(transform, include_stroke),
GraphicElement::GraphicGroup(graphic_group) => graphic_group.bounding_box(transform, include_stroke),
Graphic::VectorData(vector_data) => vector_data.bounding_box(transform, include_stroke),
Graphic::RasterDataCPU(raster) => raster.bounding_box(transform, include_stroke),
Graphic::RasterDataGPU(raster) => raster.bounding_box(transform, include_stroke),
Graphic::GraphicGroup(graphic_group) => graphic_group.bounding_box(transform, include_stroke),
}
}
}
impl BoundingBox for Table<GraphicElement> {
impl BoundingBox for Table<Graphic> {
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
self.iter_ref()
.filter_map(|element| element.element.bounding_box(transform * *element.transform, include_stroke))
@@ -198,8 +198,8 @@ impl BoundingBox for Table<GraphicElement> {
#[node_macro::node(category(""))]
async fn layer<I: 'n + Send + Clone>(
_: impl Ctx,
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>, Table<Raster<GPU>>)] mut stack: Table<I>,
#[implementations(GraphicElement, VectorData, Raster<CPU>, Raster<GPU>)] element: I,
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>, Table<Raster<GPU>>)] mut stack: Table<I>,
#[implementations(Graphic, VectorData, Raster<CPU>, Raster<GPU>)] element: I,
node_path: Vec<NodeId>,
) -> Table<I> {
// Get the penultimate element of the node path, or None if the path is too short
@@ -216,38 +216,38 @@ async fn layer<I: 'n + Send + Clone>(
}
#[node_macro::node(category("Debug"))]
async fn to_element<Data: Into<GraphicElement> + 'n>(
async fn to_element<Data: Into<Graphic> + 'n>(
_: impl Ctx,
#[implementations(
Table<GraphicElement>,
Table<Graphic>,
Table<VectorData>,
Table<Raster<CPU>>,
Table<Raster<GPU>>,
DAffine2,
)]
data: Data,
) -> GraphicElement {
) -> Graphic {
data.into()
}
#[node_macro::node(category("General"))]
async fn to_group<Data: Into<Table<GraphicElement>> + 'n>(
async fn to_group<Data: Into<Table<Graphic>> + 'n>(
_: impl Ctx,
#[implementations(
Table<GraphicElement>,
Table<Graphic>,
Table<VectorData>,
Table<Raster<CPU>>,
Table<Raster<GPU>>,
)]
element: Data,
) -> Table<GraphicElement> {
) -> Table<Graphic> {
element.into()
}
#[node_macro::node(category("General"))]
async fn flatten_group(_: impl Ctx, group: Table<GraphicElement>, fully_flatten: bool) -> Table<GraphicElement> {
// TODO: Avoid mutable reference, instead return a new Table<GraphicElement>?
fn flatten_group(output_group_table: &mut Table<GraphicElement>, current_group_table: Table<GraphicElement>, fully_flatten: bool, recursion_depth: usize) {
async fn flatten_group(_: impl Ctx, group: Table<Graphic>, fully_flatten: bool) -> Table<Graphic> {
// TODO: Avoid mutable reference, instead return a new Table<Graphic>?
fn flatten_group(output_group_table: &mut Table<Graphic>, current_group_table: Table<Graphic>, fully_flatten: bool, recursion_depth: usize) {
for current_row in current_group_table.iter_ref() {
let current_element = current_row.element.clone();
let reference = *current_row.source_node_id;
@@ -256,7 +256,7 @@ async fn flatten_group(_: impl Ctx, group: Table<GraphicElement>, fully_flatten:
match current_element {
// If we're allowed to recurse, flatten any GraphicGroups we encounter
GraphicElement::GraphicGroup(mut current_element) if recurse => {
Graphic::GraphicGroup(mut current_element) if recurse => {
// Apply the parent group's transform to all child elements
for graphic_element in current_element.iter_mut() {
*graphic_element.transform = *current_row.transform * *graphic_element.transform;
@@ -284,16 +284,16 @@ async fn flatten_group(_: impl Ctx, group: Table<GraphicElement>, fully_flatten:
}
#[node_macro::node(category("Vector"))]
async fn flatten_vector(_: impl Ctx, group: Table<GraphicElement>) -> Table<VectorData> {
// TODO: Avoid mutable reference, instead return a new Table<GraphicElement>?
fn flatten_group(output_group_table: &mut Table<VectorData>, current_group_table: Table<GraphicElement>) {
async fn flatten_vector(_: impl Ctx, group: Table<Graphic>) -> Table<VectorData> {
// TODO: Avoid mutable reference, instead return a new Table<Graphic>?
fn flatten_group(output_group_table: &mut Table<VectorData>, current_group_table: Table<Graphic>) {
for current_graphic_element_row in current_group_table.iter_ref() {
let current_element = current_graphic_element_row.element.clone();
let reference = *current_graphic_element_row.source_node_id;
match current_element {
// If we're allowed to recurse, flatten any GraphicGroups we encounter
GraphicElement::GraphicGroup(mut current_element) => {
Graphic::GraphicGroup(mut current_element) => {
// Apply the parent group's transform to all child elements
for graphic_element in current_element.iter_mut() {
*graphic_element.transform = *current_graphic_element_row.transform * *graphic_element.transform;
@@ -302,7 +302,7 @@ async fn flatten_vector(_: impl Ctx, group: Table<GraphicElement>) -> Table<Vect
flatten_group(output_group_table, current_element);
}
// Handle any leaf elements we encounter, which can be either non-GraphicGroup elements or GraphicGroups that we don't want to flatten
GraphicElement::VectorData(vector_table) => {
Graphic::VectorData(vector_table) => {
for current_vector_row in vector_table.iter_ref() {
output_group_table.push(TableRow {
element: current_vector_row.element.clone(),
@@ -341,7 +341,7 @@ fn index<T: AtIndex + Clone + Default>(
Vec<DVec2>,
Table<VectorData>,
Table<Raster<CPU>>,
Table<GraphicElement>,
Table<Graphic>,
)]
collection: T,
/// The index of the item to retrieve, starting from 0 for the first item.
@@ -379,18 +379,18 @@ impl<T: Clone> AtIndex for Table<T> {
}
// TODO: Eventually remove this migration document upgrade code
pub fn migrate_graphic_group<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Table<GraphicElement>, D::Error> {
pub fn migrate_graphic_group<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Table<Graphic>, D::Error> {
use serde::Deserialize;
#[derive(Clone, Debug, PartialEq, DynAny, Default, serde::Serialize, serde::Deserialize)]
pub struct OldGraphicGroup {
elements: Vec<(GraphicElement, Option<NodeId>)>,
elements: Vec<(Graphic, Option<NodeId>)>,
transform: DAffine2,
alpha_blending: AlphaBlending,
}
#[derive(Clone, Debug, PartialEq, DynAny, Default, serde::Serialize, serde::Deserialize)]
pub struct GraphicGroup {
elements: Vec<(GraphicElement, Option<NodeId>)>,
elements: Vec<(Graphic, Option<NodeId>)>,
}
#[derive(serde::Serialize, serde::Deserialize)]
@@ -428,10 +428,10 @@ pub fn migrate_graphic_group<'de, D: serde::Deserializer<'de>>(deserializer: D)
}
}
graphic_group_table
} else if let Ok(new_table) = serde_json::from_value::<Table<GraphicElement>>(value) {
} else if let Ok(new_table) = serde_json::from_value::<Table<Graphic>>(value) {
new_table
} else {
return Err(serde::de::Error::custom("Failed to deserialize Table<GraphicElement>"));
return Err(serde::de::Error::custom("Failed to deserialize Table<Graphic>"));
}
}
})

View File

@@ -41,7 +41,7 @@ pub use graphene_core_shaders::AsU32;
pub use graphene_core_shaders::blending;
pub use graphene_core_shaders::choice_type;
pub use graphene_core_shaders::color;
pub use graphic_element::GraphicElement;
pub use graphic_element::Graphic;
pub use memo::MemoHash;
pub use num_traits;
use std::any::TypeId;

View File

@@ -1,6 +1,6 @@
use crate::Artboard;
use crate::Color;
use crate::GraphicElement;
use crate::Graphic;
use crate::gradient::GradientStops;
use crate::graphene_core::registry::types::TextArea;
use crate::raster_types::{CPU, GPU, Raster};
@@ -17,7 +17,7 @@ fn to_string<T: std::fmt::Debug>(_: impl Ctx, #[implementations(String, bool, f6
#[node_macro::node(category("Text"))]
fn serialize<T: serde::Serialize>(
_: impl Ctx,
#[implementations(String, bool, f64, u32, u64, DVec2, DAffine2, Color, Option<Color>, Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)] value: T,
#[implementations(String, bool, f64, u32, u64, DVec2, DAffine2, Color, Option<Color>, Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)] value: T,
) -> String {
serde_json::to_string(&value).unwrap_or_else(|_| "Serialization Error".to_string())
}
@@ -61,10 +61,10 @@ async fn switch<T, C: Send + 'n + Clone>(
Context -> DAffine2,
Context -> Table<Artboard>,
Context -> Table<VectorData>,
Context -> Table<GraphicElement>,
Context -> Table<Graphic>,
Context -> Table<Raster<CPU>>,
Context -> Table<Raster<GPU>>,
Context -> GraphicElement,
Context -> Graphic,
Context -> Color,
Context -> Option<Color>,
Context -> GradientStops,
@@ -82,10 +82,10 @@ async fn switch<T, C: Send + 'n + Clone>(
Context -> DAffine2,
Context -> Table<Artboard>,
Context -> Table<VectorData>,
Context -> Table<GraphicElement>,
Context -> Table<Graphic>,
Context -> Table<Raster<CPU>>,
Context -> Table<Raster<GPU>>,
Context -> GraphicElement,
Context -> Graphic,
Context -> Color,
Context -> Option<Color>,
Context -> GradientStops,

View File

@@ -1,7 +1,7 @@
use crate::raster_types::{CPU, GPU, Raster};
use crate::table::Table;
use crate::vector::VectorData;
use crate::{Artboard, Color, GraphicElement};
use crate::{Artboard, Color, Graphic};
use glam::DVec2;
pub trait RenderComplexity {
@@ -22,7 +22,7 @@ impl RenderComplexity for Artboard {
}
}
impl RenderComplexity for GraphicElement {
impl RenderComplexity for Graphic {
fn render_complexity(&self) -> usize {
match self {
Self::GraphicGroup(table) => table.render_complexity(),

View File

@@ -2,7 +2,7 @@ use crate::raster_types::{CPU, GPU, Raster};
use crate::table::Table;
use crate::transform::{ApplyTransform, Footprint, Transform};
use crate::vector::VectorData;
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, GraphicElement, OwnedContextImpl};
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, Graphic, OwnedContextImpl};
use core::f64;
use glam::{DAffine2, DVec2};
@@ -13,7 +13,7 @@ async fn transform<T: ApplyTransform + 'n + 'static>(
Context -> DAffine2,
Context -> DVec2,
Context -> Table<VectorData>,
Context -> Table<GraphicElement>,
Context -> Table<Graphic>,
Context -> Table<Raster<CPU>>,
Context -> Table<Raster<GPU>>,
)]
@@ -43,7 +43,7 @@ async fn transform<T: ApplyTransform + 'n + 'static>(
#[node_macro::node(category(""))]
fn replace_transform<Data, TransformInput: Transform>(
_: impl Ctx,
#[implementations(Table<VectorData>, Table<Raster<CPU>>, Table<GraphicElement>)] mut data: Table<Data>,
#[implementations(Table<VectorData>, Table<Raster<CPU>>, Table<Graphic>)] mut data: Table<Data>,
#[implementations(DAffine2)] transform: TransformInput,
) -> Table<Data> {
for data_transform in data.iter_mut() {
@@ -56,7 +56,7 @@ fn replace_transform<Data, TransformInput: Transform>(
async fn extract_transform<T>(
_: impl Ctx,
#[implementations(
Table<GraphicElement>,
Table<Graphic>,
Table<VectorData>,
Table<Raster<CPU>>,
Table<Raster<GPU>>,
@@ -91,7 +91,7 @@ async fn boundless_footprint<T: 'n + 'static>(
ctx: impl Ctx + CloneVarArgs + ExtractAll,
#[implementations(
Context -> Table<VectorData>,
Context -> Table<GraphicElement>,
Context -> Table<Graphic>,
Context -> Table<Raster<CPU>>,
Context -> Table<Raster<GPU>>,
Context -> String,
@@ -109,7 +109,7 @@ async fn freeze_real_time<T: 'n + 'static>(
ctx: impl Ctx + CloneVarArgs + ExtractAll,
#[implementations(
Context -> Table<VectorData>,
Context -> Table<GraphicElement>,
Context -> Table<Graphic>,
Context -> Table<Raster<CPU>>,
Context -> Table<Raster<GPU>>,
Context -> String,

View File

@@ -1,15 +1,15 @@
use crate::raster_types::{CPU, Raster};
use crate::table::{Table, TableRowRef};
use crate::vector::VectorData;
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractIndex, ExtractVarArgs, GraphicElement, OwnedContextImpl};
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractIndex, ExtractVarArgs, Graphic, OwnedContextImpl};
use glam::DVec2;
#[node_macro::node(name("Instance on Points"), category("Instancing"), path(graphene_core::vector))]
async fn instance_on_points<T: Into<GraphicElement> + Default + Send + Clone + 'static>(
async fn instance_on_points<T: Into<Graphic> + Default + Send + Clone + 'static>(
ctx: impl ExtractAll + CloneVarArgs + Sync + Ctx,
points: Table<VectorData>,
#[implementations(
Context -> Table<GraphicElement>,
Context -> Table<Graphic>,
Context -> Table<VectorData>,
Context -> Table<Raster<CPU>>
)]
@@ -47,10 +47,10 @@ async fn instance_on_points<T: Into<GraphicElement> + Default + Send + Clone + '
}
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
async fn instance_repeat<T: Into<GraphicElement> + Default + Send + Clone + 'static>(
async fn instance_repeat<T: Into<Graphic> + Default + Send + Clone + 'static>(
ctx: impl ExtractAll + CloneVarArgs + Ctx,
#[implementations(
Context -> Table<GraphicElement>,
Context -> Table<Graphic>,
Context -> Table<VectorData>,
Context -> Table<Raster<CPU>>
)]

View File

@@ -9,7 +9,7 @@ use crate::math::quad::Quad;
use crate::table::Table;
use crate::transform::Transform;
use crate::vector::click_target::{ClickTargetType, FreePoint};
use crate::{AlphaBlending, Color, GraphicElement};
use crate::{AlphaBlending, Color, Graphic};
pub use attributes::*;
use bezier_rs::{BezierHandles, ManipulatorGroup};
use core::borrow::Borrow;
@@ -41,7 +41,7 @@ pub fn migrate_vector_data<'de, D: serde::Deserializer<'de>>(deserializer: D) ->
pub region_domain: RegionDomain,
// Used to store the upstream graphic group during destructive Boolean Operations (and other nodes with a similar effect) so that click targets can be preserved.
pub upstream_graphic_group: Option<Table<GraphicElement>>,
pub upstream_graphic_group: Option<Table<Graphic>>,
}
#[derive(serde::Serialize, serde::Deserialize)]
@@ -89,7 +89,7 @@ pub struct VectorData {
pub region_domain: RegionDomain,
// Used to store the upstream graphic group during destructive Boolean Operations (and other nodes with a similar effect) so that click targets can be preserved.
pub upstream_graphic_group: Option<Table<GraphicElement>>,
pub upstream_graphic_group: Option<Table<Graphic>>,
}
impl Default for VectorData {

View File

@@ -16,7 +16,7 @@ use crate::vector::misc::{MergeByDistanceAlgorithm, PointSpacingType, is_linear}
use crate::vector::misc::{handles_to_segment, segment_to_handles};
use crate::vector::style::{PaintOrder, StrokeAlign, StrokeCap, StrokeJoin};
use crate::vector::{FillId, RegionId};
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicElement, OwnedContextImpl};
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, Graphic, OwnedContextImpl};
use bezier_rs::ManipulatorGroup;
use core::f64::consts::PI;
use core::hash::{Hash, Hasher};
@@ -32,7 +32,7 @@ trait VectorDataTableIterMut {
fn vector_iter_mut(&mut self) -> impl Iterator<Item = TableRowMut<'_, VectorData>>;
}
impl VectorDataTableIterMut for Table<GraphicElement> {
impl VectorDataTableIterMut for Table<Graphic> {
fn vector_iter_mut(&mut self) -> impl Iterator<Item = TableRowMut<'_, VectorData>> {
// Grab only the direct children
self.iter_mut()
@@ -50,7 +50,7 @@ impl VectorDataTableIterMut for Table<VectorData> {
#[node_macro::node(category("Vector: Style"), path(graphene_core::vector))]
async fn assign_colors<T>(
_: impl Ctx,
#[implementations(Table<GraphicElement>, Table<VectorData>)]
#[implementations(Table<Graphic>, Table<VectorData>)]
#[widget(ParsedWidgetOverride::Hidden)]
/// The vector elements, or group of vector elements, to apply the fill and/or stroke style to.
mut vector_group: T,
@@ -115,10 +115,10 @@ async fn fill<F: Into<Fill> + 'n + Send, V>(
Table<VectorData>,
Table<VectorData>,
Table<VectorData>,
Table<GraphicElement>,
Table<GraphicElement>,
Table<GraphicElement>,
Table<GraphicElement>
Table<Graphic>,
Table<Graphic>,
Table<Graphic>,
Table<Graphic>
)]
/// The vector elements, or group of vector elements, to apply the fill to.
mut vector_data: V,
@@ -157,7 +157,7 @@ where
#[node_macro::node(category("Vector: Style"), path(graphene_core::vector), properties("stroke_properties"))]
async fn stroke<C: Into<Option<Color>> + 'n + Send, V>(
_: impl Ctx,
#[implementations(Table<VectorData>, Table<VectorData>, Table<GraphicElement>, Table<GraphicElement>)]
#[implementations(Table<VectorData>, Table<VectorData>, Table<Graphic>, Table<Graphic>)]
/// The vector elements, or group of vector elements, to apply the stroke to.
mut vector_data: Table<V>,
#[implementations(
@@ -220,8 +220,8 @@ where
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
async fn repeat<I: 'n + Send + Clone>(
_: impl Ctx,
// TODO: Implement other GraphicElementRendered types.
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
// TODO: Implement other graphical types.
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
#[default(100., 100.)]
// TODO: When using a custom Properties panel layout in document_node_definitions.rs and this default is set, the widget weirdly doesn't show up in the Properties panel. Investigation is needed.
direction: PixelSize,
@@ -256,8 +256,8 @@ async fn repeat<I: 'n + Send + Clone>(
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
async fn circular_repeat<I: 'n + Send + Clone>(
_: impl Ctx,
// TODO: Implement other GraphicElementRendered types.
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
// TODO: Implement other graphical types.
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
angle_offset: Angle,
#[unit(" px")]
#[default(5)]
@@ -293,7 +293,7 @@ async fn copy_to_points<I: 'n + Send + Clone>(
points: Table<VectorData>,
#[expose]
/// Artwork to be copied and placed at each point.
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)]
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)]
instance: Table<I>,
/// Minimum range of randomized sizes given to each instance.
#[default(1)]
@@ -368,7 +368,7 @@ async fn copy_to_points<I: 'n + Send + Clone>(
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
async fn mirror<I: 'n + Send + Clone>(
_: impl Ctx,
#[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
#[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>)] instance: Table<I>,
#[default(ReferencePoint::Center)] relative_to_bounds: ReferencePoint,
#[unit(" px")] offset: f64,
#[range((-90., 90.))] angle: Angle,
@@ -958,17 +958,17 @@ async fn solidify_stroke(_: impl Ctx, vector_data: Table<VectorData>) -> Table<V
}
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
async fn flatten_path<I: 'n + Send>(_: impl Ctx, #[implementations(Table<GraphicElement>, Table<VectorData>)] graphic_group_input: Table<I>) -> Table<VectorData>
async fn flatten_path<I: 'n + Send>(_: impl Ctx, #[implementations(Table<Graphic>, Table<VectorData>)] graphic_group_input: Table<I>) -> Table<VectorData>
where
GraphicElement: From<Table<I>>,
Graphic: From<Table<I>>,
{
// A node based solution to support passing through vector data could be a network node with a cache node connected to
// a Flatten Path connected to an if else node, another connection from the cache directly
// To the if else node, and another connection from the cache to a matches type node connected to the if else node.
fn flatten_group(graphic_group_table: &Table<GraphicElement>, output: &mut TableRowMut<VectorData>) {
fn flatten_group(graphic_group_table: &Table<Graphic>, output: &mut TableRowMut<VectorData>) {
for (group_index, current_element) in graphic_group_table.iter_ref().enumerate() {
match current_element.element {
GraphicElement::VectorData(vector_data_table) => {
Graphic::VectorData(vector_data_table) => {
// Loop through every row of the Table<VectorData> and concatenate each element's subpath into the output VectorData element.
for (vector_index, row) in vector_data_table.iter_ref().enumerate() {
let other = row.element;
@@ -985,7 +985,7 @@ where
output.element.style = row.element.style.clone();
}
}
GraphicElement::GraphicGroup(graphic_group) => {
Graphic::GraphicGroup(graphic_group) => {
let mut graphic_group = graphic_group.clone();
for row in graphic_group.iter_mut() {
*row.transform = *current_element.transform * *row.transform;
@@ -1005,7 +1005,7 @@ where
};
// Flatten the graphic group input into the output VectorData element
let base_graphic_group = Table::new_from_element(GraphicElement::from(graphic_group_input));
let base_graphic_group = Table::new_from_element(Graphic::from(graphic_group_input));
flatten_group(&base_graphic_group, &mut output);
// Return the single-row Table<VectorData> containing the flattened VectorData subpaths
@@ -1911,7 +1911,7 @@ fn point_inside(_: impl Ctx, source: Table<VectorData>, point: DVec2) -> bool {
}
#[node_macro::node(category("General"), path(graphene_core::vector))]
async fn count_elements<I>(_: impl Ctx, #[implementations(Table<GraphicElement>, Table<VectorData>, Table<Raster<CPU>>, Table<Raster<GPU>>)] source: Table<I>) -> u64 {
async fn count_elements<I>(_: impl Ctx, #[implementations(Table<Graphic>, Table<VectorData>, Table<Raster<CPU>>, Table<Raster<GPU>>)] source: Table<I>) -> u64 {
source.len() as u64
}