@@ -4,7 +4,6 @@ use crate::axis::{AbsoluteAxis, AbstractAxis, InBothAbsAxis};
4
4
use crate :: geometry:: { Line , Point , Rect , Size } ;
5
5
use crate :: layout:: { Layout , RunMode , SizeAndBaselines , SizingMode } ;
6
6
use crate :: math:: MaybeMath ;
7
- use crate :: node:: Node ;
8
7
use crate :: resolve:: { MaybeResolve , ResolveOrZero } ;
9
8
use crate :: style:: { AlignContent , AlignItems , AlignSelf , AvailableSpace , Display , Position } ;
10
9
use crate :: style_helpers:: * ;
@@ -17,14 +16,14 @@ use placement::place_grid_items;
17
16
use track_sizing:: {
18
17
determine_if_item_crosses_flexible_or_intrinsic_tracks, resolve_item_track_indexes, track_sizing_algorithm,
19
18
} ;
20
- use types:: { CellOccupancyMatrix , GridTrack } ;
19
+ use types:: { CellOccupancyMatrix , GridItem , GridTrack } ;
21
20
22
21
pub ( crate ) use types:: { GridCoordinate , GridLine , OriginZeroLine } ;
23
22
24
23
#[ cfg( feature = "debug" ) ]
25
24
use crate :: debug:: NODE_LOGGER ;
26
25
27
- use super :: { GenericAlgorithm , LayoutAlgorithm } ;
26
+ use super :: LayoutAlgorithm ;
28
27
29
28
mod alignment;
30
29
mod explicit_grid;
@@ -35,30 +34,30 @@ mod types;
35
34
mod util;
36
35
37
36
/// The public interface to Taffy's CSS Grid algorithm implementation
38
- pub ( crate ) struct CssGridAlgorithm ;
37
+ pub struct CssGridAlgorithm ;
39
38
impl LayoutAlgorithm for CssGridAlgorithm {
40
39
const NAME : & ' static str = "CSS GRID" ;
41
40
41
+ #[ inline( always) ]
42
42
fn perform_layout (
43
43
tree : & mut impl LayoutTree ,
44
- node : Node ,
45
44
known_dimensions : Size < Option < f32 > > ,
46
45
parent_size : Size < Option < f32 > > ,
47
46
available_space : Size < AvailableSpace > ,
48
47
_sizing_mode : SizingMode ,
49
48
) -> SizeAndBaselines {
50
- compute ( tree, node , known_dimensions, parent_size, available_space, RunMode :: PeformLayout )
49
+ compute ( tree, known_dimensions, parent_size, available_space, RunMode :: PeformLayout )
51
50
}
52
51
52
+ #[ inline( always) ]
53
53
fn measure_size (
54
54
tree : & mut impl LayoutTree ,
55
- node : Node ,
56
55
known_dimensions : Size < Option < f32 > > ,
57
56
parent_size : Size < Option < f32 > > ,
58
57
available_space : Size < AvailableSpace > ,
59
58
_sizing_mode : SizingMode ,
60
59
) -> Size < f32 > {
61
- compute ( tree, node , known_dimensions, parent_size, available_space, RunMode :: ComputeSize ) . size
60
+ compute ( tree, known_dimensions, parent_size, available_space, RunMode :: ComputeSize ) . size
62
61
}
63
62
}
64
63
@@ -68,17 +67,16 @@ impl LayoutAlgorithm for CssGridAlgorithm {
68
67
/// - Placing items (which also resolves the implicit grid)
69
68
/// - Track (row/column) sizing
70
69
/// - Alignment & Final item placement
71
- pub fn compute (
72
- tree : & mut impl LayoutTree ,
73
- node : Node ,
70
+ pub fn compute < Tree : LayoutTree > (
71
+ tree : & mut Tree ,
74
72
known_dimensions : Size < Option < f32 > > ,
75
73
parent_size : Size < Option < f32 > > ,
76
74
available_space : Size < AvailableSpace > ,
77
75
run_mode : RunMode ,
78
76
) -> SizeAndBaselines {
79
- let get_child_styles_iter = |node | tree. children ( node ) . map ( |child_node : & Node | tree. style ( * child_node) ) ;
80
- let style = tree. style ( node ) . clone ( ) ;
81
- let child_styles_iter = get_child_styles_iter ( node ) ;
77
+ let get_child_styles_iter = || tree. children ( ) . map ( |child_node : Tree :: ChildId | tree. child_style ( child_node) ) ;
78
+ let style = tree. style ( ) . clone ( ) ;
79
+ let child_styles_iter = get_child_styles_iter ( ) ;
82
80
83
81
// 1. Resolve the explicit grid
84
82
// Exactly compute the number of rows and columns in the explicit grid.
@@ -93,13 +91,12 @@ pub fn compute(
93
91
94
92
// 2. Grid Item Placement
95
93
// Match items (children) to a definite grid position (row start/end and column start/end position)
96
- let mut items = Vec :: with_capacity ( tree. child_count ( node ) ) ;
94
+ let mut items: Vec < GridItem < Tree > > = Vec :: with_capacity ( tree. child_count ( ) ) ;
97
95
let mut cell_occupancy_matrix = CellOccupancyMatrix :: with_track_counts ( est_col_counts, est_row_counts) ;
98
96
let in_flow_children_iter = || {
99
- tree. children ( node)
100
- . copied ( )
97
+ tree. children ( )
101
98
. enumerate ( )
102
- . map ( |( index, child_node) | ( index, child_node, tree. style ( child_node) ) )
99
+ . map ( |( index, child_node) | ( index, child_node, tree. child_style ( child_node) ) )
103
100
. filter ( |( _, _, style) | style. display != Display :: None && style. position != Position :: Absolute )
104
101
} ;
105
102
place_grid_items (
@@ -443,21 +440,14 @@ pub fn compute(
443
440
444
441
// Position hidden and absolutely positioned children
445
442
let mut order = items. len ( ) as u32 ;
446
- ( 0 ..tree. child_count ( node ) ) . for_each ( |index| {
447
- let child = tree. child ( node , index) ;
448
- let child_style = tree. style ( child) ;
443
+ ( 0 ..tree. child_count ( ) ) . for_each ( |index| {
444
+ let child = tree. child ( index) ;
445
+ let child_style = tree. child_style ( child) ;
449
446
450
447
// Position hidden child
451
448
if child_style. display == Display :: None {
452
- * tree. layout_mut ( node) = Layout :: with_order ( order) ;
453
- GenericAlgorithm :: perform_layout (
454
- tree,
455
- child,
456
- Size :: NONE ,
457
- Size :: NONE ,
458
- Size :: MAX_CONTENT ,
459
- SizingMode :: InherentSize ,
460
- ) ;
449
+ * tree. layout_mut ( ) = Layout :: with_order ( order) ;
450
+ tree. perform_child_layout ( child, Size :: NONE , Size :: NONE , Size :: MAX_CONTENT , SizingMode :: InherentSize ) ;
461
451
order += 1 ;
462
452
return ;
463
453
}
@@ -526,7 +516,7 @@ pub fn compute(
526
516
& first_row_items[ 0 ]
527
517
} ;
528
518
529
- let layout = tree. layout_mut ( item. node ) ;
519
+ let layout = tree. child_layout_mut ( item. node ) ;
530
520
layout. location . y + item. baseline . unwrap_or ( layout. size . height )
531
521
} ;
532
522
0 commit comments