@@ -47,22 +47,20 @@ pub fn new_svg_layer(svg: String, transform: glam::DAffine2, id: NodeId, parent:
4747 LayerNodeIdentifier :: new_unchecked ( id)
4848}
4949
50- /// Batch set all of the manipulator groups to mirror on a specific layer
51- pub fn set_manipulator_mirror_angle ( manipulator_groups : & [ ManipulatorGroup < ManipulatorGroupId > ] , layer : LayerNodeIdentifier , mirror_angle : bool , responses : & mut VecDeque < Message > ) {
50+ /// Batch set all of the manipulator groups to set their colinear handle state on a specific layer
51+ pub fn set_manipulator_colinear_handles_state ( manipulator_groups : & [ ManipulatorGroup < ManipulatorGroupId > ] , layer : LayerNodeIdentifier , colinear : bool , responses : & mut VecDeque < Message > ) {
5252 for manipulator_group in manipulator_groups {
5353 responses. add ( GraphOperationMessage :: Vector {
5454 layer,
55- modification : VectorDataModification :: SetManipulatorHandleMirroring {
56- id : manipulator_group. id ,
57- mirror_angle,
58- } ,
55+ modification : VectorDataModification :: SetManipulatorColinearHandlesState { id : manipulator_group. id , colinear } ,
5956 } ) ;
6057 }
6158}
6259
6360/// Locate the subpaths from the shape nodes of a particular layer
6461pub fn get_subpaths ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < & Vec < Subpath < ManipulatorGroupId > > > {
65- if let TaggedValue :: Subpaths ( subpaths) = NodeGraphLayer :: new ( layer, document_network) ?. find_input ( "Shape" , 0 ) ? {
62+ let path_data_node_input_index = 0 ;
63+ if let TaggedValue :: Subpaths ( subpaths) = NodeGraphLayer :: new ( layer, document_network) . find_input ( "Shape" , path_data_node_input_index) ? {
6664 Some ( subpaths)
6765 } else {
6866 None
@@ -71,7 +69,8 @@ pub fn get_subpaths(layer: LayerNodeIdentifier, document_network: &NodeNetwork)
7169
7270/// Locate the final pivot from the transform (TODO: decide how the pivot should actually work)
7371pub fn get_pivot ( layer : LayerNodeIdentifier , network : & NodeNetwork ) -> Option < DVec2 > {
74- if let TaggedValue :: DVec2 ( pivot) = NodeGraphLayer :: new ( layer, network) ?. find_input ( "Transform" , 5 ) ? {
72+ let pivot_node_input_index = 5 ;
73+ if let TaggedValue :: DVec2 ( pivot) = NodeGraphLayer :: new ( layer, network) . find_input ( "Transform" , pivot_node_input_index) ? {
7574 Some ( * pivot)
7675 } else {
7776 None
@@ -84,18 +83,19 @@ pub fn get_viewport_pivot(layer: LayerNodeIdentifier, document_network: &NodeNet
8483 document_metadata. transform_to_viewport ( layer) . transform_point2 ( min + ( max - min) * pivot)
8584}
8685
87- /// Get the currently mirrored handles for a particular layer from the shape node
88- pub fn get_mirror_handles ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < & Vec < ManipulatorGroupId > > {
89- if let TaggedValue :: ManipulatorGroupIds ( mirror_handles) = NodeGraphLayer :: new ( layer, document_network) ?. find_input ( "Shape" , 1 ) ? {
90- Some ( mirror_handles)
86+ /// Get the manipulator groups that currently have colinear handles for a particular layer from the shape node
87+ pub fn get_colinear_manipulators ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < & Vec < ManipulatorGroupId > > {
88+ let colinear_manipulators_node_input_index = 1 ;
89+ if let TaggedValue :: ManipulatorGroupIds ( manipulator_groups) = NodeGraphLayer :: new ( layer, document_network) . find_input ( "Shape" , colinear_manipulators_node_input_index) ? {
90+ Some ( manipulator_groups)
9191 } else {
9292 None
9393 }
9494}
9595
9696/// Get the current gradient of a layer from the closest Fill node
9797pub fn get_gradient ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < Gradient > {
98- let inputs = NodeGraphLayer :: new ( layer, document_network) ? . find_node_inputs ( "Fill" ) ?;
98+ let inputs = NodeGraphLayer :: new ( layer, document_network) . find_node_inputs ( "Fill" ) ?;
9999 let TaggedValue :: FillType ( FillType :: Gradient ) = inputs. get ( 1 ) ?. as_value ( ) ? else {
100100 return None ;
101101 } ;
@@ -125,7 +125,7 @@ pub fn get_gradient(layer: LayerNodeIdentifier, document_network: &NodeNetwork)
125125
126126/// Get the current fill of a layer from the closest Fill node
127127pub fn get_fill_color ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < Color > {
128- let inputs = NodeGraphLayer :: new ( layer, document_network) ? . find_node_inputs ( "Fill" ) ?;
128+ let inputs = NodeGraphLayer :: new ( layer, document_network) . find_node_inputs ( "Fill" ) ?;
129129 let TaggedValue :: Color ( color) = inputs. get ( 2 ) ?. as_value ( ) ? else {
130130 return None ;
131131 } ;
@@ -134,7 +134,7 @@ pub fn get_fill_color(layer: LayerNodeIdentifier, document_network: &NodeNetwork
134134
135135/// Get the current blend mode of a layer from the closest Blend Mode node
136136pub fn get_blend_mode ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < BlendMode > {
137- let inputs = NodeGraphLayer :: new ( layer, document_network) ? . find_node_inputs ( "Blend Mode" ) ?;
137+ let inputs = NodeGraphLayer :: new ( layer, document_network) . find_node_inputs ( "Blend Mode" ) ?;
138138 let TaggedValue :: BlendMode ( blend_mode) = inputs. get ( 1 ) ?. as_value ( ) ? else {
139139 return None ;
140140 } ;
@@ -149,24 +149,24 @@ pub fn get_blend_mode(layer: LayerNodeIdentifier, document_network: &NodeNetwork
149149/// - The default value of 100% if no Opacity node is present, but this function returns None in that case
150150/// With those limitations in mind, the intention of this function is to show just the value already present in an upstream Opacity node so that value can be directly edited.
151151pub fn get_opacity ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < f64 > {
152- let inputs = NodeGraphLayer :: new ( layer, document_network) ? . find_node_inputs ( "Opacity" ) ?;
152+ let inputs = NodeGraphLayer :: new ( layer, document_network) . find_node_inputs ( "Opacity" ) ?;
153153 let TaggedValue :: F64 ( opacity) = inputs. get ( 1 ) ?. as_value ( ) ? else {
154154 return None ;
155155 } ;
156156 Some ( * opacity)
157157}
158158
159159pub fn get_fill_id ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < NodeId > {
160- NodeGraphLayer :: new ( layer, document_network) ? . node_id ( "Fill" )
160+ NodeGraphLayer :: new ( layer, document_network) . node_id ( "Fill" )
161161}
162162
163163pub fn get_text_id ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < NodeId > {
164- NodeGraphLayer :: new ( layer, document_network) ? . node_id ( "Text" )
164+ NodeGraphLayer :: new ( layer, document_network) . node_id ( "Text" )
165165}
166166
167167/// Gets properties from the Text node
168168pub fn get_text ( layer : LayerNodeIdentifier , document_network : & NodeNetwork ) -> Option < ( & String , & Font , f64 ) > {
169- let inputs = NodeGraphLayer :: new ( layer, document_network) ? . find_node_inputs ( "Text" ) ?;
169+ let inputs = NodeGraphLayer :: new ( layer, document_network) . find_node_inputs ( "Text" ) ?;
170170 let NodeInput :: Value {
171171 tagged_value : TaggedValue :: String ( text) ,
172172 ..
@@ -195,7 +195,8 @@ pub fn get_text(layer: LayerNodeIdentifier, document_network: &NodeNetwork) -> O
195195}
196196
197197pub fn get_stroke_width ( layer : LayerNodeIdentifier , network : & NodeNetwork ) -> Option < f64 > {
198- if let TaggedValue :: F64 ( width) = NodeGraphLayer :: new ( layer, network) ?. find_input ( "Stroke" , 2 ) ? {
198+ let weight_node_input_index = 2 ;
199+ if let TaggedValue :: F64 ( width) = NodeGraphLayer :: new ( layer, network) . find_input ( "Stroke" , weight_node_input_index) ? {
199200 Some ( * width)
200201 } else {
201202 None
@@ -204,7 +205,7 @@ pub fn get_stroke_width(layer: LayerNodeIdentifier, network: &NodeNetwork) -> Op
204205
205206/// Checks if a specified layer uses an upstream node matching the given name.
206207pub fn is_layer_fed_by_node_of_name ( layer : LayerNodeIdentifier , document_network : & NodeNetwork , node_name : & str ) -> bool {
207- NodeGraphLayer :: new ( layer, document_network) . is_some_and ( |layer| layer . find_node_inputs ( node_name) . is_some ( ) )
208+ NodeGraphLayer :: new ( layer, document_network) . find_node_inputs ( node_name) . is_some ( )
208209}
209210
210211/// Convert subpaths to an iterator of manipulator groups
@@ -220,20 +221,16 @@ pub fn get_manipulator_from_id(subpaths: &[Subpath<ManipulatorGroupId>], id: Man
220221/// An immutable reference to a layer within the document node graph for easy access.
221222pub struct NodeGraphLayer < ' a > {
222223 node_graph : & ' a NodeNetwork ,
223- _outwards_links : HashMap < NodeId , Vec < NodeId > > ,
224224 layer_node : NodeId ,
225225}
226226
227227impl < ' a > NodeGraphLayer < ' a > {
228228 /// Get the layer node from the document
229- pub fn new ( layer : LayerNodeIdentifier , network : & ' a NodeNetwork ) -> Option < Self > {
230- let outwards_links = network. collect_outwards_links ( ) ;
231-
232- Some ( Self {
229+ pub fn new ( layer : LayerNodeIdentifier , network : & ' a NodeNetwork ) -> Self {
230+ Self {
233231 node_graph : network,
234- _outwards_links : outwards_links,
235232 layer_node : layer. to_node ( ) ,
236- } )
233+ }
237234 }
238235
239236 /// Return an iterator up the primary flow of the layer
@@ -257,6 +254,7 @@ impl<'a> NodeGraphLayer<'a> {
257254
258255 /// Find a specific input of a node within the layer's primary flow
259256 pub fn find_input ( & self , node_name : & str , index : usize ) -> Option < & ' a TaggedValue > {
257+ // TODO: Find a better way to accept a node input rather than using its index (which is quite unclear and fragile)
260258 self . find_node_inputs ( node_name) ?. get ( index) ?. as_value ( )
261259 }
262260}
0 commit comments