Skip to content

Commit 214329b

Browse files
martinfalisseawesomekling
authored andcommitted
LibWeb: Layout grid items after calculation
Now that the positions of each grid item have been calculated, and the sizes of the individual rows and columns ascertained, can actually layout the different items.
1 parent 58078c1 commit 214329b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ void GridFormattingContext::run(Box const& box, LayoutMode)
369369
// FIXME: 4.2. For dense packing:
370370
}
371371

372+
for (auto& positioned_box : positioned_boxes) {
373+
(void)layout_inside(positioned_box.box, LayoutMode::Normal);
374+
}
375+
372376
// https://drafts.csswg.org/css-grid/#overview-sizing
373377
// 2.3. Sizing the Grid
374378
// Once the grid items have been placed, the sizes of the grid tracks (rows and columns) are
@@ -965,6 +969,29 @@ void GridFormattingContext::run(Box const& box, LayoutMode)
965969
if (grid_row.max_track_sizing_function.is_length() && grid_row.max_track_sizing_function.length().is_auto())
966970
grid_row.base_size = max(grid_row.base_size, remaining_vertical_space / count_of_auto_max_row_tracks);
967971
}
972+
973+
// Do layout
974+
auto layout_box = [&](int row_start, int row_end, int column_start, int column_end, Box const& child_box) -> void {
975+
auto& child_box_state = m_state.get_mutable(child_box);
976+
float x_start = 0;
977+
float x_end = 0;
978+
float y_start = 0;
979+
float y_end = 0;
980+
for (int i = 0; i < column_start; i++)
981+
x_start += grid_columns[i].base_size;
982+
for (int i = 0; i < column_end; i++)
983+
x_end += grid_columns[i].base_size;
984+
for (int i = 0; i < row_start; i++)
985+
y_start += grid_rows[i].base_size;
986+
for (int i = 0; i < row_end; i++)
987+
y_end += grid_rows[i].base_size;
988+
child_box_state.set_content_width(x_end - x_start);
989+
child_box_state.set_content_height(y_end - y_start);
990+
child_box_state.offset = { x_start, y_start };
991+
};
992+
993+
for (auto& positioned_box : positioned_boxes)
994+
layout_box(positioned_box.row, positioned_box.row + positioned_box.row_span, positioned_box.column, positioned_box.column + positioned_box.column_span, positioned_box.box);
968995
}
969996

970997
}

0 commit comments

Comments
 (0)