| 72 | } |
| 73 | |
| 74 | void Table::UpdateRequisitions() { |
| 75 | // Reset requisitions and expand flags, at first. |
| 76 | for( auto& column : m_columns ) { |
| 77 | column.requisition = 0.f; |
| 78 | column.allocation = 0.f; |
| 79 | column.expand = false; |
| 80 | } |
| 81 | |
| 82 | for( auto& row : m_rows ) { |
| 83 | row.requisition = 0.f; |
| 84 | row.allocation = 0.f; |
| 85 | row.expand = false; |
| 86 | } |
| 87 | |
| 88 | // Iterate over children and add requisitions to columns and rows. |
| 89 | for( const auto& cell : m_cells ) { |
| 90 | auto col_requisition = cell.child->GetRequisition().x / static_cast<float>( cell.rect.size.x ) + 2 * cell.padding.x; |
| 91 | auto col_bound = cell.rect.position.x + cell.rect.size.x; |
| 92 | |
| 93 | for( std::uint32_t col_idx = cell.rect.position.x; col_idx < col_bound; ++col_idx ) { |
| 94 | m_columns[col_idx].requisition = std::max( |
| 95 | m_columns[col_idx].requisition, |
| 96 | col_requisition + (col_idx + 1 < m_columns.size() ? m_columns[col_idx].spacing : 0) // Add spacing if not last column. |
| 97 | ); |
| 98 | |
| 99 | // Set expand flag. |
| 100 | if( (cell.x_options & EXPAND) == EXPAND ) { |
| 101 | m_columns[col_idx].expand = true; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | auto row_requisition = cell.child->GetRequisition().y / static_cast<float>( cell.rect.size.y ) + 2 * cell.padding.y; |
| 106 | auto row_bound = cell.rect.position.y + cell.rect.size.y; |
| 107 | |
| 108 | for( std::uint32_t row_idx = cell.rect.position.y; row_idx < row_bound; ++row_idx ) { |
| 109 | m_rows[row_idx].requisition = std::max( |
| 110 | m_rows[row_idx].requisition, |
| 111 | row_requisition + (row_idx + 1 < m_rows.size() ? m_rows[row_idx].spacing : 0) // Add spacing if not last row. |
| 112 | ); |
| 113 | |
| 114 | // Set expand flag. |
| 115 | if( (cell.y_options & EXPAND) == EXPAND ) { |
| 116 | m_rows[row_idx].expand = true; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | AllocateChildren(); |
| 122 | } |
| 123 | |
| 124 | void Table::AllocateChildren() { |
| 125 | auto gap = Context::Get().GetEngine().GetProperty<float>( |