Skip to content

Commit e742e48

Browse files
committed
move IndexNode to gelement-nodes
1 parent 4ef02b4 commit e742e48

File tree

4 files changed

+62
-51
lines changed

4 files changed

+62
-51
lines changed

editor/src/messages/portfolio/document_migration.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[
5858
node: graphene_std::element_nodes::conversion::flatten_vector::IDENTIFIER,
5959
aliases: &["graphene_core::graphic_element::FlattenVectorNode"],
6060
},
61+
NodeReplacement {
62+
node: graphene_std::element_nodes::index::index::IDENTIFIER,
63+
aliases: &["graphene_core::graphic_element::IndexNode"],
64+
},
6165
// -----------------------
6266
// blending
6367
// -----------------------

node-graph/gcore/src/graphic_element.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::blending::AlphaBlending;
22
use crate::bounds::BoundingBox;
33
use crate::color::Color;
4-
use crate::context::Ctx;
54
use crate::instances::{Instance, Instances};
65
use crate::math::quad::Quad;
76
use crate::raster::image::Image;
@@ -369,53 +368,3 @@ impl From<GraphicGroupTable> for GraphicElement {
369368
pub trait ToGraphicElement {
370369
fn to_graphic_element(&self) -> GraphicElement;
371370
}
372-
373-
/// Returns the value at the specified index in the collection.
374-
/// If that index has no value, the type's default value is returned.
375-
#[node_macro::node(category("General"))]
376-
fn index<T: AtIndex + Clone + Default>(
377-
_: impl Ctx,
378-
/// The collection of data, such as a list or table.
379-
#[implementations(
380-
Vec<Color>,
381-
Vec<Option<Color>>,
382-
Vec<f64>, Vec<u64>,
383-
Vec<DVec2>,
384-
VectorDataTable,
385-
RasterDataTable<CPU>,
386-
GraphicGroupTable,
387-
)]
388-
collection: T,
389-
/// The index of the item to retrieve, starting from 0 for the first item.
390-
index: u32,
391-
) -> T::Output
392-
where
393-
T::Output: Clone + Default,
394-
{
395-
collection.at_index(index as usize).unwrap_or_default()
396-
}
397-
398-
pub trait AtIndex {
399-
type Output;
400-
fn at_index(&self, index: usize) -> Option<Self::Output>;
401-
}
402-
impl<T: Clone> AtIndex for Vec<T> {
403-
type Output = T;
404-
405-
fn at_index(&self, index: usize) -> Option<Self::Output> {
406-
self.get(index).cloned()
407-
}
408-
}
409-
impl<T: Clone> AtIndex for Instances<T> {
410-
type Output = Instances<T>;
411-
412-
fn at_index(&self, index: usize) -> Option<Self::Output> {
413-
let mut result_table = Self::default();
414-
if let Some(row) = self.instance_ref_iter().nth(index) {
415-
result_table.push(row.to_instance_cloned());
416-
Some(result_table)
417-
} else {
418-
None
419-
}
420-
}
421-
}
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)