From: Xiangyin Ma Date: Fri, 26 Jun 2015 14:30:34 +0000 (+0100) Subject: TableView: Cleanup X-Git-Tag: dali_1.0.47~12 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=9d225ea151817d5de5b2ecd8d151da84ef685a23 TableView: Cleanup Change-Id: Icc063e8d9c83efeeec0560ef1d02e1e79e0f0d53 --- diff --git a/dali-toolkit/internal/controls/table-view/table-view-impl.cpp b/dali-toolkit/internal/controls/table-view/table-view-impl.cpp index 2250801..f355713 100644 --- a/dali-toolkit/internal/controls/table-view/table-view-impl.cpp +++ b/dali-toolkit/internal/controls/table-view/table-view-impl.cpp @@ -254,6 +254,15 @@ bool TableView::AddChild( Actor& child, const Toolkit::TableView::CellPosition& } // Relayout the whole table + if( mRowData[position.rowIndex].sizePolicy == Toolkit::TableView::FIT && position.rowSpan == 1 ) + { + mRowDirty = true; + } + if( mColumnData[position.columnIndex].sizePolicy == Toolkit::TableView::FIT && position.columnSpan == 1 ) + { + mColumnDirty = true; + } + RelayoutRequest(); return true; // Addition successful @@ -284,6 +293,14 @@ Actor TableView::RemoveChildAt( const Toolkit::TableView::CellPosition& position // relayout the table only if instances were found if( RemoveAllInstances( child ) ) { + if( mRowData[position.rowIndex].sizePolicy == Toolkit::TableView::FIT ) + { + mRowDirty = true; + } + if( mColumnData[position.columnIndex].sizePolicy == Toolkit::TableView::FIT ) + { + mColumnDirty = true; + } RelayoutRequest(); } } @@ -354,7 +371,7 @@ void TableView::InsertRow( unsigned int rowIndex ) mRowData.Insert( mRowData.Begin() + rowIndex, RowColumnData() ); // Sizes may have changed, so relayout - mRowColumnDirty = true; + mRowDirty = true; RelayoutRequest(); } @@ -410,7 +427,10 @@ void TableView::DeleteRow( unsigned int rowIndex, std::vector& removed ) mRowData.Erase( mRowData.Begin() + rowIndex ); // Sizes may have changed, so relayout - mRowColumnDirty = true; + mRowDirty = true; + // it is possible that the deletion of row leads to remove of child which might further lead to the change of FIT column + mColumnDirty = true; + RelayoutRequest(); } @@ -453,7 +473,7 @@ void TableView::InsertColumn( unsigned int columnIndex ) mColumnData.Insert( mColumnData.Begin() + columnIndex, RowColumnData() ); // Sizes may have changed so relayout - mRowColumnDirty = true; + mColumnDirty = true; RelayoutRequest(); } @@ -509,7 +529,10 @@ void TableView::DeleteColumn( unsigned int columnIndex, std::vector& remo mColumnData.Erase( mColumnData.Begin() + columnIndex ); // Size may have changed so relayout - mRowColumnDirty = true; + mColumnDirty = true; + // it is possible that the deletion of column leads to remove of child which might further lead to the change of FIT row + mRowDirty = true; + RelayoutRequest(); } @@ -550,7 +573,8 @@ void TableView::Resize( unsigned int rows, unsigned int columns, std::vector 0 ? mColumnData[column-1].position : 0.f; + float right = mColumnData[column+position.columnSpan-1].position; + float top = row > 0 ? mRowData[row-1].position : 0.f; + float bottom = mRowData[row+position.rowSpan-1].position; + if( cellData.horizontalAlignment == HorizontalAlignment::LEFT ) { - actor.SetX( mColumnData[column].position + mPadding.width + padding.left ); + actor.SetX( left + mPadding.width + padding.left ); } - else + else if( cellData.horizontalAlignment == HorizontalAlignment::RIGHT ) { - float cellRightPosition = column+position.columnSpan < columnCount ? mColumnData[column+position.columnSpan].position : cumulatedWidth; - - 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 ); - } + actor.SetX( right - mPadding.width - padding.right - actor.GetRelayoutSize( Dimension::WIDTH ) ); + } + else //if( cellData.horizontalAlignment == HorizontalAlignment::CENTER ) + { + actor.SetX( (left + right + padding.left - padding.right - actor.GetRelayoutSize( Dimension::WIDTH )) * 0.5f ); } if( cellData.verticalAlignment == VerticalAlignment::TOP ) { - actor.SetY( mRowData[row].position + mPadding.height + padding.top ); + actor.SetY( top + mPadding.height + padding.top ); } - else + else if( cellData.verticalAlignment == VerticalAlignment::BOTTOM ) { - 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 ); - } + actor.SetY( bottom - mPadding.height - padding.bottom - actor.GetRelayoutSize( Dimension::HEIGHT ) ); + } + else //if( cellData.verticalAlignment = VerticalAlignment::CENTER ) + { + actor.SetY( (top + bottom + padding.top - padding.bottom - actor.GetRelayoutSize( Dimension::HEIGHT )) * 0.5f ); } } } @@ -979,7 +1002,6 @@ void TableView::OnControlChildAdd( Actor& child ) SetCellAlignment(cellPosition, horizontalAlignment, verticalAlignment); // Do not continue - RelayoutRequest(); return; } @@ -1040,7 +1062,8 @@ TableView::TableView( unsigned int initialRows, unsigned int initialColumns ) : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ), mCellData( initialRows, initialColumns ), mLayoutingChild( false ), - mRowColumnDirty( true ) // Force recalculation first time + mRowDirty( true ), // Force recalculation first time + mColumnDirty( true ) { SetKeyboardNavigationSupport( true ); ResizeContainers( initialRows, initialColumns ); @@ -1357,76 +1380,44 @@ Vector3 TableView::GetNaturalSize() float TableView::CalculateChildSize( const Actor& child, Dimension::Type dimension ) { - CalculateRowColumnData(); - - const unsigned int rowCount = mCellData.GetRows(); - const unsigned int columnCount = mCellData.GetColumns(); - - for( unsigned int row = 0; row < rowCount; ++row ) + Toolkit::TableView::CellPosition position; + if( FindChildPosition( child, position) ) { - for( unsigned int column = 0; column < columnCount; ++column ) + switch( dimension ) { - // check if this cell has an actor - Actor& actor = mCellData[ row ][ column ].actor; - - if( actor && ( actor == child ) ) + case Dimension::WIDTH: { - const Toolkit::TableView::CellPosition position = mCellData[ row ][ column ].position; + 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 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. - if ( ( position.rowIndex == row ) && ( position.columnIndex == column ) ) + if( cellSize < 0.0f ) { - switch( dimension ) - { - case Dimension::WIDTH: - { - float cellSize = 0.0f; - - // Accumulate the width - for( unsigned int i = 0; i < position.columnSpan; ++i ) - { - DALI_ASSERT_DEBUG( column + i < mColumnData.Size() ); - cellSize += mColumnData[ column + i ].size; - } - - // Apply padding - cellSize -= mPadding.width * 2.0f; - if( cellSize < 0.0f ) - { - cellSize = 0.0f; - } - - return cellSize; - } + cellSize = 0.0f; + } - case Dimension::HEIGHT: - { - float cellSize = 0.0f; - - // Accumulate the height - for( unsigned int i = 0; i < position.rowSpan; ++i ) - { - DALI_ASSERT_DEBUG( row + i < mRowData.Size() ); - cellSize += mRowData[ row + i ].size; - } - - // Apply padding - cellSize -= mPadding.height * 2.0f; - if( cellSize < 0.0f ) - { - cellSize = 0.0f; - } - - return cellSize; - } + return cellSize; + } - default: - { - return 0.0f; - } - } + 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; } } } @@ -1465,7 +1456,7 @@ void TableView::SetCellAlignment( Toolkit::TableView::CellPosition position, Hor data.verticalAlignment = vertical; } -void TableView::ComputeRelativeSizes( RowColumnArray& data ) +void TableView::CalculateFillSizes( RowColumnArray& data ) { // First pass: Count number of fill entries and calculate used relative space Dali::Vector< RowColumnData* > fillData; @@ -1556,7 +1547,7 @@ Vector2 TableView::GetCellPadding( Dimension::Type dimension ) return Vector2(); } -void TableView::CalculateFixedSizes( RowColumnArray& data, Dimension::Type dimension ) +void TableView::CalculateFitSizes( RowColumnArray& data, Dimension::Type dimension ) { Vector2 cellPadding = GetCellPadding( dimension ); @@ -1596,21 +1587,6 @@ void TableView::CalculateFixedSizes( RowColumnArray& data, Dimension::Type dimen } } -void TableView::CalculateRelativeSizes( RowColumnArray& data, float size ) -{ - const unsigned int dataCount = data.Size(); - - for( unsigned int i = 0; i < dataCount; ++i ) - { - RowColumnData& dataInstance = data[ i ]; - - if( dataInstance.sizePolicy == Toolkit::TableView::FILL || dataInstance.sizePolicy == Toolkit::TableView::RELATIVE) - { - dataInstance.size = dataInstance.fillRatio * size; - } - } -} - bool TableView::FindFit( const RowColumnArray& data ) { for( unsigned int i = 0, count = data.Size(); i < count; ++i ) 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 62e0a6f..2543b5e 100644 --- a/dali-toolkit/internal/controls/table-view/table-view-impl.h +++ b/dali-toolkit/internal/controls/table-view/table-view-impl.h @@ -267,7 +267,7 @@ private: // Implementation * Struct to hold data for rows and columns * * If sizePolicy is FIXED then size is the absolute size to use. - * If sizePolicy is FIT or FILL then size is the calculated value of size. + * If sizePolicy is FIT, RELATIVE or FILL then size is the calculated value of size. */ struct RowColumnData { @@ -277,7 +277,7 @@ private: // Implementation RowColumnData() : size( 0.0f ), fillRatio( 0.0f ), - position(0.0f), + position( 0.0f ), sizePolicy( Toolkit::TableView::FILL ) { } @@ -291,7 +291,7 @@ private: // Implementation RowColumnData( float newSize, float newFillRatio, Toolkit::TableView::LayoutPolicy newSizePolicy ) : size( newSize ), fillRatio( newFillRatio ), - position(0.0f), + position( 0.0f ), sizePolicy( newSizePolicy ) { } @@ -365,11 +365,11 @@ private: bool RemoveAllInstances( const Actor& child ); /** - * @brief Compute relative sizes for an array + * @brief Calculate the ratio of FILL rows/columns * * @param[in] data The RowColumn data to compute the relative sizes for */ - void ComputeRelativeSizes( RowColumnArray& data ); + void CalculateFillSizes( RowColumnArray& data ); /** * @brief Calculate the total fixed sizes for a row or column @@ -379,20 +379,12 @@ private: float CalculateTotalFixedSize( const RowColumnArray& data ); /** - * @brief Calculate the fixed sizes for a row or column + * @brief Calculate the sizes of FIT rows/columns * * @param[in] data The row or column data to process * @param[in] dimension The dimension being calculated: row == Dimension::HEIGHT, column == Dimension::WIDTH */ - void CalculateFixedSizes( RowColumnArray& data, Dimension::Type dimension ); - - /** - * @brief Calculate the value of the relative sizes - * - * @param[in] data The row or column data to process - * @param[in] size The size of the table view in that dimension - */ - void CalculateRelativeSizes( RowColumnArray& data, float size ); + void CalculateFitSizes( RowColumnArray& data, Dimension::Type dimension ); /** * @brief Search for a FIT cell in the array @@ -403,11 +395,6 @@ private: bool FindFit( const RowColumnArray& data ); /** - * @brief Calculate row and column data when it is dirty - */ - void CalculateRowColumnData(); - - /** * @brief Return the cell padding for a given dimension * * @param[in] dimension The dimension to return the padding for @@ -506,7 +493,8 @@ 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 mRowDirty : 1; ///< Flag to indicate the row data is dirty + bool mColumnDirty : 1; ///< Flag to indicate the column data is dirty }; } // namespace Internal 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 fb59939..c3f0545 100644 --- a/dali-toolkit/public-api/controls/table-view/table-view.h +++ b/dali-toolkit/public-api/controls/table-view/table-view.h @@ -37,27 +37,31 @@ class TableView; } /** - * TableView is a layout container for aligning child actors in a grid like layout. + * @brief TableView is a layout container for aligning child actors in a grid like layout. + * * 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. + *

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 + * 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 + * | %Property Name | Type | + * |---------------------------|-------------| + * | cell-index | Vector2 | + * | row-span | float | + * | column-span | float | + * | cell-horizontal-alignment | string | + * | cell-vertical-alignment | string | + * + * The row-span or column span has integer value, but its type is float here due to the limitation of the builder's ability to differentiate integer and float from Json string. + * The available values for cell-horizontal-alignment are: left, center, right. + * The available values for cell-vertical-alignment are: top, center, bottom. * * @code * "name":"gallery-1", @@ -131,7 +135,7 @@ public: { FIXED, ///< Fixed with the given value. RELATIVE, ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width - FILL, ///< Default policy, 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 Fixed, Fit and Relative height/ width) divided evenly between 'fill' rows/columns FIT ///< Fit around its children. };