@@ -97,26 +97,48 @@ static void ui_flexbox_layout_next_line(ui_flexbox_layout_context_t *ctx)
97
97
list_append (& ctx -> lines , ctx -> line );
98
98
}
99
99
100
- LIBUI_INLINE float ui_compute_row_item_main_size (css_computed_style_t * s )
100
+ float ui_compute_row_item_main_size (ui_widget_t * item )
101
101
{
102
+ css_computed_style_t * s = & item -> computed_style ;
103
+ float spacing = css_padding_x (s ) + css_border_x (s );
104
+
105
+ if (s -> type_bits .flex_basis == CSS_FLEX_BASIS_CONTENT ) {
106
+ CSS_SET_FIXED_LENGTH (
107
+ s , flex_basis ,
108
+ css_convert_content_box_width (s , item -> max_content_width ));
109
+ }
102
110
if (css_computed_box_sizing (s ) == CSS_BOX_SIZING_BORDER_BOX ) {
103
- if (s -> flex_basis < css_padding_x ( s ) + css_border_x ( s ) ) {
104
- return 0 ;
111
+ if (s -> flex_basis < spacing ) {
112
+ s -> flex_basis = spacing ;
105
113
}
106
- return s -> flex_basis - css_padding_x ( s ) - css_border_x (s );
114
+ return s -> flex_basis + css_margin_x (s );
107
115
}
108
- return s -> flex_basis ;
116
+ if (s -> flex_basis < 0 ) {
117
+ s -> flex_basis = 0 ;
118
+ }
119
+ return s -> flex_basis + css_margin_x (s ) + spacing ;
109
120
}
110
121
111
- LIBUI_INLINE float ui_compute_column_item_main_size (css_computed_style_t * s )
122
+ float ui_compute_column_item_main_size (ui_widget_t * item )
112
123
{
124
+ css_computed_style_t * s = & item -> computed_style ;
125
+ float spacing = css_padding_y (s ) + css_border_y (s );
126
+
127
+ if (s -> type_bits .flex_basis == CSS_FLEX_BASIS_CONTENT ) {
128
+ CSS_SET_FIXED_LENGTH (s , flex_basis ,
129
+ css_convert_content_box_height (
130
+ s , item -> max_content_height ));
131
+ }
113
132
if (css_computed_box_sizing (s ) == CSS_BOX_SIZING_BORDER_BOX ) {
114
- if (s -> flex_basis < css_padding_y ( s ) + css_border_y ( s ) ) {
115
- return 0 ;
133
+ if (s -> flex_basis < spacing ) {
134
+ s -> flex_basis = spacing ;
116
135
}
117
- return s -> flex_basis - css_padding_y (s ) - css_border_y (s );
136
+ return s -> flex_basis + css_margin_y (s );
137
+ }
138
+ if (s -> flex_basis < 0 ) {
139
+ s -> flex_basis = 0 ;
118
140
}
119
- return s -> flex_basis ;
141
+ return s -> flex_basis + css_margin_y ( s ) + spacing ;
120
142
}
121
143
122
144
static void ui_flexbox_layout_load_rows (ui_flexbox_layout_context_t * ctx )
@@ -142,25 +164,14 @@ static void ui_flexbox_layout_load_rows(ui_flexbox_layout_context_t *ctx)
142
164
if (cs -> type_bits .display == CSS_DISPLAY_NONE ) {
143
165
continue ;
144
166
}
145
- ui_widget_reset_layout (child , ctx -> rule );
146
167
if (!ui_widget_in_layout_flow (child )) {
147
168
list_append (& ctx -> line -> items , child );
148
169
continue ;
149
170
}
171
+ ui_widget_reset_layout (child );
150
172
ui_widget_compute_style (child );
151
173
ui_widget_auto_reflow (child );
152
- switch (cs -> type_bits .flex_basis ) {
153
- case CSS_FLEX_BASIS_CONTENT :
154
- CSS_SET_FIXED_LENGTH (cs , flex_basis ,
155
- css_convert_content_box_width (
156
- cs , child -> max_content_width ));
157
- break ;
158
- default :
159
- break ;
160
- }
161
- main_size = ui_compute_row_item_main_size (cs ) +
162
- css_margin_x (cs ) + css_padding_x (cs ) +
163
- css_border_x (cs );
174
+ main_size = ui_compute_row_item_main_size (child );
164
175
#ifdef UI_DEBUG_ENABLED
165
176
{
166
177
UI_WIDGET_STR (child , str );
@@ -226,22 +237,14 @@ static void ui_flexbox_layout_load_columns(ui_flexbox_layout_context_t *ctx)
226
237
if (cs -> type_bits .display == CSS_DISPLAY_NONE ) {
227
238
continue ;
228
239
}
229
- ui_widget_reset_layout (child , ctx -> rule );
230
240
if (!ui_widget_in_layout_flow (child )) {
231
241
list_append (& ctx -> line -> items , child );
232
242
continue ;
233
243
}
244
+ ui_widget_reset_layout (child );
234
245
ui_widget_compute_style (child );
235
246
ui_widget_auto_reflow (child );
236
- if (cs -> type_bits .flex_basis == CSS_FLEX_BASIS_CONTENT ) {
237
- CSS_SET_FIXED_LENGTH (
238
- cs , flex_basis ,
239
- css_convert_content_box_height (
240
- cs , child -> max_content_height ));
241
- }
242
- main_size = ui_compute_column_item_main_size (cs ) +
243
- css_margin_y (cs ) + css_padding_y (cs ) +
244
- css_border_y (cs );
247
+ main_size = ui_compute_column_item_main_size (child );
245
248
#ifdef UI_DEBUG_ENABLED
246
249
{
247
250
UI_WIDGET_STR (child , str );
@@ -368,22 +371,22 @@ static void ui_flexbox_layout_update_row(ui_flexbox_layout_context_t *ctx)
368
371
369
372
for (list_each (node , & ctx -> line -> items )) {
370
373
child = node -> data ;
374
+ if (!ui_widget_in_layout_flow (child )) {
375
+ continue ;
376
+ }
371
377
s = & child -> computed_style ;
372
- ui_widget_reset_layout (child , ctx -> rule );
378
+ ui_widget_reset_layout (child );
373
379
ui_widget_compute_style (child );
374
- main_size = ui_compute_row_item_main_size (s );
375
- if (css_computed_box_sizing (s ) == CSS_BOX_SIZING_BORDER_BOX ) {
376
- main_size += css_border_x (s ) + css_padding_x (s );
377
- }
380
+ main_size = ui_compute_row_item_main_size (child );
378
381
// 根据项目的 flex-grow 和 flex-shrink,调整它的宽度
379
382
if (space >= 0 ) {
380
383
if (s -> type_bits .flex_grow > 0 ) {
381
384
CSS_SET_FIXED_LENGTH (
382
- s , width , main_size + k * s -> flex_grow );
385
+ s , width , s -> flex_basis + k * s -> flex_grow );
383
386
}
384
387
} else if (s -> type_bits .flex_shrink > 0 ) {
385
- CSS_SET_FIXED_LENGTH (s , width ,
386
- main_size + k * s -> flex_shrink );
388
+ CSS_SET_FIXED_LENGTH (
389
+ s , width , s -> flex_basis + k * s -> flex_shrink );
387
390
}
388
391
// 计算拉伸的高度
389
392
if (align_items == CSS_ALIGN_ITEMS_STRETCH &&
@@ -394,7 +397,7 @@ static void ui_flexbox_layout_update_row(ui_flexbox_layout_context_t *ctx)
394
397
css_margin_y (s )));
395
398
}
396
399
ui_widget_auto_reflow (child );
397
- main_axis += child -> outer_box . width ;
400
+ main_axis += main_size ;
398
401
}
399
402
ctx -> line -> main_size = main_axis ;
400
403
space = ctx -> widget -> content_box .width - main_axis ;
@@ -431,8 +434,11 @@ static void ui_flexbox_layout_update_row(ui_flexbox_layout_context_t *ctx)
431
434
#ifdef UI_DEBUG_ENABLED
432
435
{
433
436
UI_WIDGET_STR (ctx -> widget , str );
434
- UI_DEBUG_MSG ("%s: main_axis_start = %g, free_space = %g, justify_content = %d" ,
435
- str , main_axis , space , ctx -> widget -> computed_style .type_bits .justify_content );
437
+ UI_DEBUG_MSG (
438
+ "%s: main_axis_start = %g, free_space = %g, "
439
+ "justify_content = %d" ,
440
+ str , main_axis , space ,
441
+ ctx -> widget -> computed_style .type_bits .justify_content );
436
442
}
437
443
#endif
438
444
for (list_each (node , & ctx -> line -> items )) {
@@ -441,6 +447,7 @@ static void ui_flexbox_layout_update_row(ui_flexbox_layout_context_t *ctx)
441
447
child -> layout_x = main_axis ;
442
448
child -> layout_y = ctx -> line -> cross_axis ;
443
449
if (!ui_widget_in_layout_flow (child )) {
450
+ ui_widget_reset_layout (child );
444
451
ui_widget_compute_style (node -> data );
445
452
ui_widget_auto_reflow (node -> data );
446
453
ui_widget_update_box_position (node -> data );
@@ -497,22 +504,23 @@ static void ui_flexbox_layout_update_column(ui_flexbox_layout_context_t *ctx)
497
504
498
505
for (list_each (node , & ctx -> line -> items )) {
499
506
child = node -> data ;
507
+ if (!ui_widget_in_layout_flow (child )) {
508
+ continue ;
509
+ }
500
510
s = & child -> computed_style ;
501
- ui_widget_reset_layout (child , ctx -> rule );
511
+ ui_widget_reset_layout (child );
502
512
ui_widget_compute_style (child );
503
- main_size = ui_compute_column_item_main_size (s );
504
- if (css_computed_box_sizing (s ) == CSS_BOX_SIZING_BORDER_BOX ) {
505
- main_size += css_border_y (s ) + css_padding_y (s );
506
- }
513
+ main_size = ui_compute_column_item_main_size (child );
507
514
// 根据项目的 flex-grow 和 flex-shrink,调整它的高度
508
515
if (space >= 0 ) {
509
516
if (s -> type_bits .flex_grow > 0 ) {
510
517
CSS_SET_FIXED_LENGTH (
511
- s , height , main_size + k * s -> flex_grow );
518
+ s , height ,
519
+ s -> flex_basis + k * s -> flex_grow );
512
520
}
513
521
} else if (s -> type_bits .flex_shrink > 0 ) {
514
- CSS_SET_FIXED_LENGTH (s , height ,
515
- main_size + k * s -> flex_shrink );
522
+ CSS_SET_FIXED_LENGTH (
523
+ s , height , s -> flex_basis + k * s -> flex_shrink );
516
524
}
517
525
// 计算拉伸的宽度
518
526
if (align_items == CSS_ALIGN_ITEMS_STRETCH &&
@@ -523,7 +531,7 @@ static void ui_flexbox_layout_update_column(ui_flexbox_layout_context_t *ctx)
523
531
css_margin_x (s )));
524
532
}
525
533
ui_widget_auto_reflow (child );
526
- main_axis += child -> outer_box . height ;
534
+ main_axis += main_size ;
527
535
}
528
536
ctx -> line -> main_size = main_axis ;
529
537
space = ctx -> widget -> content_box .height - main_axis ;
@@ -563,6 +571,7 @@ static void ui_flexbox_layout_update_column(ui_flexbox_layout_context_t *ctx)
563
571
child -> layout_y = main_axis ;
564
572
child -> layout_x = ctx -> line -> cross_axis ;
565
573
if (!ui_widget_in_layout_flow (child )) {
574
+ ui_widget_reset_layout (child );
566
575
ui_widget_compute_style (node -> data );
567
576
ui_widget_auto_reflow (node -> data );
568
577
ui_widget_update_box_position (node -> data );
0 commit comments