@@ -3,7 +3,7 @@ use super::node_graph::utility_types::Transform;
33use super :: utility_types:: error:: EditorError ;
44use super :: utility_types:: misc:: { GroupFolderType , SNAP_FUNCTIONS_FOR_BOUNDING_BOXES , SNAP_FUNCTIONS_FOR_PATHS , SnappingOptions , SnappingState } ;
55use super :: utility_types:: network_interface:: { self , NodeNetworkInterface , TransactionStatus } ;
6- use super :: utility_types:: nodes:: { CollapsedLayers , SelectedNodes } ;
6+ use super :: utility_types:: nodes:: { CollapsedLayers , LayerStructureEntry , SelectedNodes } ;
77use crate :: application:: { GRAPHITE_GIT_COMMIT_HASH , generate_uuid} ;
88use crate :: consts:: { ASYMPTOTIC_EFFECT , COLOR_OVERLAY_GRAY , DEFAULT_DOCUMENT_NAME , FILE_EXTENSION , SCALE_EFFECT , SCROLLBAR_SPACING , VIEWPORT_ROTATE_SNAP_INTERVAL } ;
99use crate :: messages:: input_mapper:: utility_types:: macros:: action_shortcut;
@@ -19,7 +19,6 @@ use crate::messages::portfolio::document::properties_panel::properties_panel_mes
1919use crate :: messages:: portfolio:: document:: utility_types:: document_metadata:: { DocumentMetadata , LayerNodeIdentifier } ;
2020use crate :: messages:: portfolio:: document:: utility_types:: misc:: { AlignAggregate , AlignAxis , FlipAxis , PTZ } ;
2121use crate :: messages:: portfolio:: document:: utility_types:: network_interface:: { FlowType , InputConnector , NodeTemplate } ;
22- use crate :: messages:: portfolio:: document:: utility_types:: nodes:: RawBuffer ;
2322use crate :: messages:: portfolio:: utility_types:: { PanelType , PersistentData } ;
2423use crate :: messages:: prelude:: * ;
2524use crate :: messages:: tool:: common_functionality:: graph_modification_utils:: { self , get_blend_mode, get_fill, get_opacity} ;
@@ -317,8 +316,8 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
317316 DocumentMessage :: ClearLayersPanel => {
318317 // Send an empty layer list
319318 if layers_panel_open {
320- let data_buffer : RawBuffer = Self :: default ( ) . serialize_root ( ) ;
321- responses. add ( FrontendMessage :: UpdateDocumentLayerStructure { data_buffer } ) ;
319+ let layer_structure = Self :: default ( ) . build_layer_structure ( LayerNodeIdentifier :: ROOT_PARENT ) ;
320+ responses. add ( FrontendMessage :: UpdateDocumentLayerStructure { layer_structure } ) ;
322321 }
323322
324323 // Clear the control bar
@@ -380,12 +379,12 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
380379 DocumentMessage :: DocumentStructureChanged => {
381380 if layers_panel_open {
382381 self . network_interface . load_structure ( ) ;
383- let data_buffer : RawBuffer = self . serialize_root ( ) ;
382+ let layer_structure = self . build_layer_structure ( LayerNodeIdentifier :: ROOT_PARENT ) ;
384383
385384 self . update_layers_panel_control_bar_widgets ( layers_panel_open, responses) ;
386385 self . update_layers_panel_bottom_bar_widgets ( layers_panel_open, responses) ;
387386
388- responses. add ( FrontendMessage :: UpdateDocumentLayerStructure { data_buffer } ) ;
387+ responses. add ( FrontendMessage :: UpdateDocumentLayerStructure { layer_structure } ) ;
389388 }
390389 }
391390 DocumentMessage :: DrawArtboardOverlays { context : overlay_context } => {
@@ -1891,70 +1890,22 @@ impl DocumentMessageHandler {
18911890 Ok ( document_message_handler)
18921891 }
18931892
1894- /// Called recursively by the entry function [`serialize_root`].
1895- fn serialize_structure ( & self , folder : LayerNodeIdentifier , structure_section : & mut Vec < u64 > , data_section : & mut Vec < u64 > , path : & mut Vec < LayerNodeIdentifier > ) {
1896- let mut space = 0 ;
1897- for layer_node in folder. children ( self . metadata ( ) ) {
1898- data_section. push ( layer_node. to_node ( ) . 0 ) ;
1899- space += 1 ;
1900- if layer_node. has_children ( self . metadata ( ) ) && !self . collapsed . 0 . contains ( & layer_node) {
1901- path. push ( layer_node) ;
1902-
1903- // TODO: Skip if folder is not expanded.
1904- structure_section. push ( space) ;
1905- self . serialize_structure ( layer_node, structure_section, data_section, path) ;
1906- space = 0 ;
1907-
1908- path. pop ( ) ;
1909- }
1910- }
1911- structure_section. push ( space | ( 1 << 63 ) ) ;
1912- }
1913-
1914- /// Serializes the layer structure into a condensed 1D structure.
1915- ///
1916- /// # Format
1917- /// It is a string of numbers broken into three sections:
1918- ///
1919- /// | Data | Description | Length |
1920- /// |------------------------------------------------------------------------------------------------------------------------------ |---------------------------------------------------------------|------------------|
1921- /// | `4,` `2, 1, -2, -0,` `16533113728871998040,3427872634365736244,18115028555707261608,15878401910454357952,449479075714955186` | Encoded example data | |
1922- /// | _____________________________________________________________________________________________________________________________ | _____________________________________________________________ | ________________ |
1923- /// | **Length** section: `4` | Length of the **Structure** section (`L` = `structure.len()`) | First value |
1924- /// | **Structure** section: `2, 1, -2, -0` | The **Structure** section | Next `L` values |
1925- /// | **Data** section: `16533113728871998040, 3427872634365736244, 18115028555707261608, 15878401910454357952, 449479075714955186` | The **Data** section (layer IDs) | Remaining values |
1926- ///
1927- /// The data section lists the layer IDs for all folders/layers in the tree as read from top to bottom.
1928- /// The structure section lists signed numbers. The sign indicates a folder indentation change (`+` is down a level, `-` is up a level).
1929- /// The numbers in the structure block encode the indentation. For example:
1930- /// - `2` means read two elements from the data section, then place a `[`.
1931- /// - `-x` means read `x` elements from the data section and then insert a `]`.
1932- ///
1933- /// ```text
1934- /// 2 V 1 V -2 A -0 A
1935- /// 16533113728871998040,3427872634365736244, 18115028555707261608, 15878401910454357952,449479075714955186
1936- /// 16533113728871998040,3427872634365736244,[ 18115028555707261608,[15878401910454357952,449479075714955186] ]
1937- /// ```
1938- ///
1939- /// Resulting layer panel:
1940- /// ```text
1941- /// 16533113728871998040
1942- /// 3427872634365736244
1943- /// [3427872634365736244,18115028555707261608]
1944- /// [3427872634365736244,18115028555707261608,15878401910454357952]
1945- /// [3427872634365736244,18115028555707261608,449479075714955186]
1946- /// ```
1947- pub fn serialize_root ( & self ) -> RawBuffer {
1948- let mut structure_section = vec ! [ NodeId ( 0 ) . 0 ] ;
1949- let mut data_section = Vec :: new ( ) ;
1950- self . serialize_structure ( LayerNodeIdentifier :: ROOT_PARENT , & mut structure_section, & mut data_section, & mut vec ! [ ] ) ;
1951-
1952- // Remove the ROOT element. Prepend `L`, the length (excluding the ROOT) of the structure section (which happens to be where the ROOT element was).
1953- structure_section[ 0 ] = structure_section. len ( ) as u64 - 1 ;
1954- // Append the data section to the end.
1955- structure_section. extend ( data_section) ;
1956-
1957- structure_section. as_slice ( ) . into ( )
1893+ /// Recursively builds the layer structure tree for a folder.
1894+ fn build_layer_structure ( & self , folder : LayerNodeIdentifier ) -> Vec < LayerStructureEntry > {
1895+ folder
1896+ . children ( self . metadata ( ) )
1897+ . map ( |layer_node| {
1898+ let children = if layer_node. has_children ( self . metadata ( ) ) && !self . collapsed . 0 . contains ( & layer_node) {
1899+ self . build_layer_structure ( layer_node)
1900+ } else {
1901+ Vec :: new ( )
1902+ } ;
1903+ LayerStructureEntry {
1904+ layer_id : layer_node. to_node ( ) ,
1905+ children,
1906+ }
1907+ } )
1908+ . collect ( )
19581909 }
19591910
19601911 pub fn undo_with_history ( & mut self , viewport : & ViewportMessageHandler , responses : & mut VecDeque < Message > ) {
0 commit comments