2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/table-view/table-view-impl.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/object/type-registry-helper.h>
26 #include <dali/devel-api/actors/actor-devel.h>
27 #include <dali/devel-api/scripting/scripting.h>
28 #include <dali/public-api/size-negotiation/relayout-container.h>
29 #include <dali/integration-api/debug.h>
36 * @brief Should the tableview fit around the given actor
38 * @param[in] actor The child actor to test against
39 * @param[dimension] The dimension to test against
41 bool FitToChild( Actor actor, Dimension::Type dimension )
43 return actor.GetResizePolicy( dimension ) != ResizePolicy::FILL_TO_PARENT && actor.GetRelayoutSize( dimension ) > 0.0f;
46 #if defined(DEBUG_ENABLED)
47 // debugging support, very useful when new features are added or bugs are hunted down
48 // currently not called from code so compiler will optimize these away, kept here for future debugging
50 #define TABLEVIEW_TAG "DALI Toolkit::TableView "
51 #define TV_LOG(fmt, args,...) Debug::LogMessage(Debug::DebugInfo, TABLEVIEW_TAG fmt, ## args)
52 //#define TABLEVIEW_DEBUG 1
54 #if defined(TABLEVIEW_DEBUG)
55 void PrintArray( Array2d<Dali::Toolkit::Internal::TableView::CellData>& array )
57 TV_LOG( "Array2d<CellData> size [%d,%d] \n", array.GetRows(), array.GetColumns() );
59 for( unsigned int i = 0; i < array.GetRows(); ++i )
61 for( unsigned int j = 0; j < array.GetColumns(); ++j )
63 Dali::Toolkit::Internal::TableView::CellData data = array[i][j];
65 std::string actorName;
69 actorName = data.actor.GetName();
71 TV_LOG("Array[%d,%d]=%c %s %d,%d,%d,%d ", i, j, actor, actorName.c_str(),
72 data.position.rowIndex, data.position.columnIndex,
73 data.position.rowSpan, data.position.columnSpan );
79 // debugging support, very useful when new features are added or bugs are hunted down
80 // currently not called from code so compiler will optimize these away, kept here for future debugging
81 void PrintArray( Array2d<Size>& array )
83 TV_LOG( "Array2d<Size> size [%d,%d] \n", array.GetRows(), array.GetColumns() );
85 for( unsigned int i = 0; i < array.GetRows(); ++i )
87 for( unsigned int j = 0; j < array.GetColumns(); ++j )
89 TV_LOG( "Array[%d,%d]=%.2f,%.2f ", i, j, array[i][j].width, array[i][j].height );
94 // debugging support, very useful when new features are added or bugs are hunted down
95 // currently not called from code so compiler will optimize these away, kept here for future debugging
96 void PrintVector( std::vector<float>& array )
98 TV_LOG( "vector, size [%d]\n", array.size() );
100 for( unsigned int i = 0; i < array.size(); ++i )
102 TV_LOG( "vector[%d]=%.2f ", i, array[i] );
106 #endif // defined(TABLEVIEW_DEBUG)
107 #endif // defined(DEBUG_ENABLED)
126 return Toolkit::TableView::New( 0, 0 );
129 // Setup properties, signals and actions using the type-registry.
130 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TableView, Toolkit::Control, Create );
132 DALI_PROPERTY_REGISTRATION( Toolkit, TableView, "rows", INTEGER, ROWS )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TableView, "columns", INTEGER, COLUMNS )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TableView, "cellPadding", VECTOR2, CELL_PADDING )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TableView, "layoutRows", MAP, LAYOUT_ROWS )
136 DALI_PROPERTY_REGISTRATION( Toolkit, TableView, "layoutColumns", MAP, LAYOUT_COLUMNS )
137 DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "cellIndex", VECTOR2, CELL_INDEX )
138 DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "rowSpan", INTEGER, ROW_SPAN )
139 DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "columnSpan", INTEGER, COLUMN_SPAN )
140 DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "cellHorizontalAlignment", STRING, CELL_HORIZONTAL_ALIGNMENT )
141 DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "cellVerticalAlignment", STRING, CELL_VERTICAL_ALIGNMENT )
143 DALI_TYPE_REGISTRATION_END()
145 const Scripting::StringEnum LAYOUT_POLICY_STRING_TABLE[] =
147 { "fixed", Toolkit::TableView::FIXED },
148 { "relative", Toolkit::TableView::RELATIVE },
149 { "fill", Toolkit::TableView::FILL },
150 { "fit", Toolkit::TableView::FIT }
152 const unsigned int LAYOUT_POLICY_STRING_TABLE_COUNT = sizeof(LAYOUT_POLICY_STRING_TABLE) / sizeof( LAYOUT_POLICY_STRING_TABLE[0] );
154 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
156 {"left", HorizontalAlignment::LEFT},
157 {"center", HorizontalAlignment::CENTER},
158 {"right", HorizontalAlignment::RIGHT}
160 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof(HORIZONTAL_ALIGNMENT_STRING_TABLE) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
162 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
164 {"top", VerticalAlignment::TOP},
165 {"center", VerticalAlignment::CENTER},
166 {"bottom", VerticalAlignment::BOTTOM}
168 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof(VERTICAL_ALIGNMENT_STRING_TABLE) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
170 } // Unnamed namespace
172 Toolkit::TableView TableView::New( unsigned int initialRows, unsigned int initialColumns )
174 // Create the implementation, temporarily owned by this handle on stack
175 IntrusivePtr< TableView > impl = new TableView( initialRows, initialColumns );
177 // Pass ownership to CustomActor handle
178 Toolkit::TableView handle( *impl );
180 // Second-phase init of the implementation
181 // This can only be done after the CustomActor connection has been made...
187 bool TableView::AddChild( Actor& child, const Toolkit::TableView::CellPosition& position )
189 // check that the child is valid
190 DALI_ASSERT_ALWAYS( child );
192 // if child is already parented, we adopt it
195 // check if we need to expand our data array
196 if( position.rowIndex >= mCellData.GetRows() )
198 // only adding new rows
199 ResizeContainers( position.rowIndex + 1, mCellData.GetColumns() );
202 if( position.columnIndex >= mCellData.GetColumns() )
204 // only adding new columns
205 ResizeContainers( mCellData.GetRows(), position.columnIndex + 1 );
208 // check if there already is something in this cell
209 if( mCellData[ position.rowIndex ][ position.columnIndex ].actor )
211 return false; // cannot share a cell, it would complicate all logic and not bring much benefit
214 RelayoutingLock lock( *this );
218 // if child spans multiple rows of columns
219 if( ( position.rowSpan > 1 ) && ( position.rowIndex + position.rowSpan > mCellData.GetRows() ) )
221 // increase table size for the full span, only increasing rows
222 ResizeContainers( position.rowIndex + position.rowSpan, mCellData.GetColumns() );
225 if( ( position.columnSpan > 1 ) && ( position.columnIndex + position.columnSpan > mCellData.GetColumns() ) )
227 // increase table size for the full span, only increasing columns
228 ResizeContainers( mCellData.GetRows(), position.columnIndex + position.columnSpan );
231 // Fill in all cells that need the data
234 data.position = position;
236 for( unsigned int row = position.rowIndex; row < ( position.rowIndex + position.rowSpan ); ++row )
238 // store same information to all cells, this way we can identify
239 // if a cell is the prime location of an actor or a spanned one
240 for( unsigned int column = position.columnIndex; column < ( position.columnIndex + position.columnSpan ); ++column )
242 // store same information to all cells, this way we can identify
243 // if a cell is the prime location of an actor or a spanned one
244 mCellData[ row ][ column ] = data;
248 // Relayout the whole table
249 if( mRowData[position.rowIndex].sizePolicy == Toolkit::TableView::FIT && position.rowSpan == 1 )
253 if( mColumnData[position.columnIndex].sizePolicy == Toolkit::TableView::FIT && position.columnSpan == 1 )
260 return true; // Addition successful
263 Actor TableView::GetChildAt( const Toolkit::TableView::CellPosition& position )
265 if( ( position.rowIndex < mCellData.GetRows() ) && ( position.columnIndex < mCellData.GetColumns() ) )
267 return mCellData[ position.rowIndex ][ position.columnIndex ].actor;
270 // Return an empty handle
274 Actor TableView::RemoveChildAt( const Toolkit::TableView::CellPosition& position )
276 // get the child handle
277 Actor child = GetChildAt( position );
278 // if no real actor there, nothing else to be done
281 RelayoutingLock lock( *this );
282 // Remove the child, this will trigger a call to OnChildRemove
283 Self().Remove( child );
285 // relayout the table only if instances were found
286 if( RemoveAllInstances( child ) )
288 if( mRowData[position.rowIndex].sizePolicy == Toolkit::TableView::FIT )
292 if( mColumnData[position.columnIndex].sizePolicy == Toolkit::TableView::FIT )
299 // return the child back to caller
303 bool TableView::FindChildPosition( const Actor& child, Toolkit::TableView::CellPosition& positionOut )
305 // Only find valid child actors
308 // Walk through the layout data
309 const unsigned int rowCount = mCellData.GetRows();
310 const unsigned int columnCount = mCellData.GetColumns();
312 for( unsigned int row = 0; row < rowCount; ++row )
314 for( unsigned int column = 0; column < columnCount; ++column )
316 if( mCellData[ row ][ column ].actor == child )
318 positionOut = mCellData[ row ][ column ].position;
328 void TableView::InsertRow( unsigned int rowIndex )
330 RelayoutingLock lock( *this );
332 mCellData.InsertRow( rowIndex );
334 // Need to update the cell infos for the items that moved
335 const unsigned int rowCount = mCellData.GetRows();
336 const unsigned int columnCount = mCellData.GetColumns();
338 for( unsigned int row = 0; row < rowCount; ++row )
340 for( unsigned int column = 0; column < columnCount; ++column )
342 Toolkit::TableView::CellPosition& position = mCellData[ row ][ column ].position;
344 // If cell is spanning and above and spans to inserted row
345 if( ( position.rowSpan > 1 ) && ( position.rowIndex <= rowIndex ) &&
346 ( position.rowIndex + position.rowSpan > rowIndex ) )
351 // Copy cell to occupy the new column
352 mCellData[ rowIndex ][ column ] = mCellData[ row ][ column ];
354 else if( row > rowIndex ) // If below of inserted row, increase row index
362 // Expand row data array
363 mRowData.Insert( mRowData.Begin() + rowIndex, RowColumnData() );
365 // Sizes may have changed, so relayout
370 void TableView::DeleteRow( unsigned int rowIndex )
372 std::vector< Actor > ignored;
373 DeleteRow( rowIndex, ignored );
376 void TableView::DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed )
378 RelayoutingLock lock( *this );
381 std::vector< CellData > lost;
382 mCellData.DeleteRow( rowIndex, lost );
384 // Need to update the cell infos for the items that moved
385 const unsigned int rowCount = mCellData.GetRows();
386 const unsigned int columnCount = mCellData.GetColumns();
388 for( unsigned int row = 0; row < rowCount; ++row )
390 for( unsigned int column = 0; column < columnCount; ++column )
392 Toolkit::TableView::CellPosition& position = mCellData[ row ][ column ].position;
394 // If cell is spanning and above and spans to deleted row
395 if( ( position.rowSpan > 1 ) && ( position.rowIndex <= rowIndex ) &&
396 ( position.rowIndex + position.rowSpan > rowIndex ) )
399 if( position.rowSpan > 1 )
404 else if( row >= rowIndex ) // If below of or at the inserted row, decrease row index
407 if( position.rowIndex > 0 )
415 // 1 row removed, 0 columns
416 RemoveAndGetLostActors( lost, removed, 1u, 0u );
418 // Contract row data array
419 mRowData.Erase( mRowData.Begin() + rowIndex );
421 // Sizes may have changed, so relayout
423 // it is possible that the deletion of row leads to remove of child which might further lead to the change of FIT column
429 void TableView::InsertColumn( unsigned int columnIndex )
431 RelayoutingLock lock( *this );
433 // Insert the new column
434 mCellData.InsertColumn( columnIndex );
436 // Need to update the cell infos for the items that moved
437 const unsigned int rowCount = mCellData.GetRows();
438 const unsigned int columnCount = mCellData.GetColumns();
440 for( unsigned int row = 0; row < rowCount; ++row )
442 for( unsigned int column = 0; column < columnCount; ++column )
444 Toolkit::TableView::CellPosition& position = mCellData[ row ][ column ].position;
446 // If cell is spanning and left side and spans to inserted column
447 if( ( position.columnSpan > 1 ) && ( position.columnIndex <= columnIndex ) &&
448 ( position.columnIndex + position.columnSpan > columnIndex ) )
451 position.columnSpan++;
453 // Copy cell to occupy the new column
454 mCellData[ row ][ columnIndex ] = mCellData[ row ][ column ];
456 else if( column > columnIndex ) // If on the right side of inserted column, increase column index
459 position.columnIndex++;
464 // Expand column data array
465 mColumnData.Insert( mColumnData.Begin() + columnIndex, RowColumnData() );
467 // Sizes may have changed so relayout
472 void TableView::DeleteColumn( unsigned int columnIndex )
474 std::vector< Actor > ignored;
475 DeleteColumn( columnIndex, ignored );
478 void TableView::DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed )
480 RelayoutingLock lock( *this );
483 std::vector< CellData > lost;
484 mCellData.DeleteColumn( columnIndex, lost );
486 // Need to update the cell infos for the items that moved
487 const unsigned int rowCount = mCellData.GetRows();
488 const unsigned int columnCount = mCellData.GetColumns();
490 for( unsigned int row = 0; row < rowCount; ++row )
492 for( unsigned int column = 0; column < columnCount; ++column )
494 Toolkit::TableView::CellPosition& position = mCellData[ row ][ column ].position;
496 // If cell is spanning and left side and spans to inserted column
497 if( ( position.columnSpan > 1 ) && ( position.columnIndex <= columnIndex ) &&
498 ( position.columnIndex + position.columnSpan > columnIndex ) )
501 if( position.columnSpan > 1 )
503 position.columnSpan--;
506 else if( column >= columnIndex ) // If on the right side of or at the inserted column, decrease column index
509 if( position.columnIndex > 0 )
511 position.columnIndex--;
517 // 0 rows, 1 column removed
518 RemoveAndGetLostActors( lost, removed, 0u, 1u );
520 // Contract column data array
521 mColumnData.Erase( mColumnData.Begin() + columnIndex );
523 // Size may have changed so relayout
525 // it is possible that the deletion of column leads to remove of child which might further lead to the change of FIT row
531 void TableView::Resize( unsigned int rows, unsigned int columns )
533 std::vector< Actor > ignored;
534 Resize( rows, columns, ignored );
537 void TableView::Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed )
539 RelayoutingLock lock( *this );
541 unsigned int oldRows = GetRows();
542 unsigned int oldColumns = GetColumns();
545 std::vector< CellData > lost;
546 ResizeContainers( rows, columns, lost );
548 // Calculate if we lost rows
549 unsigned int rowsRemoved = 0;
550 unsigned int newRows = GetRows();
552 if( oldRows < newRows )
554 rowsRemoved = newRows - oldRows;
557 // Calculate if we lost columns
558 unsigned int columnsRemoved = 0;
559 unsigned int newColumns = GetColumns();
560 if( oldColumns < newColumns )
562 rowsRemoved = newColumns - oldColumns;
565 RemoveAndGetLostActors( lost, removed, rowsRemoved, columnsRemoved );
567 // Sizes may have changed so request a relayout
573 void TableView::SetCellPadding( Size padding )
575 // If padding really changed
576 if( padding != mPadding )
584 Size TableView::GetCellPadding()
589 void TableView::SetFitHeight( unsigned int rowIndex )
591 DALI_ASSERT_ALWAYS( rowIndex < mRowData.Size() );
593 if( mRowData[ rowIndex ].sizePolicy != Toolkit::TableView::FIT )
595 mRowData[ rowIndex ].sizePolicy = Toolkit::TableView::FIT;
602 bool TableView::IsFitHeight( unsigned int rowIndex ) const
604 DALI_ASSERT_ALWAYS( rowIndex < mRowData.Size() );
606 return mRowData[ rowIndex ].sizePolicy == Toolkit::TableView::FIT;
609 void TableView::SetFitWidth( unsigned int columnIndex )
611 DALI_ASSERT_ALWAYS( columnIndex < mColumnData.Size() );
613 if( mColumnData[ columnIndex ].sizePolicy != Toolkit::TableView::FIT )
615 mColumnData[ columnIndex ].sizePolicy = Toolkit::TableView::FIT;
622 bool TableView::IsFitWidth( unsigned int columnIndex ) const
624 DALI_ASSERT_ALWAYS( columnIndex < mColumnData.Size() );
626 return mColumnData[ columnIndex ].sizePolicy == Toolkit::TableView::FIT;
629 void TableView::SetFixedHeight( unsigned int rowIndex, float height )
631 DALI_ASSERT_ALWAYS( rowIndex < mRowData.Size() );
633 RowColumnData& data = mRowData[ rowIndex ];
635 data.sizePolicy = Toolkit::TableView::FIXED;
641 float TableView::GetFixedHeight( unsigned int rowIndex ) const
643 DALI_ASSERT_ALWAYS( rowIndex < mRowData.Size() );
645 return mRowData[ rowIndex ].size;
648 void TableView::SetFixedWidth( unsigned int columnIndex, float width )
650 DALI_ASSERT_ALWAYS( columnIndex < mColumnData.Size() );
652 RowColumnData& data = mColumnData[ columnIndex ];
654 data.sizePolicy = Toolkit::TableView::FIXED;
660 float TableView::GetFixedWidth( unsigned int columnIndex ) const
662 DALI_ASSERT_ALWAYS( columnIndex < mColumnData.Size() );
664 return mColumnData[ columnIndex ].size;
667 void TableView::SetRelativeHeight( unsigned int rowIndex, float heightPercentage )
669 DALI_ASSERT_ALWAYS( rowIndex < mRowData.Size() );
671 RowColumnData& data = mRowData[ rowIndex ];
672 data.fillRatio = heightPercentage;
673 data.sizePolicy = Toolkit::TableView::RELATIVE;
679 float TableView::GetRelativeHeight( unsigned int rowIndex ) const
681 DALI_ASSERT_ALWAYS( rowIndex < mRowData.Size() );
683 return mRowData[ rowIndex ].fillRatio;
686 void TableView::SetRelativeWidth( unsigned int columnIndex, float widthPercentage )
688 DALI_ASSERT_ALWAYS( columnIndex < mColumnData.Size() );
690 RowColumnData& data = mColumnData[ columnIndex ];
691 data.fillRatio = widthPercentage;
692 data.sizePolicy = Toolkit::TableView::RELATIVE;
698 float TableView::GetRelativeWidth( unsigned int columnIndex ) const
700 DALI_ASSERT_ALWAYS( columnIndex < mColumnData.Size() );
702 return mColumnData[ columnIndex ].fillRatio;
705 void TableView::OnCalculateRelayoutSize( Dimension::Type dimension )
707 if( (dimension & Dimension::WIDTH) && mColumnDirty )
710 * FIXED and FIT have size in pixel
711 * Nothing to do with FIXED, as its value is assigned by user and will not get changed
713 * Need to update the size for FIT column here
715 CalculateFitSizes( mColumnData, Dimension::WIDTH );
717 /* RELATIVE and FILL have size in ratio
718 * Their size in pixel is not available until we get the negotiated size for the whole table
719 * Nothing to do with RELATIVE, as its ratio is assigned by user and will not get changed
721 * Need to update the ratio for FILL column here
723 CalculateFillSizes( mColumnData );
725 mFixedTotals.width = CalculateTotalFixedSize( mColumnData );
728 if( (dimension & Dimension::HEIGHT) && mRowDirty )
730 // refer to the comment above
731 CalculateFitSizes( mRowData, Dimension::HEIGHT );
733 // refer to the comment above
734 CalculateFillSizes( mRowData );
736 mFixedTotals.height = CalculateTotalFixedSize( mRowData );
740 void TableView::OnLayoutNegotiated( float size, Dimension::Type dimension )
742 // Update the column sizes
743 if( (dimension & Dimension::WIDTH) && mColumnDirty )
745 float remainingSize = size - mFixedTotals.width;
746 if( remainingSize < 0.0f )
748 remainingSize = 0.0f;
751 // update every column position in ColumnData array
752 float cumulatedWidth = 0.0f;
753 for( auto&& element : mColumnData )
755 if( element.sizePolicy == Toolkit::TableView::FILL || element.sizePolicy == Toolkit::TableView::RELATIVE )
757 element.size = element.fillRatio * remainingSize;
760 cumulatedWidth += element.size;
761 element.position = cumulatedWidth;
764 mColumnDirty = false;
767 // Update the row sizes
768 if( (dimension & Dimension::HEIGHT) && mRowDirty )
770 float remainingSize = size - mFixedTotals.height;
771 if( remainingSize < 0.0f )
773 remainingSize = 0.0f;
776 // update every row position in RowData array
777 float cumulatedHeight = 0.0f;
778 for( unsigned int row = 0, rowCount = mCellData.GetRows(); row < rowCount; ++row )
780 if( mRowData[ row ].sizePolicy == Toolkit::TableView::FILL || mRowData[ row ].sizePolicy == Toolkit::TableView::RELATIVE)
782 mRowData[ row ].size = mRowData[ row ].fillRatio * remainingSize;
785 cumulatedHeight += mRowData[ row ].size;
786 mRowData[row].position = cumulatedHeight;
793 void TableView::OnSizeSet( const Vector3& size )
795 // If this table view is size negotiated by another actor or control, then the
796 // rows and columns must be recalculated or the new size will not take effect.
797 mRowDirty = mColumnDirty = true;
800 Control::OnSizeSet( size );
803 void TableView::OnRelayout( const Vector2& size, RelayoutContainer& container )
805 // Go through the layout data
806 float totalWidth = 0.0;
808 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>() );
810 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
812 for (auto&& element : mColumnData)
814 totalWidth += element.size;
818 for( unsigned int row = 0, rowCount = mCellData.GetRows(); row < rowCount; ++row )
820 for( unsigned int column = 0, columnCount = mCellData.GetColumns(); column < columnCount; ++column )
822 CellData& cellData= mCellData[ row ][ column ];
823 Actor& actor = cellData.actor;
824 const Toolkit::TableView::CellPosition position = cellData.position;
826 // If there is an actor and this is the main cell of the actor.
827 // An actor can be in multiple cells if its row or column span is more than 1.
828 // We however must lay out each actor only once.
829 if( actor && position.rowIndex == row && position.columnIndex == column )
831 // Anchor actor to top left of the cell
832 if( actor.GetProperty( DevelActor::Property::POSITION_USES_ANCHOR_POINT ).Get< bool >() )
834 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
836 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
839 actor.GetPadding( padding );
841 float left = (column > 0) ? mColumnData[column - 1].position : 0.f;
844 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
846 right = totalWidth - left;
847 left = right - mColumnData[column].size;
851 right = left + mColumnData[column].size;
854 float top = row > 0 ? mRowData[row-1].position : 0.f;
855 float bottom = mRowData[row+position.rowSpan-1].position;
857 if( cellData.horizontalAlignment == HorizontalAlignment::LEFT )
859 actor.SetX( left + mPadding.width + padding.left );
861 else if( cellData.horizontalAlignment == HorizontalAlignment::RIGHT )
863 actor.SetX( right - mPadding.width - padding.right - actor.GetRelayoutSize( Dimension::WIDTH ) );
865 else //if( cellData.horizontalAlignment == HorizontalAlignment::CENTER )
867 actor.SetX( (left + right + padding.left - padding.right - actor.GetRelayoutSize( Dimension::WIDTH )) * 0.5f );
870 if( cellData.verticalAlignment == VerticalAlignment::TOP )
872 actor.SetY( top + mPadding.height + padding.top );
874 else if( cellData.verticalAlignment == VerticalAlignment::BOTTOM )
876 actor.SetY( bottom - mPadding.height - padding.bottom - actor.GetRelayoutSize( Dimension::HEIGHT ) );
878 else //if( cellData.verticalAlignment = VerticalAlignment::CENTER )
880 actor.SetY( (top + bottom + padding.top - padding.bottom - actor.GetRelayoutSize( Dimension::HEIGHT )) * 0.5f );
887 unsigned int TableView::GetRows()
889 return mCellData.GetRows();
892 unsigned int TableView::GetColumns()
894 return mCellData.GetColumns();
897 void TableView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
899 Toolkit::TableView tableView = Toolkit::TableView::DownCast( Dali::BaseHandle( object ) );
903 TableView& tableViewImpl( GetImpl( tableView ) );
906 case Toolkit::TableView::Property::ROWS:
909 if( value.Get( rows ) && rows >= 0 )
911 if( static_cast<unsigned int>(rows) != tableViewImpl.GetRows() )
913 tableViewImpl.Resize( rows, tableViewImpl.GetColumns() );
918 case Toolkit::TableView::Property::COLUMNS:
921 if( value.Get( columns ) && columns >= 0 )
923 if( static_cast<unsigned int>( columns ) != tableViewImpl.GetColumns() )
925 tableViewImpl.Resize( tableViewImpl.GetRows(), value.Get<int>() );
930 case Toolkit::TableView::Property::CELL_PADDING:
932 tableViewImpl.SetCellPadding( value.Get<Vector2>() );
935 case Toolkit::TableView::Property::LAYOUT_ROWS:
937 SetHeightOrWidthProperty( tableViewImpl, &TableView::SetFixedHeight, &TableView::SetRelativeHeight, &TableView::SetFitHeight, value );
940 case Toolkit::TableView::Property::LAYOUT_COLUMNS:
942 SetHeightOrWidthProperty( tableViewImpl, &TableView::SetFixedWidth, &TableView::SetRelativeWidth, &TableView::SetFitWidth, value );
949 Property::Value TableView::GetProperty( BaseObject* object, Property::Index index )
951 Property::Value value;
953 Toolkit::TableView tableView = Toolkit::TableView::DownCast( Dali::BaseHandle( object ) );
957 TableView& tableViewImpl( GetImpl( tableView ) );
960 case Toolkit::TableView::Property::ROWS:
962 value = static_cast<int>( tableViewImpl.GetRows() );
965 case Toolkit::TableView::Property::COLUMNS:
967 value = static_cast<int>( tableViewImpl.GetColumns() );
970 case Toolkit::TableView::Property::CELL_PADDING:
972 value = tableViewImpl.GetCellPadding();
975 case Toolkit::TableView::Property::LAYOUT_ROWS:
977 value = tableViewImpl.GetRowHeightsPropertyValue();
980 case Toolkit::TableView::Property::LAYOUT_COLUMNS:
982 value = tableViewImpl.GetColumnWidthsPropertyValue();
991 void TableView::OnChildAdd( Actor& child )
993 if( ! mLayoutingChild )
995 // Ensure we're not in the middle of laying out children
997 // Check child properties on actor to decide its position inside the table
998 HorizontalAlignment::Type horizontalAlignment = HorizontalAlignment::LEFT;
999 VerticalAlignment::Type verticalAlignment = VerticalAlignment::TOP;
1001 if( child.GetPropertyType( Toolkit::TableView::ChildProperty::CELL_HORIZONTAL_ALIGNMENT ) != Property::NONE )
1003 std::string value = child.GetProperty( Toolkit::TableView::ChildProperty::CELL_HORIZONTAL_ALIGNMENT ).Get<std::string >();
1004 Scripting::GetEnumeration< HorizontalAlignment::Type >( value.c_str(),
1005 HORIZONTAL_ALIGNMENT_STRING_TABLE,
1006 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
1007 horizontalAlignment );
1010 if( child.GetPropertyType( Toolkit::TableView::ChildProperty::CELL_VERTICAL_ALIGNMENT ) != Property::NONE )
1012 std::string value = child.GetProperty( Toolkit::TableView::ChildProperty::CELL_VERTICAL_ALIGNMENT ).Get<std::string >();
1013 Scripting::GetEnumeration< VerticalAlignment::Type >( value.c_str(),
1014 VERTICAL_ALIGNMENT_STRING_TABLE,
1015 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
1016 verticalAlignment );
1019 Toolkit::TableView::CellPosition cellPosition;
1020 if( child.GetPropertyType( Toolkit::TableView::ChildProperty::ROW_SPAN ) != Property::NONE )
1022 cellPosition.rowSpan = child.GetProperty( Toolkit::TableView::ChildProperty::ROW_SPAN ).Get< int >();
1025 if( child.GetPropertyType( Toolkit::TableView::ChildProperty::COLUMN_SPAN ) != Property::NONE )
1027 cellPosition.columnSpan = child.GetProperty( Toolkit::TableView::ChildProperty::COLUMN_SPAN ).Get< int >();
1030 if( child.GetPropertyType( Toolkit::TableView::ChildProperty::CELL_INDEX ) != Property::NONE )
1032 Vector2 indices = child.GetProperty( Toolkit::TableView::ChildProperty::CELL_INDEX ).Get<Vector2 >();
1033 cellPosition.rowIndex = static_cast<unsigned int>( indices.x );
1034 cellPosition.columnIndex = static_cast<unsigned int>( indices.y );
1036 AddChild( child, cellPosition );
1037 SetCellAlignment(cellPosition, horizontalAlignment, verticalAlignment);
1041 bool availableCellFound = false;
1043 // Find the first available cell to store the actor in
1044 const unsigned int rowCount = mCellData.GetRows();
1045 const unsigned int columnCount = mCellData.GetColumns();
1046 for( unsigned int row = 0; row < rowCount && !availableCellFound; ++row )
1048 for( unsigned int column = 0; column < columnCount && !availableCellFound; ++column )
1050 if( !(mCellData[ row ][ column ].actor) )
1052 // Put the actor in the cell
1055 data.position.columnIndex = column;
1056 data.position.rowIndex = row;
1057 data.horizontalAlignment = horizontalAlignment;
1058 data.verticalAlignment = verticalAlignment;
1059 mCellData[ row ][ column ] = data;
1061 availableCellFound = true;
1067 if( ! availableCellFound )
1069 // No empty cells, so increase size of the table
1070 unsigned int newColumnCount = ( columnCount > 0 ) ? columnCount : 1;
1071 ResizeContainers( rowCount + 1, newColumnCount );
1073 // Put the actor in the first cell of the new row
1076 data.position.rowIndex = rowCount;
1077 data.position.columnIndex = 0;
1078 data.horizontalAlignment = horizontalAlignment;
1079 data.verticalAlignment = verticalAlignment;
1080 mCellData[ rowCount ][ 0 ] = data;
1087 Control::OnChildAdd( child );
1090 void TableView::OnChildRemove( Actor& child )
1092 // dont process if we're in the middle of bigger operation like delete row, column or resize
1093 if( !mLayoutingChild )
1095 // relayout the table only if instances were found
1096 if( RemoveAllInstances( child ) )
1102 Control::OnChildRemove( child );
1105 TableView::TableView( unsigned int initialRows, unsigned int initialColumns )
1106 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1107 mCellData( initialRows, initialColumns ),
1108 mPreviousFocusedActor(),
1109 mLayoutingChild( false ),
1110 mRowDirty( true ), // Force recalculation first time
1111 mColumnDirty( true )
1113 SetKeyboardNavigationSupport( true );
1114 ResizeContainers( initialRows, initialColumns );
1117 void TableView::OnInitialize()
1119 // Make self as keyboard focusable and focus group
1120 Actor self = Self();
1121 self.SetKeyboardFocusable(true);
1122 SetAsKeyboardFocusGroup(true);
1125 void TableView::ResizeContainers( unsigned int rows, unsigned int columns )
1127 std::vector<CellData> ignored;
1128 ResizeContainers( rows, columns, ignored );
1131 void TableView::ResizeContainers( unsigned int rows, unsigned int columns, std::vector<CellData>& removed )
1134 mCellData.Resize( rows, columns, removed );
1136 // We don't care if these go smaller, data will be regenerated or is not needed anymore
1137 mRowData.Resize( rows );
1138 mColumnData.Resize( columns );
1141 void TableView::RemoveAndGetLostActors( const std::vector<CellData>& lost, std::vector<Actor>& removed,
1142 unsigned int rowsRemoved, unsigned int columnsRemoved )
1144 // iterate through all lost cells
1145 std::vector< CellData >::const_iterator iter = lost.begin();
1146 for( ; iter != lost.end(); ++iter )
1148 // if it is a valid actor
1151 // is this actor still somewhere else in the table
1152 Toolkit::TableView::CellPosition position;
1153 if( FindChildPosition( (*iter).actor, position ) )
1155 // it must be spanning multiple cells, position contains the top left most one
1156 // check if position is left of the removed location
1157 if( position.columnIndex < (*iter).position.columnIndex )
1159 // if column span is greater than 1
1160 if( mCellData[ position.rowIndex ][ position.columnIndex ].position.columnSpan > 1 )
1162 // decrease column span
1163 mCellData[ position.rowIndex ][ position.columnIndex ].position.columnSpan -= columnsRemoved;
1166 // check if position is left of the removed location
1167 if( position.rowIndex < (*iter).position.rowIndex )
1169 // if row span is greater than 1
1170 if( mCellData[ position.rowIndex ][ position.columnIndex ].position.rowSpan > 1 )
1172 // decrease row span
1173 mCellData[ position.rowIndex ][ position.columnIndex ].position.rowSpan -= rowsRemoved;
1179 // this actor is gone for good
1180 // add actor to removed container
1181 removed.push_back( (*iter).actor );
1182 // we dont want the child actor anymore
1183 Self().Remove( (*iter).actor );
1189 bool TableView::RemoveAllInstances( const Actor& child )
1192 // walk through the layout data
1193 const unsigned int rowCount = mCellData.GetRows();
1194 const unsigned int columnCount = mCellData.GetColumns();
1195 for( unsigned int row = 0; row < rowCount; ++row )
1197 for( unsigned int column = 0; column < columnCount; ++column )
1199 if( mCellData[ row ][ column ].actor == child )
1201 // clear the cell, NOTE that the cell might be spanning multiple cells
1202 mCellData[ row ][ column ] = CellData();
1210 void TableView::SetHeightOrWidthProperty(TableView& tableViewImpl,
1211 void(TableView::*funcFixed)(unsigned int, float),
1212 void(TableView::*funcRelative)(unsigned int, float),
1213 void(TableView::*funcFit)(unsigned int),
1214 const Property::Value& value )
1216 Property::Map* map = value.GetMap();
1219 unsigned int index(0);
1220 for ( unsigned int i = 0, count = map->Count(); i < count; ++i )
1222 Property::Value& item = map->GetValue(i);
1223 Property::Map* childMap = item.GetMap();
1225 std::istringstream( map->GetKey(i) ) >> index;
1228 Property::Value* policy = childMap->Find( "policy" );
1229 Property::Value* childMapValue = childMap->Find( "value" );
1230 if( policy && childMapValue )
1232 std::string policyValue;
1233 policy->Get( policyValue );
1234 Toolkit::TableView::LayoutPolicy policy;
1235 if( Scripting::GetEnumeration< Toolkit::TableView::LayoutPolicy >( policyValue.c_str(),
1236 LAYOUT_POLICY_STRING_TABLE,
1237 LAYOUT_POLICY_STRING_TABLE_COUNT,
1240 if( policy == Toolkit::TableView::FIXED )
1242 (tableViewImpl.*funcFixed)( index, childMapValue->Get<float>() );
1244 else if( policy == Toolkit::TableView::RELATIVE )
1246 (tableViewImpl.*funcRelative)( index, childMapValue->Get<float>() );
1248 else if( policy == Toolkit::TableView::FIT )
1250 (tableViewImpl.*funcFit)( index );
1252 // do nothing for FILL policy
1260 Property::Value TableView::GetRowHeightsPropertyValue()
1263 GetMapPropertyValue( mRowData, map);
1264 return Property::Value(map);
1267 Property::Value TableView::GetColumnWidthsPropertyValue()
1270 GetMapPropertyValue( mColumnData, map);
1271 return Property::Value(map);
1274 void TableView::GetMapPropertyValue( const RowColumnArray& data, Property::Map& map )
1276 const char* fixedPolicy = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::FIXED,
1277 LAYOUT_POLICY_STRING_TABLE,
1278 LAYOUT_POLICY_STRING_TABLE_COUNT );
1279 const char* relativePolicy = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::RELATIVE,
1280 LAYOUT_POLICY_STRING_TABLE,
1281 LAYOUT_POLICY_STRING_TABLE_COUNT );
1282 const char* fillPolicy = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::FILL,
1283 LAYOUT_POLICY_STRING_TABLE,
1284 LAYOUT_POLICY_STRING_TABLE_COUNT );
1285 const char* fitPolicy = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::FIT,
1286 LAYOUT_POLICY_STRING_TABLE,
1287 LAYOUT_POLICY_STRING_TABLE_COUNT );
1289 const RowColumnArray::SizeType count = data.Size();
1290 for( RowColumnArray::SizeType i = 0; i < count; i++ )
1292 const RowColumnData& dataInstance = data[ i ];
1295 switch( dataInstance.sizePolicy )
1297 case Toolkit::TableView::FIXED:
1299 item[ "policy" ] = fixedPolicy;
1300 item[ "value" ] = dataInstance.size;
1303 case Toolkit::TableView::RELATIVE:
1305 item[ "policy" ] = relativePolicy;
1306 item[ "value" ] = dataInstance.fillRatio;
1309 case Toolkit::TableView::FIT:
1311 item[ "policy" ] = fitPolicy;
1312 item[ "value" ] = 0.f;
1315 case Toolkit::TableView::FILL:
1318 item[ "policy" ] = fillPolicy;
1319 item[ "value" ] = 0.f;
1323 std::ostringstream ss;
1325 map[ ss.str() ] = item;
1329 TableView::~TableView()
1334 Actor TableView::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled)
1336 Actor nextFocusableActor;
1338 if ( !currentFocusedActor )
1340 // Nothing is currently focused, so the child in the first cell should be focused.
1341 nextFocusableActor = GetChildAt(Toolkit::TableView::CellPosition(0, 0));
1345 Toolkit::TableView::CellPosition position;
1346 if( FindChildPosition( currentFocusedActor, position ) )
1348 // The current focused actor is a child of TableView
1349 bool focusLost = false;
1350 int currentRow = position.rowIndex;
1351 int currentColumn = position.columnIndex;
1352 int numberOfColumns = GetColumns();
1353 int numberOfRows = GetRows();
1355 bool lastCell = false;
1356 Actor nextValidActor;
1358 switch ( direction )
1360 case Toolkit::Control::KeyboardFocus::LEFT:
1364 if(--currentColumn < 0)
1366 currentColumn = numberOfColumns - 1;
1367 if(--currentRow < 0)
1370 currentRow = loopEnabled ? numberOfRows - 1 : 0;
1371 focusLost = (currentRow == 0);
1374 nextValidActor = GetChildAt(Toolkit::TableView::CellPosition(currentRow, currentColumn));
1375 } while ( !nextValidActor && !lastCell );
1378 case Toolkit::Control::KeyboardFocus::RIGHT:
1382 if(++currentColumn > numberOfColumns - 1)
1385 if(++currentRow > numberOfRows - 1)
1388 currentRow = loopEnabled ? 0 : numberOfRows - 1;
1389 focusLost = (currentRow == numberOfRows - 1);
1392 nextValidActor = GetChildAt(Toolkit::TableView::CellPosition(currentRow, currentColumn));
1393 } while ( !nextValidActor && !lastCell );
1396 case Toolkit::Control::KeyboardFocus::UP:
1400 if(--currentRow < 0)
1403 currentRow = loopEnabled ? numberOfRows - 1 : 0;
1404 focusLost = (currentRow == 0);
1406 nextValidActor = GetChildAt(Toolkit::TableView::CellPosition(currentRow, currentColumn));
1407 } while ( !nextValidActor && !lastCell );
1410 case Toolkit::Control::KeyboardFocus::DOWN:
1415 if(++currentRow > numberOfRows - 1)
1418 currentRow = loopEnabled ? 0 : numberOfRows - 1;
1419 focusLost = (currentRow == numberOfRows - 1);
1421 nextValidActor = GetChildAt(Toolkit::TableView::CellPosition(currentRow, currentColumn));
1422 } while ( !nextValidActor && !lastCell );
1431 // Move the focus if we haven't lost it.
1434 nextFocusableActor = GetChildAt(Toolkit::TableView::CellPosition(currentRow, currentColumn));
1436 // Save the focused actor in the TableView.
1437 mPreviousFocusedActor = nextFocusableActor;
1442 // The current focused actor is not within this TableView.
1444 unsigned int numberOfColumns = GetColumns();
1445 unsigned int numberOfRows = GetRows();
1447 // Check whether the previous focused actor is a focus group (i.e. a layout container)
1448 bool wasFocusedOnLayoutContainer = false;
1449 Actor previousFocusedActor = mPreviousFocusedActor.GetHandle();
1450 if( previousFocusedActor )
1452 Toolkit::Control control = Toolkit::Control::DownCast( previousFocusedActor );
1455 Internal::Control& controlImpl = static_cast<Internal::Control&>(control.GetImplementation());
1456 wasFocusedOnLayoutContainer = controlImpl.IsKeyboardFocusGroup();
1460 // Check whether the previous focused actor is a layout container and also a child of this TableView
1461 Toolkit::TableView::CellPosition position;
1462 if( wasFocusedOnLayoutContainer && FindChildPosition( previousFocusedActor, position ) )
1464 nextFocusableActor = GetNextKeyboardFocusableActor(previousFocusedActor, direction, loopEnabled);
1468 // Otherwise, move the focus to either the first or the last cell according to the given direction.
1469 if(direction == Toolkit::Control::KeyboardFocus::LEFT || direction == Toolkit::Control::KeyboardFocus::UP)
1471 nextFocusableActor = GetChildAt(Toolkit::TableView::CellPosition(numberOfRows - 1, numberOfColumns - 1));
1475 nextFocusableActor = GetChildAt(Toolkit::TableView::CellPosition(0, 0));
1481 return nextFocusableActor;
1484 Vector3 TableView::GetNaturalSize()
1486 // Natural size is the size of all fixed cell widths or heights. This ignores cells with relative heights.
1487 return Vector3( mFixedTotals.width, mFixedTotals.height, 1.0f );
1490 float TableView::CalculateChildSize( const Actor& child, Dimension::Type dimension )
1492 Toolkit::TableView::CellPosition position;
1493 if( FindChildPosition( child, position) )
1497 case Dimension::WIDTH:
1499 float cellSize = 0.0f;
1500 cellSize = mColumnData[position.columnIndex+position.columnSpan-1].position
1501 - (position.columnIndex > 0 ? mColumnData[position.columnIndex-1].position : 0.f)
1502 - mPadding.width * 2.0f;
1504 if( cellSize < 0.0f )
1512 case Dimension::HEIGHT:
1514 float cellSize = 0.0f;
1516 cellSize = mRowData[position.rowIndex+position.rowSpan-1].position
1517 - (position.rowIndex > 0 ? mRowData[position.rowIndex-1].position : 0.f)
1518 - mPadding.height * 2.0f;
1520 if( cellSize < 0.0f )
1534 return 0.0f; // Child not found
1537 bool TableView::RelayoutDependentOnChildren( Dimension::Type dimension )
1539 if ( Control::RelayoutDependentOnChildren( dimension ) )
1544 return FindFit( mRowData ) || FindFit( mColumnData );
1547 void TableView::SetCellAlignment( Toolkit::TableView::CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical )
1549 // Check if we need to expand our data array
1550 if( position.rowIndex >= mCellData.GetRows() )
1552 // Only adding new rows
1553 ResizeContainers( position.rowIndex + 1, mCellData.GetColumns() );
1556 if( position.columnIndex >= mCellData.GetColumns() )
1558 // Only adding new columns
1559 ResizeContainers( mCellData.GetRows(), position.columnIndex + 1 );
1562 // Set the alignment of the cell
1563 CellData& data = mCellData[ position.rowIndex ][ position.columnIndex ];
1564 data.horizontalAlignment = horizontal;
1565 data.verticalAlignment = vertical;
1568 void TableView::CalculateFillSizes( RowColumnArray& data )
1570 // First pass: Count number of fill entries and calculate used relative space
1571 Dali::Vector< RowColumnData* > fillData;
1572 float relativeTotal = 0.0f;
1574 const unsigned int dataCount = data.Size();
1576 for( unsigned int i = 0; i < dataCount; ++i )
1578 RowColumnData& dataInstance = data[ i ];
1580 if( dataInstance.sizePolicy == Toolkit::TableView::RELATIVE )
1582 relativeTotal += dataInstance.fillRatio;
1584 else if(dataInstance.sizePolicy == Toolkit::TableView::FILL)
1586 fillData.PushBack( &dataInstance );
1590 // Second pass: Distribute remaining relative space
1591 const unsigned int fillCount = fillData.Size();
1594 if( relativeTotal > 1.0f )
1596 relativeTotal = 1.0f;
1599 const float evenFillRatio = (1.0f - relativeTotal ) / fillCount;
1601 for( unsigned int i = 0; i < fillCount; ++i )
1603 fillData[ i ]->fillRatio = evenFillRatio;
1608 float TableView::CalculateTotalFixedSize( const RowColumnArray& data )
1610 float totalSize = 0.0f;
1612 const unsigned int dataCount = data.Size();
1614 for( unsigned int i = 0; i < dataCount; ++i )
1616 const RowColumnData& dataInstance = data[ i ];
1618 switch( dataInstance.sizePolicy )
1620 // we have absolute size to FIXED and FIT column/row and relative size for RELATIVE and FILL column/row
1621 case Toolkit::TableView::FIXED:
1622 case Toolkit::TableView::FIT:
1624 totalSize += dataInstance.size;
1638 Vector2 TableView::GetCellPadding( Dimension::Type dimension )
1642 case Dimension::WIDTH:
1644 return Vector2( mPadding.x, mPadding.x );
1646 case Dimension::HEIGHT:
1648 return Vector2( mPadding.y, mPadding.y );
1659 void TableView::CalculateFitSizes( RowColumnArray& data, Dimension::Type dimension )
1661 Vector2 cellPadding = GetCellPadding( dimension );
1663 const unsigned int dataCount = data.Size();
1665 for( unsigned int i = 0; i < dataCount; ++i )
1667 RowColumnData& dataInstance = data[ i ];
1669 if( dataInstance.sizePolicy == Toolkit::TableView::FIT )
1671 // Find the size of the biggest actor in the row or column
1672 float maxActorHeight = 0.0f;
1674 unsigned int fitCount = ( dimension == Dimension::WIDTH ) ? mCellData.GetRows() : mCellData.GetColumns();
1676 for( unsigned int j = 0; j < fitCount; ++j )
1678 unsigned int row = ( dimension == Dimension::WIDTH ) ? j : i;
1679 unsigned int column = ( dimension == Dimension::WIDTH ) ? i : j;
1680 DALI_ASSERT_DEBUG( row < mCellData.GetRows() );
1681 DALI_ASSERT_DEBUG( column < mCellData.GetColumns() );
1683 const CellData& cellData = mCellData[ row ][ column ];
1684 const Actor& actor = cellData.actor;
1687 if( FitToChild( actor, dimension ) && ( dimension == Dimension::WIDTH ) ? ( cellData.position.columnSpan == 1 ) : ( cellData.position.rowSpan == 1 ) )
1689 maxActorHeight = std::max( maxActorHeight, actor.GetRelayoutSize( dimension ) + cellPadding.x + cellPadding.y );
1694 dataInstance.size = maxActorHeight;
1699 bool TableView::FindFit( const RowColumnArray& data )
1701 for( unsigned int i = 0, count = data.Size(); i < count; ++i )
1703 if( data[ i ].sizePolicy == Toolkit::TableView::FIT )
1712 } // namespace Internal
1714 } // namespace Toolkit