mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:17:35 +00:00
LibWeb: New start at layouting out the grid
According to the spec it's necessary to: 1. Layout the cells in the grid 2. Find the sizes of the rows and columns Since I had started to do this backwards, and as I expand in future commits, I take here the opportunity to start with a clean state. The occupation_grid keeps track of which cells in the grid have been filled out.
This commit is contained in:
parent
df88e2bd8e
commit
a2ecb903af
1 changed files with 6 additions and 55 deletions
|
@ -35,59 +35,10 @@ void GridFormattingContext::run(Box const& box, LayoutMode)
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto number_of_columns = (int)box.computed_values().grid_template_columns().size();
|
Vector<Vector<bool>> occupation_grid;
|
||||||
struct GridRow {
|
Vector<bool> occupation_grid_row;
|
||||||
float height { 0 };
|
for (int column_index = 0; column_index < max((int)box.computed_values().grid_template_columns().size(), 1); column_index++)
|
||||||
Vector<Box&> boxes;
|
occupation_grid_row.append(false);
|
||||||
};
|
for (int row_index = 0; row_index < max((int)box.computed_values().grid_template_rows().size(), 1); row_index++)
|
||||||
Vector<GridRow> grid_rows;
|
occupation_grid.append(occupation_grid_row);
|
||||||
|
|
||||||
auto current_column_count = 0;
|
|
||||||
box.for_each_child_of_type<Box>([&](Box& child_box) {
|
|
||||||
if (should_skip_is_anonymous_text_run(child_box))
|
|
||||||
return IterationDecision::Continue;
|
|
||||||
|
|
||||||
if (current_column_count == 0)
|
|
||||||
grid_rows.append(GridRow());
|
|
||||||
GridRow& grid_row = grid_rows.last();
|
|
||||||
grid_row.boxes.append(child_box);
|
|
||||||
|
|
||||||
auto& child_box_state = m_state.get_mutable(child_box);
|
|
||||||
if (child_box_state.content_height() > grid_row.height)
|
|
||||||
grid_row.height = child_box_state.content_height();
|
|
||||||
(void)layout_inside(child_box, LayoutMode::Normal);
|
|
||||||
if (child_box_state.content_height() > grid_row.height)
|
|
||||||
grid_row.height = child_box_state.content_height();
|
|
||||||
|
|
||||||
current_column_count++;
|
|
||||||
if (current_column_count == number_of_columns)
|
|
||||||
current_column_count = 0;
|
|
||||||
return IterationDecision::Continue;
|
|
||||||
});
|
|
||||||
|
|
||||||
auto& box_state = m_state.get_mutable(box);
|
|
||||||
float current_y_position = 0;
|
|
||||||
current_column_count = 0;
|
|
||||||
for (auto& grid_row : grid_rows) {
|
|
||||||
for (auto& child_box : grid_row.boxes) {
|
|
||||||
if (should_skip_is_anonymous_text_run(child_box))
|
|
||||||
continue;
|
|
||||||
auto& child_box_state = m_state.get_mutable(child_box);
|
|
||||||
|
|
||||||
// FIXME: instead of dividing the parent width equally between the columns, should use
|
|
||||||
// the values in the GridTrackSize objects.
|
|
||||||
child_box_state.set_content_width(box_state.content_width() / number_of_columns);
|
|
||||||
child_box_state.set_content_height(grid_row.height);
|
|
||||||
child_box_state.offset = { current_column_count * (box_state.content_width() / number_of_columns), current_y_position };
|
|
||||||
|
|
||||||
current_column_count++;
|
|
||||||
if (current_column_count == number_of_columns) {
|
|
||||||
current_y_position += grid_row.height;
|
|
||||||
current_column_count = 0;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue