@@ -99,59 +99,112 @@ HFlow(itemSpacing: 4, rowSpacing: 20) {
9999
100100![ HFlow] ( Resources/hflow-spacing.png )
101101
102- ## Justified
102+ ## Distribute items
103103
104- Justify by stretching items, the spaces between them, or both.
104+ Distribute items evenly by minimizing the empty spaces left in each row.
105+ Implements the Knuth-Plass line breaking algorithm.
105106
106107``` swift
107- HFlow (justification : . stretchItems ) {
108+ HFlow (distributeItemsEvenly : true ) {
108109 ForEach (colors, id : \.description ) { color in
109110 RoundedRectangle (cornerRadius : 10 )
110111 .fill (color.gradient )
111- .frame (height : 50 )
112- .frame (minWidth : 35 )
112+ .frame (width : 65 , height : 50 )
113113 }
114114}
115- .frame (width : 300 )
115+ .frame (width : 300 , alignment : . leading )
116116```
117117
118- ![ HFlow] ( Resources/hflow-justified.png )
119-
120- ---
118+ ![ HFlow] ( Resources/hflow-distributed.png )
121119
122- Distribute items evenly by minimizing the empty spaces left in each row.
123- Implements the Knuth-Plass line breaking algorithm.
120+ ## Justified
124121
125122``` swift
126- HFlow (distributeItemsEvenly : true ) {
123+ HFlow (justified : true ) {
127124 ForEach (colors, id : \.description ) { color in
128125 RoundedRectangle (cornerRadius : 10 )
129126 .fill (color.gradient )
130- .frame (width : 65 , height : 50 )
127+ .frame (width : 50 , height : 50 )
131128 }
132129}
133- .frame (width : 300 , alignment : . leading )
130+ .frame (width : 300 )
134131```
135132
136- ![ HFlow] ( Resources/hflow-distributed.png )
133+ ![ HFlow] ( Resources/hflow-justified.png )
134+
135+ ## Flexibility
136+
137+ ``` swift
138+ HFlow { // distributes flexible items proportionally
139+ RoundedRectangle (cornerRadius : 10 )
140+ .fill (.red )
141+ .frame (minWidth : 50 , maxWidth : .infinity )
142+ .frame (height : 50 )
143+ .flexibility (.minimum ) // takes as little space as possible, rigid
144+ RoundedRectangle (cornerRadius : 10 )
145+ .fill (.green )
146+ .frame (minWidth : 50 , maxWidth : .infinity )
147+ .frame (height : 50 )
148+ .flexibility (.natural ) // expands
149+ RoundedRectangle (cornerRadius : 10 )
150+ .fill (.blue )
151+ .frame (minWidth : 50 , maxWidth : .infinity )
152+ .frame (height : 50 )
153+ .flexibility (.natural ) // expands
154+ RoundedRectangle (cornerRadius : 10 )
155+ .fill (.yellow )
156+ .frame (minWidth : 50 , maxWidth : .infinity )
157+ .frame (height : 50 ) // takes as much space as possible
158+ .flexibility (.maximum )
159+ }
160+ .frame (width : 300 )
161+ ```
137162
138- ---
163+ ![ HFlow ] ( Resources/hflow-flexibility.png )
139164
140- Distribute and justify for visually pleasing UI.
165+ ## Line breaks
141166
142167``` swift
143- HFlow (justification : .stretchItems , distributeItemsEvenly : true ) {
144- ForEach (colors, id : \.description ) { color in
145- RoundedRectangle (cornerRadius : 10 )
146- .fill (color.gradient )
147- .frame (height : 50 )
148- .frame (minWidth : 60 )
149- }
168+ HFlow {
169+ RoundedRectangle (cornerRadius : 10 )
170+ .fill (.red )
171+ .frame (width : 50 , height : 50 )
172+ RoundedRectangle (cornerRadius : 10 )
173+ .fill (.green )
174+ .frame (width : 50 , height : 50 )
175+ RoundedRectangle (cornerRadius : 10 )
176+ .fill (.blue )
177+ .frame (width : 50 , height : 50 )
178+ LineBreak ()
179+ RoundedRectangle (cornerRadius : 10 )
180+ .fill (.yellow )
181+ .frame (width : 50 , height : 50 )
182+ }
183+ .frame (width : 300 )
184+ ```
185+
186+ ![ HFlow] ( Resources/hflow-linebreak.png )
187+
188+ ``` swift
189+ HFlow {
190+ RoundedRectangle (cornerRadius : 10 )
191+ .fill (.red )
192+ .frame (width : 50 , height : 50 )
193+ RoundedRectangle (cornerRadius : 10 )
194+ .fill (.green )
195+ .frame (width : 50 , height : 50 )
196+ .startInNewLine ()
197+ RoundedRectangle (cornerRadius : 10 )
198+ .fill (.blue )
199+ .frame (width : 50 , height : 50 )
200+ RoundedRectangle (cornerRadius : 10 )
201+ .fill (.yellow )
202+ .frame (width : 50 , height : 50 )
150203}
151204.frame (width : 300 )
152205```
153206
154- ![ HFlow] ( Resources/hflow-justified-and-distributed .png )
207+ ![ HFlow] ( Resources/hflow-newline .png )
155208
156209## RTL
157210
0 commit comments