File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -551,3 +551,53 @@ impl From<GraphicGroupTable> for GraphicElement {
551
551
pub trait ToGraphicElement {
552
552
fn to_graphic_element ( & self ) -> GraphicElement ;
553
553
}
554
+
555
+ /// Returns the value at the specified index in the collection.
556
+ /// If that index has no value, the type's default value is returned.
557
+ #[ node_macro:: node( category( "General" ) ) ]
558
+ fn index < T : AtIndex + Clone + Default > (
559
+ _: impl Ctx ,
560
+ /// The collection of data, such as a list or table.
561
+ #[ implementations(
562
+ Vec <Color >,
563
+ Vec <Option <Color >>,
564
+ Vec <f64 >, Vec <u64 >,
565
+ Vec <DVec2 >,
566
+ VectorDataTable ,
567
+ RasterDataTable <CPU >,
568
+ GraphicGroupTable ,
569
+ ) ]
570
+ collection : T ,
571
+ /// The index of the item to retrieve, starting from 0 for the first item.
572
+ index : u32 ,
573
+ ) -> T :: Output
574
+ where
575
+ T :: Output : Clone + Default ,
576
+ {
577
+ collection. at_index ( index as usize ) . unwrap_or_default ( )
578
+ }
579
+
580
+ pub trait AtIndex {
581
+ type Output ;
582
+ fn at_index ( & self , index : usize ) -> Option < Self :: Output > ;
583
+ }
584
+ impl < T : Clone > AtIndex for Vec < T > {
585
+ type Output = T ;
586
+
587
+ fn at_index ( & self , index : usize ) -> Option < Self :: Output > {
588
+ self . get ( index) . cloned ( )
589
+ }
590
+ }
591
+ impl < T : Clone > AtIndex for Instances < T > {
592
+ type Output = Instances < T > ;
593
+
594
+ fn at_index ( & self , index : usize ) -> Option < Self :: Output > {
595
+ let mut result_table = Self :: default ( ) ;
596
+ if let Some ( row) = self . instance_ref_iter ( ) . nth ( index) {
597
+ result_table. push ( row. to_instance_cloned ( ) ) ;
598
+ Some ( result_table)
599
+ } else {
600
+ None
601
+ }
602
+ }
603
+ }
You can’t perform that action at this time.
0 commit comments