@@ -36,6 +36,11 @@ export interface GridLayoutOptions {
36
36
* @default 18 x 18
37
37
*/
38
38
minSpace ?: Size ,
39
+ /**
40
+ * The maximum allowed horizontal space between items.
41
+ * @default Infinity
42
+ */
43
+ maxHorizontalSpace ?: number ,
39
44
/**
40
45
* The maximum number of columns.
41
46
* @default Infinity
@@ -53,6 +58,7 @@ const DEFAULT_OPTIONS = {
53
58
maxItemSize : new Size ( Infinity , Infinity ) ,
54
59
preserveAspectRatio : false ,
55
60
minSpace : new Size ( 18 , 18 ) ,
61
+ maxSpace : Infinity ,
56
62
maxColumns : Infinity ,
57
63
dropIndicatorThickness : 2
58
64
} ;
@@ -69,14 +75,16 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
69
75
protected numColumns : number = 0 ;
70
76
private contentSize : Size = new Size ( ) ;
71
77
private layoutInfos : Map < Key , LayoutInfo > = new Map ( ) ;
78
+ private margin : number = 0 ;
72
79
73
80
shouldInvalidateLayoutOptions ( newOptions : O , oldOptions : O ) : boolean {
74
81
return newOptions . maxColumns !== oldOptions . maxColumns
75
82
|| newOptions . dropIndicatorThickness !== oldOptions . dropIndicatorThickness
76
83
|| newOptions . preserveAspectRatio !== oldOptions . preserveAspectRatio
77
84
|| ( ! ( newOptions . minItemSize || DEFAULT_OPTIONS . minItemSize ) . equals ( oldOptions . minItemSize || DEFAULT_OPTIONS . minItemSize ) )
78
85
|| ( ! ( newOptions . maxItemSize || DEFAULT_OPTIONS . maxItemSize ) . equals ( oldOptions . maxItemSize || DEFAULT_OPTIONS . maxItemSize ) )
79
- || ( ! ( newOptions . minSpace || DEFAULT_OPTIONS . minSpace ) . equals ( oldOptions . minSpace || DEFAULT_OPTIONS . minSpace ) ) ;
86
+ || ( ! ( newOptions . minSpace || DEFAULT_OPTIONS . minSpace ) . equals ( oldOptions . minSpace || DEFAULT_OPTIONS . minSpace ) )
87
+ || newOptions . maxHorizontalSpace !== oldOptions . maxHorizontalSpace ;
80
88
}
81
89
82
90
update ( invalidationContext : InvalidationContext < O > ) : void {
@@ -85,6 +93,7 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
85
93
maxItemSize = DEFAULT_OPTIONS . maxItemSize ,
86
94
preserveAspectRatio = DEFAULT_OPTIONS . preserveAspectRatio ,
87
95
minSpace = DEFAULT_OPTIONS . minSpace ,
96
+ maxHorizontalSpace = DEFAULT_OPTIONS . maxSpace ,
88
97
maxColumns = DEFAULT_OPTIONS . maxColumns ,
89
98
dropIndicatorThickness = DEFAULT_OPTIONS . dropIndicatorThickness
90
99
} = invalidationContext . layoutOptions || { } ;
@@ -116,9 +125,10 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
116
125
let itemHeight = minItemSize . height + Math . floor ( ( maxItemHeight - minItemSize . height ) * t ) ;
117
126
itemHeight = Math . max ( minItemSize . height , Math . min ( maxItemHeight , itemHeight ) ) ;
118
127
119
- // Compute the horizontal spacing and content height
120
- let horizontalSpacing = Math . floor ( ( visibleWidth - numColumns * itemWidth ) / ( numColumns + 1 ) ) ;
128
+ // Compute the horizontal spacing, content height and horizontal margin
129
+ let horizontalSpacing = Math . min ( maxHorizontalSpace , Math . floor ( ( visibleWidth - numColumns * itemWidth ) / ( numColumns + 1 ) ) ) ;
121
130
this . gap = new Size ( horizontalSpacing , minSpace . height ) ;
131
+ this . margin = Math . floor ( ( visibleWidth - numColumns * itemWidth - horizontalSpacing * ( numColumns + 1 ) ) / 2 ) ;
122
132
123
133
// If there is a skeleton loader within the last 2 items in the collection, increment the collection size
124
134
// so that an additional row is added for the skeletons.
@@ -133,7 +143,7 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
133
143
}
134
144
lastKey = collection . getKeyBefore ( lastKey ) ;
135
145
}
136
-
146
+
137
147
let rows = Math . ceil ( collectionSize / numColumns ) ;
138
148
let iterator = collection [ Symbol . iterator ] ( ) ;
139
149
let y = rows > 0 ? minSpace . height : 0 ;
@@ -165,7 +175,7 @@ export class GridLayout<T, O extends GridLayoutOptions = GridLayoutOptions> exte
165
175
if ( skeleton ) {
166
176
content = oldLayoutInfo && oldLayoutInfo . content . key === key ? oldLayoutInfo . content : { ...skeleton , key} ;
167
177
}
168
- let x = horizontalSpacing + col * ( itemWidth + horizontalSpacing ) ;
178
+ let x = horizontalSpacing + col * ( itemWidth + horizontalSpacing ) + this . margin ;
169
179
let height = itemHeight ;
170
180
let estimatedSize = ! preserveAspectRatio ;
171
181
if ( oldLayoutInfo && estimatedSize ) {
0 commit comments