@@ -108,6 +108,7 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
108108 GraphOperationMessage :: NewArtboard { id, artboard } => {
109109 let mut modify_inputs = ModifyInputsContext :: new ( network_interface, responses) ;
110110
111+ let artboard_location = artboard. location ;
111112 let artboard_layer = modify_inputs. create_artboard ( id, artboard) ;
112113 network_interface. move_layer_to_stack ( artboard_layer, LayerNodeIdentifier :: ROOT_PARENT , 0 , & [ ] ) ;
113114
@@ -116,13 +117,33 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
116117 log:: error!( "Artboard not created" ) ;
117118 return ;
118119 } ;
120+ let document_metadata = network_interface. document_metadata ( ) ;
121+
119122 let primary_input = artboard. inputs . first ( ) . expect ( "Artboard should have a primary input" ) . clone ( ) ;
120123 if let NodeInput :: Node { node_id, .. } = & primary_input {
121- if network_interface. is_layer ( node_id, & [ ] ) && !network_interface. is_artboard ( node_id, & [ ] ) {
122- network_interface. move_layer_to_stack ( LayerNodeIdentifier :: new ( * node_id, network_interface) , artboard_layer, 0 , & [ ] ) ;
124+ if network_interface. is_artboard ( node_id, & [ ] ) {
125+ // Nothing to do here: we have a stack full of artboards!
126+ } else if network_interface. is_layer ( node_id, & [ ] ) {
127+ // We have a stack of non-layer artboards.
128+ for ( insert_index, layer) in LayerNodeIdentifier :: ROOT_PARENT . children ( document_metadata) . filter ( |& layer| layer != artboard_layer) . enumerate ( ) {
129+ // Parent the layer to our new artboard (retaining ordering)
130+ responses. add ( NodeGraphMessage :: MoveLayerToStack {
131+ layer,
132+ parent : artboard_layer,
133+ insert_index,
134+ } ) ;
135+ // Apply a translation to prevent the content from shifting
136+ responses. add ( GraphOperationMessage :: TransformChange {
137+ layer,
138+ transform : DAffine2 :: from_translation ( -artboard_location. as_dvec2 ( ) ) ,
139+ transform_in : TransformIn :: Local ,
140+ skip_rerender : true ,
141+ } ) ;
142+ }
123143 } else {
144+ // We have some non layers (e.g. just a rectangle node). We disconnect the bottom input and connect it to the left input.
124145 network_interface. disconnect_input ( & InputConnector :: node ( artboard_layer. to_node ( ) , 0 ) , & [ ] ) ;
125- network_interface. set_input ( & InputConnector :: node ( id , 0 ) , primary_input, & [ ] ) ;
146+ network_interface. set_input ( & InputConnector :: node ( artboard_layer . to_node ( ) , 1 ) , primary_input, & [ ] ) ;
126147 }
127148 }
128149 responses. add_front ( NodeGraphMessage :: SelectedNodesSet { nodes : vec ! [ id] } ) ;
0 commit comments