@@ -32,6 +32,8 @@ pub struct State {
3232 pub timing_method : TimingMethod ,
3333 /// The state of all the segments.
3434 pub segments : Vec < Segment > ,
35+ /// The native segment groups of the run.
36+ pub segment_groups : Vec < SegmentGroup > ,
3537 /// The names of all the custom comparisons that exist for this Run.
3638 pub comparison_names : Vec < String > ,
3739 /// Describes which actions are currently available.
@@ -86,19 +88,17 @@ pub struct Segment {
8688 pub comparison_times : Vec < String > ,
8789 /// Describes the segment's selection state.
8890 pub selected : SelectionState ,
89- /// Describes how this segment participates in a native segment group .
90- pub segment_group : SegmentGroupState ,
91+ /// The index of the group this segment belongs to, if any .
92+ pub segment_group_index : Option < usize > ,
9193}
9294
93- /// Describes a segment's role in a native segment group.
95+ /// Describes a native segment group.
9496#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
95- pub struct SegmentGroupState {
96- /// The index of the group this segment belongs to, if any.
97- pub group_index : Option < usize > ,
98- /// Whether this segment is a subsplit inside the group.
99- pub is_subsplit : bool ,
100- /// Whether this segment is the major split ending the group.
101- pub is_major_split : bool ,
97+ pub struct SegmentGroup {
98+ /// The first segment in the group.
99+ pub start : usize ,
100+ /// The segment after the last segment in the group.
101+ pub end : usize ,
102102 /// The explicit group name. If this is `None`, the major split name is the
103103 /// display name of the group.
104104 pub name : Option < String > ,
@@ -171,6 +171,24 @@ impl Editor {
171171 can_create_segment_group : self . can_create_segment_group_from_selection ( ) ,
172172 can_remove_segment_group : self . can_remove_active_segment_group ( ) ,
173173 } ;
174+ let mut segment_groups = Vec :: with_capacity ( self . run . segment_groups ( ) . groups ( ) . len ( ) ) ;
175+ for group in self . run . segment_groups ( ) . groups ( ) {
176+ let ( group_icon, has_explicit_icon) = group. icon ( ) . map_or (
177+ ( self . run . segment ( group. major_index ( ) ) . icon ( ) , false ) ,
178+ |icon| ( icon, true ) ,
179+ ) ;
180+ let icon = * image_cache
181+ . cache ( group_icon. id ( ) , || group_icon. clone ( ) )
182+ . id ( ) ;
183+ segment_groups. push ( SegmentGroup {
184+ start : group. start ( ) ,
185+ end : group. end ( ) ,
186+ name : group. name ( ) . map ( str:: to_owned) ,
187+ icon,
188+ has_explicit_icon,
189+ } ) ;
190+ }
191+
174192 let mut segments = Vec :: with_capacity ( self . run . len ( ) ) ;
175193
176194 for segment_index in 0 ..self . run . len ( ) {
@@ -198,36 +216,10 @@ impl Editor {
198216 SelectionState :: NotSelected
199217 } ;
200218
201- let segment_group = self
219+ let segment_group_index = self
202220 . run
203221 . segment_groups ( )
204- . group_index_for_segment ( segment_index)
205- . map ( |group_index| {
206- let group = & self . run . segment_groups ( ) . groups ( ) [ group_index] ;
207- let ( group_icon, has_explicit_icon) = group. icon ( ) . map_or (
208- ( self . run . segment ( group. major_index ( ) ) . icon ( ) , false ) ,
209- |icon| ( icon, true ) ,
210- ) ;
211- let icon = * image_cache
212- . cache ( group_icon. id ( ) , || group_icon. clone ( ) )
213- . id ( ) ;
214- SegmentGroupState {
215- group_index : Some ( group_index) ,
216- is_subsplit : segment_index < group. major_index ( ) ,
217- is_major_split : segment_index == group. major_index ( ) ,
218- name : group. name ( ) . map ( str:: to_owned) ,
219- icon,
220- has_explicit_icon,
221- }
222- } )
223- . unwrap_or ( SegmentGroupState {
224- group_index : None ,
225- is_subsplit : false ,
226- is_major_split : false ,
227- name : None ,
228- icon : * ImageId :: EMPTY ,
229- has_explicit_icon : false ,
230- } ) ;
222+ . group_index_for_segment ( segment_index) ;
231223
232224 segments. push ( Segment {
233225 icon,
@@ -237,7 +229,7 @@ impl Editor {
237229 best_segment_time,
238230 comparison_times,
239231 selected,
240- segment_group ,
232+ segment_group_index ,
241233 } ) ;
242234 }
243235
@@ -249,6 +241,7 @@ impl Editor {
249241 attempts,
250242 timing_method,
251243 segments,
244+ segment_groups,
252245 comparison_names,
253246 buttons,
254247 metadata : self . run . metadata ( ) . clone ( ) ,
0 commit comments