mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-07-07 15:55:00 +00:00
move IndexNode
to gelement-nodes
This commit is contained in:
parent
fd56acab83
commit
1bb7803478
4 changed files with 59 additions and 50 deletions
|
@ -139,6 +139,7 @@ const REPLACEMENTS: &[(&str, &str)] = &[
|
||||||
("graphene_core::ConstructArtboardNode", "graphene_element_nodes::conversion::ToArtboardNode"),
|
("graphene_core::ConstructArtboardNode", "graphene_element_nodes::conversion::ToArtboardNode"),
|
||||||
("graphene_core::graphic_element::AppendArtboardNode", "graphene_element_nodes::conversion::AppendArtboardNode"),
|
("graphene_core::graphic_element::AppendArtboardNode", "graphene_element_nodes::conversion::AppendArtboardNode"),
|
||||||
("graphene_core::AddArtboardNode", "graphene_element_nodes::conversion::AppendArtboardNode"),
|
("graphene_core::AddArtboardNode", "graphene_element_nodes::conversion::AppendArtboardNode"),
|
||||||
|
("graphene_core::graphic_element::IndexNode", "graphene_element_nodes::index::IndexNode"),
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn document_migration_string_preprocessing(document_serialized_content: String) -> String {
|
pub fn document_migration_string_preprocessing(document_serialized_content: String) -> String {
|
||||||
|
|
|
@ -368,53 +368,3 @@ impl From<GraphicGroupTable> for GraphicElement {
|
||||||
pub trait ToGraphicElement {
|
pub trait ToGraphicElement {
|
||||||
fn to_graphic_element(&self) -> GraphicElement;
|
fn to_graphic_element(&self) -> GraphicElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the value at the specified index in the collection.
|
|
||||||
/// If that index has no value, the type's default value is returned.
|
|
||||||
#[node_macro::node(category("General"))]
|
|
||||||
fn index<T: AtIndex + Clone + Default>(
|
|
||||||
_: impl Ctx,
|
|
||||||
/// The collection of data, such as a list or table.
|
|
||||||
#[implementations(
|
|
||||||
Vec<Color>,
|
|
||||||
Vec<Option<Color>>,
|
|
||||||
Vec<f64>, Vec<u64>,
|
|
||||||
Vec<DVec2>,
|
|
||||||
VectorDataTable,
|
|
||||||
RasterDataTable<CPU>,
|
|
||||||
GraphicGroupTable,
|
|
||||||
)]
|
|
||||||
collection: T,
|
|
||||||
/// The index of the item to retrieve, starting from 0 for the first item.
|
|
||||||
index: u32,
|
|
||||||
) -> T::Output
|
|
||||||
where
|
|
||||||
T::Output: Clone + Default,
|
|
||||||
{
|
|
||||||
collection.at_index(index as usize).unwrap_or_default()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait AtIndex {
|
|
||||||
type Output;
|
|
||||||
fn at_index(&self, index: usize) -> Option<Self::Output>;
|
|
||||||
}
|
|
||||||
impl<T: Clone> AtIndex for Vec<T> {
|
|
||||||
type Output = T;
|
|
||||||
|
|
||||||
fn at_index(&self, index: usize) -> Option<Self::Output> {
|
|
||||||
self.get(index).cloned()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<T: Clone> AtIndex for Instances<T> {
|
|
||||||
type Output = Instances<T>;
|
|
||||||
|
|
||||||
fn at_index(&self, index: usize) -> Option<Self::Output> {
|
|
||||||
let mut result_table = Self::default();
|
|
||||||
if let Some(row) = self.instance_ref_iter().nth(index) {
|
|
||||||
result_table.push(row.to_instance_cloned());
|
|
||||||
Some(result_table)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
57
node-graph/gelement-nodes/src/index.rs
Normal file
57
node-graph/gelement-nodes/src/index.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
use glam::DVec2;
|
||||||
|
use graphene_core::GraphicGroupTable;
|
||||||
|
use graphene_core::color::Color;
|
||||||
|
use graphene_core::context::Ctx;
|
||||||
|
use graphene_core::instances::Instances;
|
||||||
|
use graphene_core::raster_types::{CPU, RasterDataTable};
|
||||||
|
use graphene_core::vector::VectorDataTable;
|
||||||
|
|
||||||
|
/// Returns the value at the specified index in the collection.
|
||||||
|
/// If that index has no value, the type's default value is returned.
|
||||||
|
#[node_macro::node(category("General"))]
|
||||||
|
fn index<T: AtIndex + Clone + Default>(
|
||||||
|
_: impl Ctx,
|
||||||
|
/// The collection of data, such as a list or table.
|
||||||
|
#[implementations(
|
||||||
|
Vec<Color>,
|
||||||
|
Vec<Option<Color>>,
|
||||||
|
Vec<f64>, Vec<u64>,
|
||||||
|
Vec<DVec2>,
|
||||||
|
VectorDataTable,
|
||||||
|
RasterDataTable<CPU>,
|
||||||
|
GraphicGroupTable,
|
||||||
|
)]
|
||||||
|
collection: T,
|
||||||
|
/// The index of the item to retrieve, starting from 0 for the first item.
|
||||||
|
index: u32,
|
||||||
|
) -> T::Output
|
||||||
|
where
|
||||||
|
T::Output: Clone + Default,
|
||||||
|
{
|
||||||
|
collection.at_index(index as usize).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait AtIndex {
|
||||||
|
type Output;
|
||||||
|
fn at_index(&self, index: usize) -> Option<Self::Output>;
|
||||||
|
}
|
||||||
|
impl<T: Clone> AtIndex for Vec<T> {
|
||||||
|
type Output = T;
|
||||||
|
|
||||||
|
fn at_index(&self, index: usize) -> Option<Self::Output> {
|
||||||
|
self.get(index).cloned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T: Clone> AtIndex for Instances<T> {
|
||||||
|
type Output = Instances<T>;
|
||||||
|
|
||||||
|
fn at_index(&self, index: usize) -> Option<Self::Output> {
|
||||||
|
let mut result_table = Self::default();
|
||||||
|
if let Some(row) = self.instance_ref_iter().nth(index) {
|
||||||
|
result_table.push(row.to_instance_cloned());
|
||||||
|
Some(result_table)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod animation;
|
pub mod animation;
|
||||||
pub mod blending_nodes;
|
pub mod blending_nodes;
|
||||||
pub mod conversion;
|
pub mod conversion;
|
||||||
|
pub mod index;
|
||||||
pub mod instance;
|
pub mod instance;
|
||||||
pub mod logic;
|
pub mod logic;
|
||||||
pub mod transform_nodes;
|
pub mod transform_nodes;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue