+Vector3 TableView::GetNaturalSize()
+{
+ // Natural size is the size of all fixed cell widths or heights. This ignores cells with relative heights.
+ return Vector3(mFixedTotals.width, mFixedTotals.height, 1.0f);
+}
+
+float TableView::CalculateChildSize(const Actor& child, Dimension::Type dimension)
+{
+ Toolkit::TableView::CellPosition position;
+ if(FindChildPosition(child, position))
+ {
+ switch(dimension)
+ {
+ case Dimension::WIDTH:
+ {
+ float cellSize = 0.0f;
+ cellSize = mColumnData[position.columnIndex + position.columnSpan - 1].position - (position.columnIndex > 0 ? mColumnData[position.columnIndex - 1].position : 0.f) - mPadding.width * 2.0f;
+
+ if(cellSize < 0.0f)
+ {
+ cellSize = 0.0f;
+ }
+
+ return cellSize;
+ }
+
+ case Dimension::HEIGHT:
+ {
+ float cellSize = 0.0f;
+
+ cellSize = mRowData[position.rowIndex + position.rowSpan - 1].position - (position.rowIndex > 0 ? mRowData[position.rowIndex - 1].position : 0.f) - mPadding.height * 2.0f;
+
+ if(cellSize < 0.0f)
+ {
+ cellSize = 0.0f;
+ }
+
+ return cellSize;
+ }
+ default:
+ {
+ return 0.0f;
+ }
+ }
+ }
+
+ return 0.0f; // Child not found
+}
+
+bool TableView::RelayoutDependentOnChildren(Dimension::Type dimension)
+{
+ if(Control::RelayoutDependentOnChildren(dimension))
+ {
+ return true;
+ }
+
+ return FindFit(mRowData) || FindFit(mColumnData);
+}
+
+void TableView::SetCellAlignment(Toolkit::TableView::CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical)
+{
+ // Check if we need to expand our data array
+ if(position.rowIndex >= mCellData.GetRows())
+ {
+ // Only adding new rows
+ ResizeContainers(position.rowIndex + 1, mCellData.GetColumns());
+ }
+
+ if(position.columnIndex >= mCellData.GetColumns())
+ {
+ // Only adding new columns
+ ResizeContainers(mCellData.GetRows(), position.columnIndex + 1);
+ }
+
+ // Set the alignment of the cell
+ CellData& data = mCellData[position.rowIndex][position.columnIndex];
+ data.horizontalAlignment = horizontal;
+ data.verticalAlignment = vertical;
+}
+
+void TableView::CalculateFillSizes(RowColumnArray& data)
+{
+ // First pass: Count number of fill entries and calculate used relative space
+ Dali::Vector<RowColumnData*> fillData;
+ float relativeTotal = 0.0f;
+
+ const unsigned int dataCount = data.Size();
+
+ for(unsigned int i = 0; i < dataCount; ++i)
+ {
+ RowColumnData& dataInstance = data[i];
+
+ if(dataInstance.sizePolicy == Toolkit::TableView::RELATIVE)
+ {
+ relativeTotal += dataInstance.fillRatio;
+ }
+ else if(dataInstance.sizePolicy == Toolkit::TableView::FILL)
+ {
+ fillData.PushBack(&dataInstance);
+ }
+ }
+
+ // Second pass: Distribute remaining relative space
+ const unsigned int fillCount = fillData.Size();
+ if(fillCount > 0)
+ {
+ if(relativeTotal > 1.0f)
+ {
+ relativeTotal = 1.0f;
+ }
+
+ const float evenFillRatio = (1.0f - relativeTotal) / fillCount;
+
+ for(unsigned int i = 0; i < fillCount; ++i)
+ {
+ fillData[i]->fillRatio = evenFillRatio;
+ }
+ }
+}
+
+float TableView::CalculateTotalFixedSize(const RowColumnArray& data)
+{
+ float totalSize = 0.0f;
+
+ const unsigned int dataCount = data.Size();
+
+ for(unsigned int i = 0; i < dataCount; ++i)
+ {
+ const RowColumnData& dataInstance = data[i];
+
+ switch(dataInstance.sizePolicy)
+ {
+ // we have absolute size to FIXED and FIT column/row and relative size for RELATIVE and FILL column/row
+ case Toolkit::TableView::FIXED:
+ case Toolkit::TableView::FIT:
+ {
+ totalSize += dataInstance.size;
+ break;
+ }
+
+ default:
+ {
+ break;
+ }
+ }
+ }
+
+ return totalSize;
+}
+
+Vector2 TableView::GetCellPadding(Dimension::Type dimension)
+{
+ switch(dimension)
+ {
+ case Dimension::WIDTH:
+ {
+ return Vector2(mPadding.x, mPadding.x);
+ }
+ case Dimension::HEIGHT:
+ {
+ return Vector2(mPadding.y, mPadding.y);
+ }
+ default:
+ {
+ break;
+ }
+ }
+
+ return Vector2();
+}
+
+void TableView::CalculateFitSizes(RowColumnArray& data, Dimension::Type dimension)
+{
+ Vector2 cellPadding = GetCellPadding(dimension);
+
+ const unsigned int dataCount = data.Size();
+
+ for(unsigned int i = 0; i < dataCount; ++i)
+ {
+ RowColumnData& dataInstance = data[i];
+
+ if(dataInstance.sizePolicy == Toolkit::TableView::FIT)
+ {
+ // Find the size of the biggest actor in the row or column
+ float maxActorHeight = 0.0f;
+
+ unsigned int fitCount = (dimension == Dimension::WIDTH) ? mCellData.GetRows() : mCellData.GetColumns();
+
+ for(unsigned int j = 0; j < fitCount; ++j)
+ {
+ unsigned int row = (dimension == Dimension::WIDTH) ? j : i;
+ unsigned int column = (dimension == Dimension::WIDTH) ? i : j;
+ DALI_ASSERT_DEBUG(row < mCellData.GetRows());
+ DALI_ASSERT_DEBUG(column < mCellData.GetColumns());
+
+ const CellData& cellData = mCellData[row][column];
+ const Actor& actor = cellData.actor;
+ if(actor)
+ {
+ if(FitToChild(actor, dimension) && (dimension == Dimension::WIDTH) ? (cellData.position.columnSpan == 1) : (cellData.position.rowSpan == 1))
+ {
+ maxActorHeight = std::max(maxActorHeight, actor.GetRelayoutSize(dimension) + cellPadding.x + cellPadding.y);
+ }
+ }
+ }
+
+ dataInstance.size = maxActorHeight;
+ }
+ }
+}
+
+bool TableView::FindFit(const RowColumnArray& data)
+{
+ for(unsigned int i = 0, count = data.Size(); i < count; ++i)
+ {
+ if(data[i].sizePolicy == Toolkit::TableView::FIT)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+