Skip to content

Commit 1bb7803

Browse files
committed
move IndexNode to gelement-nodes
1 parent fd56aca commit 1bb7803

File tree

4 files changed

+59
-50
lines changed

4 files changed

+59
-50
lines changed

editor/src/messages/portfolio/document_migration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const REPLACEMENTS: &[(&str, &str)] = &[
139139
("graphene_core::ConstructArtboardNode", "graphene_element_nodes::conversion::ToArtboardNode"),
140140
("graphene_core::graphic_element::AppendArtboardNode", "graphene_element_nodes::conversion::AppendArtboardNode"),
141141
("graphene_core::AddArtboardNode", "graphene_element_nodes::conversion::AppendArtboardNode"),
142+
("graphene_core::graphic_element::IndexNode", "graphene_element_nodes::index::IndexNode"),
142143
];
143144

144145
pub fn document_migration_string_preprocessing(document_serialized_content: String) -> String {

node-graph/gcore/src/graphic_element.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -368,53 +368,3 @@ impl From<GraphicGroupTable> for GraphicElement {
368368
pub trait ToGraphicElement {
369369
fn to_graphic_element(&self) -> GraphicElement;
370370
}
371-
372-
/// Returns the value at the specified index in the collection.
373-
/// If that index has no value, the type's default value is returned.
374-
#[node_macro::node(category("General"))]
375-
fn index<T: AtIndex + Clone + Default>(
376-
_: impl Ctx,
377-
/// The collection of data, such as a list or table.
378-
#[implementations(
379-
Vec<Color>,
380-
Vec<Option<Color>>,
381-
Vec<f64>, Vec<u64>,
382-
Vec<DVec2>,
383-
VectorDataTable,
384-
RasterDataTable<CPU>,
385-
GraphicGroupTable,
386-
)]
387-
collection: T,
388-
/// The index of the item to retrieve, starting from 0 for the first item.
389-
index: u32,
390-
) -> T::Output
391-
where
392-
T::Output: Clone + Default,
393-
{
394-
collection.at_index(index as usize).unwrap_or_default()
395-
}
396-
397-
pub trait AtIndex {
398-
type Output;
399-
fn at_index(&self, index: usize) -> Option<Self::Output>;
400-
}
401-
impl<T: Clone> AtIndex for Vec<T> {
402-
type Output = T;
403-
404-
fn at_index(&self, index: usize) -> Option<Self::Output> {
405-
self.get(index).cloned()
406-
}
407-
}
408-
impl<T: Clone> AtIndex for Instances<T> {
409-
type Output = Instances<T>;
410-
411-
fn at_index(&self, index: usize) -> Option<Self::Output> {
412-
let mut result_table = Self::default();
413-
if let Some(row) = self.instance_ref_iter().nth(index) {
414-
result_table.push(row.to_instance_cloned());
415-
Some(result_table)
416-
} else {
417-
None
418-
}
419-
}
420-
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use glam::DVec2;
2+
use graphene_core::GraphicGroupTable;
3+
use graphene_core::color::Color;
4+
use graphene_core::context::Ctx;
5+
use graphene_core::instances::Instances;
6+
use graphene_core::raster_types::{CPU, RasterDataTable};
7+
use graphene_core::vector::VectorDataTable;
8+
9+
/// Returns the value at the specified index in the collection.
10+
/// If that index has no value, the type's default value is returned.
11+
#[node_macro::node(category("General"))]
12+
fn index<T: AtIndex + Clone + Default>(
13+
_: impl Ctx,
14+
/// The collection of data, such as a list or table.
15+
#[implementations(
16+
Vec<Color>,
17+
Vec<Option<Color>>,
18+
Vec<f64>, Vec<u64>,
19+
Vec<DVec2>,
20+
VectorDataTable,
21+
RasterDataTable<CPU>,
22+
GraphicGroupTable,
23+
)]
24+
collection: T,
25+
/// The index of the item to retrieve, starting from 0 for the first item.
26+
index: u32,
27+
) -> T::Output
28+
where
29+
T::Output: Clone + Default,
30+
{
31+
collection.at_index(index as usize).unwrap_or_default()
32+
}
33+
34+
pub trait AtIndex {
35+
type Output;
36+
fn at_index(&self, index: usize) -> Option<Self::Output>;
37+
}
38+
impl<T: Clone> AtIndex for Vec<T> {
39+
type Output = T;
40+
41+
fn at_index(&self, index: usize) -> Option<Self::Output> {
42+
self.get(index).cloned()
43+
}
44+
}
45+
impl<T: Clone> AtIndex for Instances<T> {
46+
type Output = Instances<T>;
47+
48+
fn at_index(&self, index: usize) -> Option<Self::Output> {
49+
let mut result_table = Self::default();
50+
if let Some(row) = self.instance_ref_iter().nth(index) {
51+
result_table.push(row.to_instance_cloned());
52+
Some(result_table)
53+
} else {
54+
None
55+
}
56+
}
57+
}

node-graph/gelement-nodes/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod animation;
22
pub mod blending_nodes;
33
pub mod conversion;
4+
pub mod index;
45
pub mod instance;
56
pub mod logic;
67
pub mod transform_nodes;

0 commit comments

Comments
 (0)