mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 13:45:06 +00:00
LibWeb: More work on table layout
Table row layout is now split into two phases: 1. Compute all the column widths (even taking colspan into account!) 2. Place all cells at the correct x,y offsets based on column widths. Both phases visit all rows and all cells.
This commit is contained in:
parent
365703e3f3
commit
62893a54cc
4 changed files with 53 additions and 7 deletions
|
@ -41,12 +41,30 @@ LayoutTableRow::~LayoutTableRow()
|
|||
|
||||
void LayoutTableRow::layout(LayoutMode)
|
||||
{
|
||||
float tallest_cell_height = 0;
|
||||
float content_width = 0;
|
||||
}
|
||||
|
||||
void LayoutTableRow::calculate_column_widths(Vector<float>& column_widths)
|
||||
{
|
||||
size_t column_index = 0;
|
||||
for_each_child_of_type<LayoutTableCell>([&](auto& cell) {
|
||||
cell.layout(LayoutMode::OnlyRequiredLineBreaks);
|
||||
column_widths[column_index] = max(column_widths[column_index], cell.width());
|
||||
column_index += cell.colspan();
|
||||
});
|
||||
}
|
||||
|
||||
void LayoutTableRow::layout_row(const Vector<float>& column_widths)
|
||||
{
|
||||
size_t column_index = 0;
|
||||
float tallest_cell_height = 0;
|
||||
float content_width = 0;
|
||||
|
||||
for_each_child_of_type<LayoutTableCell>([&](auto& cell) {
|
||||
cell.set_offset(effective_offset().translated(content_width, 0));
|
||||
content_width += cell.width();
|
||||
|
||||
size_t cell_colspan = cell.colspan();
|
||||
for (size_t i = 0; i < cell_colspan; ++i)
|
||||
content_width += column_widths[column_index++];
|
||||
tallest_cell_height = max(tallest_cell_height, cell.height());
|
||||
});
|
||||
set_width(content_width);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue