From d7638de1a66bed4868e8a9fb2f4d3c03f4ce27f8 Mon Sep 17 00:00:00 2001 From: Xiangyin Ma Date: Mon, 22 Jun 2015 18:38:31 +0100 Subject: [PATCH] TableView: Enum cleanup and Complete the SetCellAlignment() func Change-Id: Id93a391c9600db277eb62f77e567bdfaddb87757 --- .../src/dali-toolkit/utc-Dali-TableView.cpp | 29 +- dali-toolkit/internal/builder/builder-actor.cpp | 2 +- .../controls/table-view/table-view-impl.cpp | 305 +++++++++++++-------- .../internal/controls/table-view/table-view-impl.h | 66 ++--- .../public-api/controls/table-view/table-view.cpp | 12 +- .../public-api/controls/table-view/table-view.h | 54 +++- 6 files changed, 292 insertions(+), 176 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp index 6254e7a..9c1e054 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp @@ -693,13 +693,14 @@ int UtcDaliTableViewCustomProperties(void) // Create a 10x10 table-view TableView tableView = TableView::New(10,10); - Constraint constraint = Constraint::New( tableView, Actor::Property::SIZE, Constraint100() ); - constraint.Apply(); + Stage::GetCurrent().Add( tableView ); + tableView.SetSize( Dali::Vector2( 100.0f, 100.0f ) ); + DALI_TEST_CHECK( tableView ); // Create a child actor with the custom properties Actor child1 = Actor::New(); - child1.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 3, 4 ) ); + child1.RegisterProperty( "cell-index", Vector2( 3, 4 ), Property::READ_WRITE ); tableView.Add( child1 ); // Check for actors at actual positions. DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(3,4)) == child1); @@ -708,9 +709,9 @@ int UtcDaliTableViewCustomProperties(void) Actor child2 = Actor::New(); float rowSpan = 3.f; float columnSpan = 2.f; - child2.RegisterProperty( TableView::CELL_INDICES_PROPERTY_NAME, Vector2( 6, 1 ) ); - child2.RegisterProperty( TableView::ROW_SPAN_PROPERTY_NAME, rowSpan ); - child2.RegisterProperty( TableView::COLUMN_SPAN_PROPERTY_NAME, columnSpan ); + child2.RegisterProperty( "cell-index", Vector2( 6, 1 ), Property::READ_WRITE ); + child2.RegisterProperty( "row-span", rowSpan, Property::READ_WRITE ); + child2.RegisterProperty( "column-span", columnSpan, Property::READ_WRITE ); tableView.Add( child2 ); // Check for actors at actual positions. for( int i=0; i= mCellData.GetRows() ) @@ -544,44 +570,44 @@ Size TableView::GetCellPadding() return mPadding; } -void TableView::SetRowPolicy( unsigned int rowIndex, CellSizePolicy policy ) +void TableView::SetFitHeight( unsigned int rowIndex ) { DALI_ASSERT_ALWAYS( rowIndex < mRowData.Size() ); - if( mRowData[ rowIndex ].sizePolicy != policy ) + if( mRowData[ rowIndex ].sizePolicy != Toolkit::TableView::FIT ) { - mRowData[ rowIndex ].sizePolicy = policy; + mRowData[ rowIndex ].sizePolicy = Toolkit::TableView::FIT; mRowColumnDirty = true; RelayoutRequest(); } } -TableView::CellSizePolicy TableView::GetRowPolicy( unsigned int rowIndex ) const +bool TableView::IsFitHeight( unsigned int rowIndex ) const { DALI_ASSERT_ALWAYS( rowIndex < mRowData.Size() ); - return mRowData[ rowIndex ].sizePolicy; + return mRowData[ rowIndex ].sizePolicy == Toolkit::TableView::FIT; } -void TableView::SetColumnPolicy( unsigned int columnIndex, CellSizePolicy policy ) +void TableView::SetFitWidth( unsigned int columnIndex ) { DALI_ASSERT_ALWAYS( columnIndex < mColumnData.Size() ); - if( mColumnData[ columnIndex ].sizePolicy != policy ) + if( mColumnData[ columnIndex ].sizePolicy != Toolkit::TableView::FIT ) { - mColumnData[ columnIndex ].sizePolicy = policy; + mColumnData[ columnIndex ].sizePolicy = Toolkit::TableView::FIT; mRowColumnDirty = true; RelayoutRequest(); } } -TableView::CellSizePolicy TableView::GetColumnPolicy( unsigned int columnIndex ) const +bool TableView::IsFitWidth( unsigned int columnIndex ) const { DALI_ASSERT_ALWAYS( columnIndex < mColumnData.Size() ); - return mColumnData[ columnIndex ].sizePolicy; + return mColumnData[ columnIndex ].sizePolicy == Toolkit::TableView::FIT; } void TableView::SetFixedHeight( unsigned int rowIndex, float height ) @@ -590,7 +616,7 @@ void TableView::SetFixedHeight( unsigned int rowIndex, float height ) RowColumnData& data = mRowData[ rowIndex ]; data.size = height; - data.sizePolicy = FIXED; + data.sizePolicy = Toolkit::TableView::FIXED; mRowColumnDirty = true; RelayoutRequest(); @@ -609,7 +635,7 @@ void TableView::SetFixedWidth( unsigned int columnIndex, float width ) RowColumnData& data = mColumnData[ columnIndex ]; data.size = width; - data.sizePolicy = FIXED; + data.sizePolicy = Toolkit::TableView::FIXED; mRowColumnDirty = true; RelayoutRequest(); @@ -628,8 +654,7 @@ void TableView::SetRelativeHeight( unsigned int rowIndex, float heightPercentage RowColumnData& data = mRowData[ rowIndex ]; data.fillRatio = heightPercentage; - data.userFillRatio = true; - data.sizePolicy = FILL; + data.sizePolicy = Toolkit::TableView::RELATIVE; mRowColumnDirty = true; RelayoutRequest(); @@ -648,8 +673,7 @@ void TableView::SetRelativeWidth( unsigned int columnIndex, float widthPercentag RowColumnData& data = mColumnData[ columnIndex ]; data.fillRatio = widthPercentage; - data.userFillRatio = true; - data.sizePolicy = FILL; + data.sizePolicy = Toolkit::TableView::RELATIVE; mRowColumnDirty = true; RelayoutRequest(); @@ -723,45 +747,89 @@ void TableView::OnRelayout( const Vector2& size, RelayoutContainer& container ) { CalculateRowColumnData(); - // Go through the layout data - float cumulatedHeight = 0.0f; - - const unsigned int rowCount = mCellData.GetRows(); + // update every column position in ColumnData array + float cumulatedWidth = 0.0f; const unsigned int columnCount = mCellData.GetColumns(); + for( unsigned int column = 0; column < columnCount; ++column ) + { + mColumnData[column].position = cumulatedWidth; + cumulatedWidth += mColumnData[ column ].size; + } + // update every row position in RowData array + float cumulatedHeight = 0.0f; + const unsigned int rowCount = mCellData.GetRows(); for( unsigned int row = 0; row < rowCount; ++row ) { - float cumulatedWidth = 0.0f; + mRowData[row].position = cumulatedHeight; + cumulatedHeight += mRowData[ row ].size; + } + // Go through the layout data + for( unsigned int row = 0; row < rowCount; ++row ) + { for( unsigned int column = 0; column < columnCount; ++column ) { - Actor& actor = mCellData[ row ][ column ].actor; - const Toolkit::TableView::CellPosition position = mCellData[ row ][ column ].position; + CellData& cellData= mCellData[ row ][ column ]; + Actor& actor = cellData.actor; + const Toolkit::TableView::CellPosition position = cellData.position; // If there is an actor and this is the main cell of the actor. - // An actor can be in multiple cells if its row or columnspan is more than 1. + // An actor can be in multiple cells if its row or column span is more than 1. // We however must lay out each actor only once. - if( actor && ( position.rowIndex == row ) && ( position.columnIndex == column ) ) + if( actor && position.rowIndex == row && position.columnIndex == column ) { - // Anchor actor to top left of table view + // Anchor actor to top left of the cell actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); actor.SetParentOrigin( ParentOrigin::TOP_LEFT ); + Vector2( actor.GetRelayoutSize( Dimension::WIDTH ), actor.GetRelayoutSize( Dimension::HEIGHT ) ); + Padding padding; actor.GetPadding( padding ); - Vector3 actorPosition( cumulatedWidth + mPadding.width + padding.left, // Left padding - cumulatedHeight + mPadding.height + padding.top, // Top padding - 0.0f ); - actor.SetPosition( actorPosition ); - } + if( cellData.horizontalAlignment == HorizontalAlignment::LEFT ) + { + actor.SetX( mColumnData[column].position + mPadding.width + padding.left ); + } + else + { + float cellRightPosition = column+position.columnSpan < columnCount ? mColumnData[column+position.columnSpan].position : cumulatedWidth; - DALI_ASSERT_DEBUG( column < mColumnData.Size() ); - cumulatedWidth += mColumnData[ column ].size; - } + if( cellData.horizontalAlignment == HorizontalAlignment::RIGHT ) + { + actor.SetX( cellRightPosition - mPadding.width - padding.right - actor.GetRelayoutSize( Dimension::WIDTH ) ); + } + else //if( cellData.horizontalAlignment == HorizontalAlignment::CENTER ) + { + actor.SetX( (mColumnData[column].position + cellRightPosition + + padding.left - padding.right + - actor.GetRelayoutSize( Dimension::WIDTH )) * 0.5f ); + } + } - DALI_ASSERT_DEBUG( row < mRowData.Size() ); - cumulatedHeight += mRowData[ row ].size; + if( cellData.verticalAlignment == VerticalAlignment::TOP ) + { + actor.SetY( mRowData[row].position + mPadding.height + padding.top ); + } + else + { + float cellBottomPosition = row+position.rowSpan < rowCount ? mRowData[row+position.rowSpan].position : cumulatedHeight; + + if( cellData.verticalAlignment == VerticalAlignment::BOTTOM ) + + { + actor.SetY( cellBottomPosition - mPadding.height - padding.bottom - actor.GetRelayoutSize( Dimension::HEIGHT ) ); + } + else //if( cellData.verticalAlignment = VerticalAlignment::CENTER ) + { + actor.SetY( (mRowData[row].position + cellBottomPosition + + padding.top - padding.bottom + - actor.GetRelayoutSize( Dimension::HEIGHT )) * 0.5f ); + } + } + } + } } } @@ -807,12 +875,12 @@ void TableView::SetProperty( BaseObject* object, Property::Index index, const Pr } case Toolkit::TableView::Property::LAYOUT_ROWS: { - SetHeightOrWidthProperty( tableViewImpl, &TableView::SetFixedHeight, &TableView::SetRelativeHeight, value ); + SetHeightOrWidthProperty( tableViewImpl, &TableView::SetFixedHeight, &TableView::SetRelativeHeight, &TableView::SetFitHeight, value ); break; } case Toolkit::TableView::Property::LAYOUT_COLUMNS: { - SetHeightOrWidthProperty( tableViewImpl, &TableView::SetFixedWidth, &TableView::SetRelativeWidth, value ); + SetHeightOrWidthProperty( tableViewImpl, &TableView::SetFixedWidth, &TableView::SetRelativeWidth, &TableView::SetFitWidth, value ); break; } } @@ -869,29 +937,49 @@ void TableView::OnControlChildAdd( Actor& child ) return; } - RelayoutRequest(); - // Test properties on actor + HorizontalAlignment::Type horizontalAlignment = HorizontalAlignment::LEFT; + VerticalAlignment::Type verticalAlignment = VerticalAlignment::TOP; + if( child.GetPropertyIndex( CELL_HORIZONTAL_ALIGNMENT_PROPERTY_NAME ) != Property::INVALID_INDEX ) + { + std::string value = child.GetProperty( child.GetPropertyIndex(CELL_HORIZONTAL_ALIGNMENT_PROPERTY_NAME) ).Get(); + Scripting::GetEnumeration< HorizontalAlignment::Type >( value.c_str(), + HORIZONTAL_ALIGNMENT_STRING_TABLE, + HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT, + horizontalAlignment ); + } + if( child.GetPropertyIndex( CELL_VERTICAL_ALIGNMENT_PROPERTY_NAME ) != Property::INVALID_INDEX ) + { + std::string value = child.GetProperty( child.GetPropertyIndex(CELL_VERTICAL_ALIGNMENT_PROPERTY_NAME) ).Get(); + Scripting::GetEnumeration< VerticalAlignment::Type >( value.c_str(), + VERTICAL_ALIGNMENT_STRING_TABLE, + VERTICAL_ALIGNMENT_STRING_TABLE_COUNT, + verticalAlignment ); + } + + Toolkit::TableView::CellPosition cellPosition; - if( child.GetPropertyIndex(Toolkit::TableView::ROW_SPAN_PROPERTY_NAME) != Property::INVALID_INDEX ) + if( child.GetPropertyIndex(ROW_SPAN_PROPERTY_NAME) != Property::INVALID_INDEX ) { - cellPosition.rowSpan = static_cast( child.GetProperty( child.GetPropertyIndex(Toolkit::TableView::ROW_SPAN_PROPERTY_NAME) ).Get() ); + cellPosition.rowSpan = static_cast( child.GetProperty( child.GetPropertyIndex(ROW_SPAN_PROPERTY_NAME) ).Get() ); } - if( child.GetPropertyIndex(Toolkit::TableView::COLUMN_SPAN_PROPERTY_NAME) != Property::INVALID_INDEX ) + if( child.GetPropertyIndex(COLUMN_SPAN_PROPERTY_NAME) != Property::INVALID_INDEX ) { - cellPosition.columnSpan = static_cast( child.GetProperty( child.GetPropertyIndex(Toolkit::TableView::COLUMN_SPAN_PROPERTY_NAME) ).Get() ); + cellPosition.columnSpan = static_cast( child.GetProperty( child.GetPropertyIndex(COLUMN_SPAN_PROPERTY_NAME) ).Get() ); } - if( child.GetPropertyIndex(Toolkit::TableView::CELL_INDICES_PROPERTY_NAME) != Property::INVALID_INDEX ) + if( child.GetPropertyIndex(CELL_INDEX_PROPERTY_NAME) != Property::INVALID_INDEX ) { - Vector2 indices = child.GetProperty( child.GetPropertyIndex(Toolkit::TableView::CELL_INDICES_PROPERTY_NAME) ).Get(); + Vector2 indices = child.GetProperty( child.GetPropertyIndex(CELL_INDEX_PROPERTY_NAME) ).Get(); cellPosition.rowIndex = static_cast( indices.x ); cellPosition.columnIndex = static_cast( indices.y ); AddChild( child, cellPosition ); + SetCellAlignment(cellPosition, horizontalAlignment, verticalAlignment); // Do not continue + RelayoutRequest(); return; } @@ -909,9 +997,12 @@ void TableView::OnControlChildAdd( Actor& child ) data.actor = child; data.position.columnIndex = column; data.position.rowIndex = row; + data.horizontalAlignment = horizontalAlignment; + data.verticalAlignment = verticalAlignment; mCellData[ row ][ column ] = data; // Don't continue + RelayoutRequest(); return; } } @@ -926,7 +1017,10 @@ void TableView::OnControlChildAdd( Actor& child ) data.actor = child; data.position.rowIndex = rowCount; data.position.columnIndex = 0; + data.horizontalAlignment = horizontalAlignment; + data.verticalAlignment = verticalAlignment; mCellData[ rowCount ][ 0 ] = data; + RelayoutRequest(); } void TableView::OnControlChildRemove( Actor& child ) @@ -1048,18 +1142,19 @@ bool TableView::RemoveAllInstances( const Actor& child ) void TableView::SetHeightOrWidthProperty(TableView& tableViewImpl, void(TableView::*funcFixed)(unsigned int, float), void(TableView::*funcRelative)(unsigned int, float), + void(TableView::*funcFit)(unsigned int), const Property::Value& value ) { Property::Map* map = value.GetMap(); if( map ) { - unsigned int rowIndex(0); + unsigned int index(0); for ( unsigned int i = 0, count = map->Count(); i < count; ++i ) { Property::Value& item = map->GetValue(i); Property::Map* childMap = item.GetMap(); - std::istringstream( map->GetKey(i) ) >> rowIndex; + std::istringstream( map->GetKey(i) ) >> index; if( childMap ) { Property::Value* policy = childMap->Find( "policy" ); @@ -1074,14 +1169,19 @@ void TableView::SetHeightOrWidthProperty(TableView& tableViewImpl, LAYOUT_POLICY_STRING_TABLE_COUNT, policy ) ) { - if( policy == Toolkit::TableView::FIXED ) + if( policy == Toolkit::TableView::FIXED ) { - (tableViewImpl.*funcFixed)( rowIndex, value->Get() ); + (tableViewImpl.*funcFixed)( index, value->Get() ); } else if( policy == Toolkit::TableView::RELATIVE ) { - (tableViewImpl.*funcRelative)( rowIndex, value->Get() ); + (tableViewImpl.*funcRelative)( index, value->Get() ); + } + else if( policy == Toolkit::TableView::FIT ) + { + (tableViewImpl.*funcFit)( index ); } + // do nothing for FILL policy } } } @@ -1105,63 +1205,56 @@ Property::Value TableView::GetColumnWidthsPropertyValue() void TableView::GetMapPropertyValue( const RowColumnArray& data, Property::Map& map ) { - const char* name = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::FIXED, - LAYOUT_POLICY_STRING_TABLE, - LAYOUT_POLICY_STRING_TABLE_COUNT ); - std::string fixedPolicy; - if( name ) - { - fixedPolicy = name; - } - name = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::RELATIVE, - LAYOUT_POLICY_STRING_TABLE, - LAYOUT_POLICY_STRING_TABLE_COUNT ); - std::string relativePolicy; - if( name ) - { - relativePolicy = name; - } + const char* fixedPolicy = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::FIXED, + LAYOUT_POLICY_STRING_TABLE, + LAYOUT_POLICY_STRING_TABLE_COUNT ); + const char* relativePolicy = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::RELATIVE, + LAYOUT_POLICY_STRING_TABLE, + LAYOUT_POLICY_STRING_TABLE_COUNT ); + const char* fillPolicy = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::FILL, + LAYOUT_POLICY_STRING_TABLE, + LAYOUT_POLICY_STRING_TABLE_COUNT ); + const char* fitPolicy = Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::FIT, + LAYOUT_POLICY_STRING_TABLE, + LAYOUT_POLICY_STRING_TABLE_COUNT ); const RowColumnArray::SizeType count = data.Size(); for( RowColumnArray::SizeType i = 0; i < count; i++ ) { const RowColumnData& dataInstance = data[ i ]; + Property::Map item; switch( dataInstance.sizePolicy ) { - case FIXED: + case Toolkit::TableView::FIXED: { - Property::Map item; item[ "policy" ] = fixedPolicy; item[ "value" ] = dataInstance.size; - - std::ostringstream ss; - ss << i; - - map[ ss.str() ] = item; - break; } - - case FILL: + case Toolkit::TableView::RELATIVE: { - Property::Map item; item[ "policy" ] = relativePolicy; item[ "value" ] = dataInstance.fillRatio; - - std::ostringstream ss; - ss << i; - - map[ ss.str() ] = item; - break; } - + case Toolkit::TableView::FIT: + { + item[ "policy" ] = fitPolicy; + item[ "value" ] = 0.f; + break; + } + case Toolkit::TableView::FILL: default: { + item[ "policy" ] = fillPolicy; + item[ "value" ] = 0.f; break; } } + std::ostringstream ss; + ss << i; + map[ ss.str() ] = item; } } @@ -1319,7 +1412,7 @@ float TableView::CalculateChildSize( const Actor& child, Dimension::Type dimensi } // Apply padding - cellSize -= mPadding.width * 2.0f; + cellSize -= mPadding.height * 2.0f; if( cellSize < 0.0f ) { cellSize = 0.0f; @@ -1384,16 +1477,13 @@ void TableView::ComputeRelativeSizes( RowColumnArray& data ) { RowColumnData& dataInstance = data[ i ]; - if( dataInstance.sizePolicy == FILL ) + if( dataInstance.sizePolicy == Toolkit::TableView::RELATIVE ) { - if( dataInstance.userFillRatio ) - { - relativeTotal += dataInstance.fillRatio; - } - else - { - fillData.PushBack( &dataInstance ); - } + relativeTotal += dataInstance.fillRatio; + } + else if(dataInstance.sizePolicy == Toolkit::TableView::FILL) + { + fillData.PushBack( &dataInstance ); } } @@ -1427,8 +1517,9 @@ float TableView::CalculateTotalFixedSize( const RowColumnArray& data ) switch( dataInstance.sizePolicy ) { - case FIXED: - case FIT: + // 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; @@ -1475,7 +1566,7 @@ void TableView::CalculateFixedSizes( RowColumnArray& data, Dimension::Type dimen { RowColumnData& dataInstance = data[ i ]; - if( dataInstance.sizePolicy == FIT ) + if( dataInstance.sizePolicy == Toolkit::TableView::FIT ) { // Find the size of the biggest actor in the row or column float maxActorHeight = 0.0f; @@ -1513,7 +1604,7 @@ void TableView::CalculateRelativeSizes( RowColumnArray& data, float size ) { RowColumnData& dataInstance = data[ i ]; - if( dataInstance.sizePolicy == FILL ) + if( dataInstance.sizePolicy == Toolkit::TableView::FILL || dataInstance.sizePolicy == Toolkit::TableView::RELATIVE) { dataInstance.size = dataInstance.fillRatio * size; } @@ -1524,7 +1615,7 @@ bool TableView::FindFit( const RowColumnArray& data ) { for( unsigned int i = 0, count = data.Size(); i < count; ++i ) { - if( data[ i ].sizePolicy == FIT ) + if( data[ i ].sizePolicy == Toolkit::TableView::FIT ) { return true; } diff --git a/dali-toolkit/internal/controls/table-view/table-view-impl.h b/dali-toolkit/internal/controls/table-view/table-view-impl.h index d1d8aef..62e0a6f 100644 --- a/dali-toolkit/internal/controls/table-view/table-view-impl.h +++ b/dali-toolkit/internal/controls/table-view/table-view-impl.h @@ -41,16 +41,6 @@ class TableView : public Control public: /** - * Enum for the size policies of rows and columns - */ - enum CellSizePolicy - { - FILL, ///< Fill up available space, may have a ratio associated with it - FIXED, ///< A specific fixed width or height - FIT ///< Fit around actors in the row or column - }; - - /** * Create a new TableView. * @return A smart-pointer to the newly allocated TableView. */ @@ -127,36 +117,24 @@ public: Size GetCellPadding(); /** - * @brief Set a row policy - * - * @param[in] rowIndex The row to set the policy for - * @param[in] policy The policy to set + * @copydoc Toolkit::TableView::SetFitHeight */ - void SetRowPolicy( unsigned int rowIndex, CellSizePolicy policy ); + void SetFitHeight( unsigned int rowIndex ); /** - * @brief Querry a row policy - * - * @param[in] rowIndex The row to querry - * @return Return the policy + * @copydoc Toolkit::TableView::IsFitHeight */ - CellSizePolicy GetRowPolicy( unsigned int rowIndex ) const; + bool IsFitHeight( unsigned int rowIndex ) const; /** - * @brief Set a column policy - * - * @param[in] columnIndex The column to set the policy for - * @param[in] policy The policy to set + * @copydoc Toolkit::TableView::SetFitWidth */ - void SetColumnPolicy( unsigned int columnIndex, CellSizePolicy policy ); + void SetFitWidth( unsigned int columnIndex ); /** - * @brief Querry a column policy - * - * @param[in] columnIndex The column to querry - * @return Return the policy + * @copydoc Toolkit::TableView::IsFitWidth */ - CellSizePolicy GetColumnPolicy( unsigned int columnIndex ) const; + bool IsFitWidth( unsigned int columnIndex ) const; /** * @copydoc Toolkit::TableView::SetFixedWidth @@ -299,8 +277,8 @@ private: // Implementation RowColumnData() : size( 0.0f ), fillRatio( 0.0f ), - sizePolicy( FILL ), - userFillRatio( false ) + position(0.0f), + sizePolicy( Toolkit::TableView::FILL ) { } @@ -310,18 +288,18 @@ private: // Implementation * @param[in] newSize The size to set for this data * @param[in] newSizePolicy The policy used to interpret the size value */ - RowColumnData( float newSize, float newFillRatio, CellSizePolicy newSizePolicy, bool newUserFillRatio ) + RowColumnData( float newSize, float newFillRatio, Toolkit::TableView::LayoutPolicy newSizePolicy ) : size( newSize ), fillRatio( newFillRatio ), - sizePolicy( newSizePolicy ), - userFillRatio( newUserFillRatio ) + position(0.0f), + sizePolicy( newSizePolicy ) { } - float size; ///< Set or calculated size - float fillRatio; ///< Ratio to fill remaining space - CellSizePolicy sizePolicy; ///< The size policy used to interpret the size value - bool userFillRatio : 1; ///< FillRatio was set by user + float size; ///< Set or calculated size + float fillRatio; ///< Ratio to fill remaining space, only valid with RELATIVE or FILL policy + float position; ///< Position of the row/column, this value is updated during every Relayout round + Toolkit::TableView::LayoutPolicy sizePolicy; ///< The size policy used to interpret the size value }; typedef Dali::Vector RowColumnArray; @@ -447,13 +425,15 @@ private: // scripting support /** * Called to set the heights/widths property. * @param[in] tableViewImpl The object whose property is set. - * @param[in] funcFixed The set function to call, it can be SetFixedHeight or SetFixedWidths. - * @param[in] funcRelative The set function to call, it can be SetRelativeHeight or SetRelativeWidths. + * @param[in] funcFixed The set function to call, it can be SetFixedHeight or SetFixedWidth. + * @param[in] funcRelative The set function to call, it can be SetRelativeHeight or SetRelativeWidth. + * @param[in] funcFit The set function to call, it can be SetFitHeight or SetFiltWidth. * @param[in] value The new property value. */ static void SetHeightOrWidthProperty( TableView& tableViewImpl, void(TableView::*funcFixed)(unsigned int, float), void(TableView::*funcRelative)(unsigned int, float), + void(TableView::*funcFit)(unsigned int), const Property::Value& map ); /** @@ -518,7 +498,7 @@ private: private: // Data - Array2d mCellData; ///< Data for each cell: Actor, alignment settings etc + Array2d mCellData; ///< Data for each cell: Actor, alignment settings etc RowColumnArray mRowData; ///< Data for each row RowColumnArray mColumnData; ///< Data for each column @@ -526,7 +506,7 @@ private: // Data Size mPadding; ///< Padding to apply to each cell bool mLayoutingChild; ///< Can't be a bitfield due to Relayouting lock - bool mRowColumnDirty : 1; ///< Flag to indicate the row column data is dirty + bool mRowColumnDirty : 1; ///< Flag to indicate the row column data is dirty }; } // namespace Internal diff --git a/dali-toolkit/public-api/controls/table-view/table-view.cpp b/dali-toolkit/public-api/controls/table-view/table-view.cpp index c92f36e..126c254 100644 --- a/dali-toolkit/public-api/controls/table-view/table-view.cpp +++ b/dali-toolkit/public-api/controls/table-view/table-view.cpp @@ -29,10 +29,6 @@ namespace Dali namespace Toolkit { -const std::string TableView::CELL_INDICES_PROPERTY_NAME("cell-indices"); -const std::string TableView::ROW_SPAN_PROPERTY_NAME("row-span"); -const std::string TableView::COLUMN_SPAN_PROPERTY_NAME("column-span"); - TableView::TableView() { } @@ -137,22 +133,22 @@ Size TableView::GetCellPadding() void TableView::SetFitHeight( unsigned int rowIndex ) { - GetImpl(*this).SetRowPolicy( rowIndex, Internal::TableView::FIT ); + GetImpl(*this).SetFitHeight( rowIndex ); } bool TableView::IsFitHeight( unsigned int rowIndex ) const { - return ( GetImpl(*this).GetRowPolicy( rowIndex ) == Internal::TableView::FIT ); + return GetImpl(*this).IsFitHeight( rowIndex ); } void TableView::SetFitWidth( unsigned int columnIndex ) { - GetImpl(*this).SetColumnPolicy( columnIndex, Internal::TableView::FIT ); + GetImpl(*this).SetFitWidth( columnIndex ); } bool TableView::IsFitWidth( unsigned int columnIndex ) const { - return ( GetImpl(*this).GetColumnPolicy( columnIndex ) == Internal::TableView::FIT ); + return GetImpl(*this).IsFitWidth( columnIndex ); } void TableView::SetFixedHeight( unsigned int rowIndex, float height ) diff --git a/dali-toolkit/public-api/controls/table-view/table-view.h b/dali-toolkit/public-api/controls/table-view/table-view.h index 46e3437..fb59939 100644 --- a/dali-toolkit/public-api/controls/table-view/table-view.h +++ b/dali-toolkit/public-api/controls/table-view/table-view.h @@ -41,6 +41,38 @@ class TableView; * TableView constrains the x and y position and width and height of the child actors. * z position and depth are left intact so that 3D model actors can also be laid out * in a grid without loosing their depth scaling. + * + * @nosubgrouping + * + * Per-child Custom properties for script supporting. + * + * When an actor is add to the tableView through Actor::Add() instead of TableView::AddChild, + * the following custom properties of the actor are checked to decide the actor position inside the table + * + * These properties are registered dynamically to the child and is non-animatable. + * + * | %Property Name | Type | + * |---------------------------|--------------------| + * | cell-index | Vector2 | + * | row-span | float | // type float (Currently builder is unable to differentiate integer and float from Json string) + * | column-span | float | // type float (Currently builder is unable to differentiate integer and float from Json string) + * | cell-horizontal-alignment | string | // available values: left, center, right + * | cell-vertical-alignment | string | // available values: top, center, bottom + * + * @code + * "name":"gallery-1", + * "type":"ImageActor", + * "image": { + * "filename": "{DALI_IMAGE_DIR}gallery-small-1.jpg" + * }, + * "custom-properties": { + * "cell-index":[1,1], // property to specify the top-left cell this child occupies, if not set, the first available cell is used + * "row-span":3, // property to specify how many rows this child occupies, if not set, default value is 1 + * "column-span": 2, // property to specify how many columns this child occupies, if nor set, default value is 1 + * "cell-horizontal-alignment": "left", // property to specify how to align horizontally inside the cells, if not set, default value is 'left' + * "cell-vertical-alignment": "center" // property to specify how to align vertically inside the cells, if not set, default value is 'top' + * } + * @endcode */ class DALI_IMPORT_API TableView : public Control { @@ -64,7 +96,8 @@ public: * "layout-rows": { "0": { "policy": "fixed", "value": 40 }, //@see SetFixedHight - "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeHeight + "2": { "policy": "relative", "value": 0.33 }, //@see SetRelativeHeight + "3": { "policy": "fit", "value":0.0 } //@see SetFitHeight, the value is not used, its height is decided by the children in this row } * @endcode * @@ -74,6 +107,7 @@ public: * "layout-columns": { "0": { "policy": "fixed", "value": 40 }, //@see SetFixedWidth + "1": { "policy": "fit", "value":0.0 } //@see SetFitHeight, the value is not used, its width is decided by the children in this column "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeWidth } * @endcode @@ -90,11 +124,6 @@ public: }; }; - // Custom properties for where to put the actor, these properties should be registered to the child which would be added to the table - static const std::string CELL_INDICES_PROPERTY_NAME; ///< Property, name "cell-indices", type Vector2 - static const std::string ROW_SPAN_PROPERTY_NAME; ///< Property, name "row-span", type float (Currently builder is unable to differentiate integer and float from Json string) - static const std::string COLUMN_SPAN_PROPERTY_NAME; ///< Property, name "column-span", type float (Currently builder is unable to differentiate integer and float from Json string) - /** * @brief Describes how the size of a row / column been set */ @@ -102,7 +131,8 @@ public: { FIXED, ///< Fixed with the given value. RELATIVE, ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width - FILL ///< Get the remainder of the 100% (after subtracting Padding, Fixed and Relative height/ width) divided evenly between 'fill' rows/columns + FILL, ///< Default policy, get the remainder of the 100% (after subtracting Padding, Fixed and Relative height/ width) divided evenly between 'fill' rows/columns + FIT ///< Fit around its children. }; /** @@ -382,11 +412,13 @@ public: unsigned int GetColumns(); /** - * @brief Set the alignment on a cell + * @brief Set the alignment on a cell. + * + * Cells without calling this function have the default values of LEFT and TOP respectively. * - * @param[in] position The cell to set alignment on - * @param[in] horizontal The horizontal alignment - * @param[in] vertical The vertical alignment + * @param[in] position The cell to set alignment on. + * @param[in] horizontal The horizontal alignment. + * @param[in] vertical The vertical alignment. */ void SetCellAlignment( CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical ); -- 2.7.4