From c67dcd03dc527baa8edcb6d4e8efcade2dde632b Mon Sep 17 00:00:00 2001 From: Xiangyin Ma Date: Thu, 10 Jul 2014 17:57:10 +0100 Subject: [PATCH] TableView - scripting support example: "stage": [ { "name":"simple-table", "type":"TableView", "background-color": [0.5,0.5,0,1], "parent-origin": "CENTER", "size":[400,500,1], "rows": 4, "columns":4, "cell-padding": [10, 5], "layout-animation-duration": 0.5, "layout-rows": { "0": { "policy": "fixed", "value": 40 }, "1": { "policy": "relative", "value": 0.33 }, "2": { "policy": "fixed", "value": 120 } }, "layout-columns": { "1": { "policy": "fixed", "value": 150 }, "2": { "policy": "relative", "value": 0.35 }, "3": { "policy": "relative", "value": 0.15 } }, "actors": [ { "name":"magazine-0", "type":"ImageActor", "image": { "filename": "{DALI_IMAGE_DIR}magazine_0.jpg" }, "custom-properties": { "cell-indices": [0,0], "row-span":4, "column-spam":1 } }, { "name":"magazine-1", "type":"ImageActor", "image": { "filename": "{DALI_IMAGE_DIR}magazine_1.jpg" }, "custom-properties": { "cell-indices":[1,1], "row-span":3 } }, { "name":"magazine-2", "type":"ImageActor", "image": { "filename": "{DALI_IMAGE_DIR}magazine_2.jpg" }, "custom-properties": { "cell-indices":[2,2] } }, { "name":"magazine-3", "type":"ImageActor", "image": { "filename": "{DALI_IMAGE_DIR}magazine_3.jpg" }, "custom-properties": { "cell-indices":[3,2], "column-span": 2 } } ] } ] Change-Id: Id07b8e6727caa6ba12c43610c630cfa54a955f80 Signed-off-by: Xiangyin Ma --- .../dali-toolkit-unmanaged/utc-Dali-TableView.cpp | 152 +++++++++++++ .../internal/builder/builder-actor.cpp | 32 ++- .../dali-toolkit/internal/builder/builder-impl.cpp | 6 +- .../controls/table-view/table-view-impl.cpp | 245 ++++++++++++++++++++- .../internal/controls/table-view/table-view-impl.h | 60 +++++ .../public-api/controls/table-view/table-view.cpp | 4 + .../public-api/controls/table-view/table-view.h | 51 +++++ 7 files changed, 538 insertions(+), 12 deletions(-) diff --git a/automated-tests/src/dali-toolkit-unmanaged/utc-Dali-TableView.cpp b/automated-tests/src/dali-toolkit-unmanaged/utc-Dali-TableView.cpp index 8d0cad6..a50ffc9 100644 --- a/automated-tests/src/dali-toolkit-unmanaged/utc-Dali-TableView.cpp +++ b/automated-tests/src/dali-toolkit-unmanaged/utc-Dali-TableView.cpp @@ -35,6 +35,15 @@ void dali_tableview_cleanup(void) namespace { + +const char* const PROPERTY_NAME_ROWS = "rows"; +const char* const PROPERTY_NAME_COLUMNS = "columns"; +const char* const PROPERTY_NAME_CELL_PADDING = "cell-padding"; +const char* const PROPERTY_NAME_LAYOUT_ANIMATION_DURATION = "layout-animation-duration"; +const char* const PROPERTY_NAME_LAYOUT_ROWS = "layout-rows"; +const char* const PROPERTY_NAME_LAYOUT_COLUMNS = "layout-columns"; + + static bool gObjectCreatedCallBackCalled; static void TestCallback(BaseHandle handle) @@ -541,3 +550,146 @@ int UtcDaliTableViewMetricsAssert(void) } END_TEST; } + +int UtcDaliTableViewSetGetProperty(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTableViewSetGetProperty"); + + // Create a 1x1 table-view + TableView tableView = TableView::New(1,1); + tableView.ApplyConstraint( Constraint::New( Actor::SIZE, Constraint100() ) ); + DALI_TEST_CHECK( tableView ); + + // Test "rows" property + DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_ROWS ) == TableView::PROPERTY_ROWS ); + + tableView.SetProperty( TableView::PROPERTY_ROWS, 4u ); + + DALI_TEST_CHECK( tableView.GetRows() == 4u ); + DALI_TEST_CHECK( tableView.GetProperty(TableView::PROPERTY_ROWS).Get() == 4u ); + + // Test "columns" property + DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_COLUMNS ) == TableView::PROPERTY_COLUMNS ); + + tableView.SetProperty( TableView::PROPERTY_COLUMNS, 5u ); + + DALI_TEST_CHECK( tableView.GetColumns() == 5u ); + DALI_TEST_CHECK( tableView.GetProperty(TableView::PROPERTY_COLUMNS).Get() == 5u ); + + // Test "cell-padding" property + DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_CELL_PADDING ) == TableView::PROPERTY_CELL_PADDING ); + + tableView.SetProperty( TableView::PROPERTY_CELL_PADDING, Size( 6.f, 8.f ) ); + + DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(6.f, 8.f), TEST_LOCATION ); + DALI_TEST_EQUALS( tableView.GetProperty(TableView::PROPERTY_CELL_PADDING).Get(), Vector2(6.f,8.f), TEST_LOCATION ); + + // Test "layout-animation-duration" property + DALI_TEST_CHECK( tableView.GetPropertyIndex(PROPERTY_NAME_LAYOUT_ANIMATION_DURATION) == TableView::PROPERTY_LAYOUT_ANIMATION_DURATION ); + + tableView.SetProperty( TableView::PROPERTY_LAYOUT_ANIMATION_DURATION, 1.5f ); + + DALI_TEST_EQUALS( tableView.GetLayoutAnimationDuration(), 1.5f, TEST_LOCATION ); + DALI_TEST_EQUALS( tableView.GetProperty(TableView::PROPERTY_LAYOUT_ANIMATION_DURATION).Get(), 1.5f, TEST_LOCATION ); + + //{ "policy": "fixed", "value": 30.0 }, + Property::Map item1; + item1.push_back( Property::StringValuePair( "policy", "fixed" ) ); + item1.push_back( Property::StringValuePair( "value", 30.f) ); + //{ "policy": "relative", "value": 0.2 }, + Property::Map item2; + item2.push_back( Property::StringValuePair( "policy", "relative" ) ); + item2.push_back( Property::StringValuePair( "value", 0.2f ) ); + + // Test "layout-rows" property + DALI_TEST_CHECK( tableView.GetPropertyIndex(PROPERTY_NAME_LAYOUT_ROWS) == TableView::PROPERTY_LAYOUT_ROWS ); + + /* + * "layout-rows": + * { + * "1": { "policy": "fixed", "value": 30 }, + * "3": { "policy": "relative", "value": 0.2 } + * } + */ + Property::Map layoutRows; + layoutRows.push_back( Property::StringValuePair("1", item1) ); + layoutRows.push_back( Property::StringValuePair("3", item2) ); + tableView.SetProperty( TableView::PROPERTY_LAYOUT_ROWS, layoutRows ); + + DALI_TEST_EQUALS( tableView.GetFixedHeight( 1u ), 30.f, TEST_LOCATION ); + DALI_TEST_EQUALS( tableView.GetRelativeHeight( 3u ), 0.2f, TEST_LOCATION ); + + Property::Map layoutRowsGet = tableView.GetProperty(TableView::PROPERTY_LAYOUT_ROWS).Get(); + DALI_TEST_CHECK( layoutRowsGet[0].first.compare(layoutRows[0].first) == 0 ); + DALI_TEST_CHECK( layoutRowsGet[0].second.GetValue( "policy" ).Get().compare(layoutRows[0].second.GetValue( "policy" ).Get()) == 0 ); + DALI_TEST_EQUALS( layoutRowsGet[0].second.GetValue( "value" ).Get(),layoutRows[0].second.GetValue( "value" ).Get(), TEST_LOCATION ); + DALI_TEST_CHECK( layoutRowsGet[1].first.compare(layoutRows[1].first) == 0 ); + DALI_TEST_CHECK( layoutRowsGet[1].second.GetValue( "policy" ).Get().compare(layoutRows[1].second.GetValue( "policy" ).Get()) == 0 ); + DALI_TEST_EQUALS( layoutRowsGet[1].second.GetValue( "value" ).Get(),layoutRows[1].second.GetValue( "value" ).Get(), TEST_LOCATION ); + + // Test "layout-columns" property + DALI_TEST_CHECK( tableView.GetPropertyIndex( PROPERTY_NAME_LAYOUT_COLUMNS ) == TableView::PROPERTY_LAYOUT_COLUMNS ); + + /* + * "layout-columns": + * { + * "2": { "policy": "relative", "value": 0.2 }, + * "3": { "policy": "fixed", "value": 30 } + * } + */ + Property::Map layoutColumns; + layoutColumns.push_back( Property::StringValuePair("2", item2) ); + layoutColumns.push_back( Property::StringValuePair("3", item1) ); + tableView.SetProperty( TableView::PROPERTY_LAYOUT_COLUMNS, layoutColumns ); + + DALI_TEST_EQUALS( tableView.GetRelativeWidth( 2u ), 0.2f, TEST_LOCATION ); + DALI_TEST_EQUALS( tableView.GetFixedWidth( 3u ), 30.f, TEST_LOCATION ); + + Property::Map layoutColumnsGet = tableView.GetProperty(TableView::PROPERTY_LAYOUT_COLUMNS).Get(); + DALI_TEST_CHECK( layoutColumnsGet[0].first.compare(layoutColumns[0].first) == 0 ); + DALI_TEST_CHECK( layoutColumnsGet[0].second.GetValue( "policy" ).Get().compare(layoutColumns[0].second.GetValue( "policy" ).Get()) == 0 ); + DALI_TEST_EQUALS( layoutColumnsGet[0].second.GetValue( "value" ).Get(),layoutColumns[0].second.GetValue( "value" ).Get(), TEST_LOCATION ); + DALI_TEST_CHECK( layoutColumnsGet[1].first.compare(layoutColumns[1].first) == 0 ); + DALI_TEST_CHECK( layoutColumnsGet[1].second.GetValue( "policy" ).Get().compare(layoutColumns[1].second.GetValue( "policy" ).Get()) == 0 ); + DALI_TEST_EQUALS( layoutColumnsGet[1].second.GetValue( "value" ).Get(),layoutColumns[1].second.GetValue( "value" ).Get(), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTableViewCustomProperties(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTableViewCustomProperties"); + + // Create a 10x10 table-view + TableView tableView = TableView::New(10,10); + tableView.ApplyConstraint( Constraint::New( Actor::SIZE, Constraint100() ) ); + 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 ) ); + tableView.Add( child1 ); + // Check for actors at actual positions. + DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(3,4)) == child1); + + // Create a second child actor with the custom properties + 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 ); + tableView.Add( child2 ); + // Check for actors at actual positions. + for( int i=0; i // INTERNAL INCLUDES -#include +#include +#include namespace Dali { @@ -33,12 +34,13 @@ namespace Internal { using namespace Dali::Scripting; +extern bool SetPropertyFromNode( const TreeNode& node, Property::Value& value, const Replacement& constant ); /* * Handles special case actor configuration (anything thats not already a property) * */ -Actor SetupActor( const TreeNode& child, Actor& actor ) +Actor SetupActor( const TreeNode& child, Actor& actor, const Replacement& constant ) { DALI_ASSERT_ALWAYS( actor && "Empty actor handle" ); @@ -69,6 +71,32 @@ Actor SetupActor( const TreeNode& child, Actor& actor ) } } + // Add custom properties + if( OptionalChild customPropertiesChild = IsChild(child, "custom-properties") ) + { + const TreeNode& customPropertiesNode = *customPropertiesChild; + const TreeConstIter endIter = customPropertiesNode.CEnd(); + for( TreeConstIter iter = customPropertiesNode.CBegin(); endIter != iter; ++iter ) + { + const TreeNode::KeyNodePair& keyChild = *iter; + std::string key( keyChild.first ); + + Property::Index index = actor.GetPropertyIndex( key ); + Property::Value value; + if( SetPropertyFromNode( keyChild.second, value, constant )) + { + if( Property::INVALID_INDEX == index ) + { + index = actor.RegisterProperty( key, value ); + } + else + { + actor.SetProperty( index, value ); + } + } + } + } + return actor; } diff --git a/base/dali-toolkit/internal/builder/builder-impl.cpp b/base/dali-toolkit/internal/builder/builder-impl.cpp index 9a5c0f6..dc59a7e 100644 --- a/base/dali-toolkit/internal/builder/builder-impl.cpp +++ b/base/dali-toolkit/internal/builder/builder-impl.cpp @@ -51,7 +51,7 @@ extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Prop extern bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value, const Replacement& replacements ); extern Actor SetupSignalAction(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor); extern Actor SetupPropertyNotification(ConnectionTracker* tracker, const TreeNode &root, const TreeNode &child, Actor actor); -extern Actor SetupActor( const TreeNode& node, Actor& actor ); +extern Actor SetupActor( const TreeNode& node, Actor& actor, const Replacement& constant ); #if defined(DEBUG_ENABLED) Integration::Log::Filter* gFilterScript = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_SCRIPT"); @@ -223,7 +223,7 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace std::string key( keyChild.first ); - // ignore special fields; type,actors,signals + // ignore special fields; type,actors,signals,styles if(key == KEYNAME_TYPE || key == KEYNAME_ACTORS || key == KEYNAME_SIGNALS || key == KEYNAME_STYLES) { continue; @@ -329,7 +329,7 @@ void Builder::ApplyProperties( const TreeNode& root, const TreeNode& node, if( actor ) { - SetupActor( node, actor ); + SetupActor( node, actor, constant ); // add signals SetupSignalAction( mSlotDelegate.GetConnectionTracker(), root, node, actor ); diff --git a/base/dali-toolkit/internal/controls/table-view/table-view-impl.cpp b/base/dali-toolkit/internal/controls/table-view/table-view-impl.cpp index 7f760db..b6ff462 100644 --- a/base/dali-toolkit/internal/controls/table-view/table-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/table-view/table-view-impl.cpp @@ -22,19 +22,13 @@ // EXTERNAL INCLUDES #include #include +#include using namespace Dali; using namespace std; namespace { -// Type registration -BaseHandle Create() -{ - return Toolkit::TableView::New(0, 0); -} -TypeRegistration mType( typeid(Toolkit::TableView), typeid(Toolkit::Control), Create ); - const float DEFAULT_CONSTRAINT_DURATION = 0.0f; /** @@ -138,9 +132,44 @@ namespace Dali namespace Toolkit { +const Property::Index TableView::PROPERTY_ROWS( Internal::TableView::TABLEVIEW_PROPERTY_START_INDEX ); +const Property::Index TableView::PROPERTY_COLUMNS( Internal::TableView::TABLEVIEW_PROPERTY_START_INDEX + 1 ); +const Property::Index TableView::PROPERTY_CELL_PADDING( Internal::TableView::TABLEVIEW_PROPERTY_START_INDEX + 2 ); +const Property::Index TableView::PROPERTY_LAYOUT_ANIMATION_DURATION( Internal::TableView::TABLEVIEW_PROPERTY_START_INDEX + 3 ); +const Property::Index TableView::PROPERTY_LAYOUT_ROWS( Internal::TableView::TABLEVIEW_PROPERTY_START_INDEX + 4 ); +const Property::Index TableView::PROPERTY_LAYOUT_COLUMNS( Internal::TableView::TABLEVIEW_PROPERTY_START_INDEX + 5 ); + namespace Internal { +namespace +{ + +const Scripting::StringEnum< Toolkit::TableView::LayoutPolicy > LAYOUT_POLICY_STRING_TABLE[] = +{ + { "fixed", Toolkit::TableView::Fixed }, + { "relative", Toolkit::TableView::Relative }, + { "fill", Toolkit::TableView::Fill } +}; + +const unsigned int LAYOUT_POLICY_STRING_TABLE_COUNT = sizeof(LAYOUT_POLICY_STRING_TABLE) / sizeof( LAYOUT_POLICY_STRING_TABLE[0] ); + +// Type registration +BaseHandle Create() +{ + return Toolkit::TableView::New(0, 0); +} +TypeRegistration mType( typeid(Toolkit::TableView), typeid(Toolkit::Control), Create ); + +PropertyRegistration property1( mType, "rows", Toolkit::TableView::PROPERTY_ROWS, Property::UNSIGNED_INTEGER, &TableView::SetProperty, &TableView::GetProperty ); +PropertyRegistration property2( mType, "columns", Toolkit::TableView::PROPERTY_COLUMNS, Property::UNSIGNED_INTEGER, &TableView::SetProperty, &TableView::GetProperty ); +PropertyRegistration property3( mType, "cell-padding", Toolkit::TableView::PROPERTY_CELL_PADDING, Property::VECTOR2, &TableView::SetProperty, &TableView::GetProperty ); +PropertyRegistration property4( mType, "layout-animation-duration", Toolkit::TableView::PROPERTY_LAYOUT_ANIMATION_DURATION, Property::FLOAT, &TableView::SetProperty, &TableView::GetProperty ); +PropertyRegistration property5( mType, "layout-rows", Toolkit::TableView::PROPERTY_LAYOUT_ROWS, Property::MAP, &TableView::SetProperty, &TableView::GetProperty ); +PropertyRegistration property6( mType, "layout-columns", Toolkit::TableView::PROPERTY_LAYOUT_COLUMNS, Property::MAP, &TableView::SetProperty, &TableView::GetProperty ); + +} // namespace + Toolkit::TableView TableView::New( unsigned int initialRows, unsigned int initialColumns ) { // Create the implementation, temporarily owned by this handle on stack @@ -517,6 +546,8 @@ void TableView::SetFixedHeight( unsigned int rowIndex, float height ) DALI_ASSERT_ALWAYS( rowIndex < mFixedHeights.size() ); // add the fixed height to the array of fixed heights mFixedHeights[ rowIndex ] = height; + // remove the relative height of the same row + mRelativeHeights[ rowIndex ] = 0.f; // relayout all cells, no lock needed as nothing added or removed RelayoutRequest(); } @@ -533,6 +564,8 @@ void TableView::SetRelativeHeight( unsigned int rowIndex, float heightPercentage DALI_ASSERT_ALWAYS( rowIndex < mRelativeHeights.size() ); // add the relative height to the array of relative heights mRelativeHeights[ rowIndex ] = heightPercentage; + // remove the fixed height of the same row + mFixedHeights[ rowIndex ] = 0.f; // relayout all cells, no lock needed as nothing added or removed RelayoutRequest(); } @@ -549,6 +582,8 @@ void TableView::SetFixedWidth( unsigned int columnIndex, float width ) DALI_ASSERT_ALWAYS( columnIndex < mFixedWidths.size() ); // add the fixed width to the array of fixed column widths mFixedWidths[ columnIndex ] = width; + // remove the relative width of the same column + mRelativeWidths[ columnIndex ] = 0.f; // relayout all cells, no lock needed as nothing added or removed RelayoutRequest(); } @@ -565,6 +600,8 @@ void TableView::SetRelativeWidth( unsigned int columnIndex, float widthPercentag DALI_ASSERT_ALWAYS( columnIndex < mRelativeWidths.size() ); // add the relative widths to the array of relative widths mRelativeWidths[ columnIndex ] = widthPercentage; + // remove the fixed width of the same column + mFixedWidths[ columnIndex ] = 0.f; // relayout all cells, no lock needed as nothing added or removed RelayoutRequest(); } @@ -738,6 +775,102 @@ unsigned int TableView::GetColumns() return mCellData.GetColumns(); } +void TableView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::TableView tableView = Toolkit::TableView::DownCast( Dali::BaseHandle( object ) ); + + if( tableView ) + { + TableView& tableViewImpl( GetImpl( tableView ) ); + switch( index ) + { + case Toolkit::TableView::PROPERTY_ROWS: + { + if( value.Get() != tableViewImpl.GetRows() ) + { + tableViewImpl.Resize( value.Get(), tableViewImpl.GetColumns() ); + } + break; + } + case Toolkit::TableView::PROPERTY_COLUMNS: + { + if( value.Get() != tableViewImpl.GetColumns() ) + { + tableViewImpl.Resize( tableViewImpl.GetRows(), value.Get() ); + } + break; + } + case Toolkit::TableView::PROPERTY_CELL_PADDING: + { + tableViewImpl.SetCellPadding( value.Get() ); + break; + } + case Toolkit::TableView::PROPERTY_LAYOUT_ANIMATION_DURATION: + { + tableViewImpl.SetLayoutAnimationDuration( value.Get() ); + break; + } + case Toolkit::TableView::PROPERTY_LAYOUT_ROWS: + { + SetHeightOrWidthProperty( tableViewImpl, &TableView::SetFixedHeight, &TableView::SetRelativeHeight, value ); + break; + } + case Toolkit::TableView::PROPERTY_LAYOUT_COLUMNS: + { + SetHeightOrWidthProperty( tableViewImpl, &TableView::SetFixedWidth, &TableView::SetRelativeWidth, value ); + break; + } + } + } +} + +Property::Value TableView::GetProperty( BaseObject* object, Property::Index index ) +{ + Property::Value value; + + Toolkit::TableView tableView = Toolkit::TableView::DownCast( Dali::BaseHandle( object ) ); + + if( tableView ) + { + TableView& tableViewImpl( GetImpl( tableView ) ); + switch( index ) + { + case Toolkit::TableView::PROPERTY_ROWS: + { + value = tableViewImpl.GetRows(); + break; + } + case Toolkit::TableView::PROPERTY_COLUMNS: + { + value = tableViewImpl.GetColumns(); + break; + } + case Toolkit::TableView::PROPERTY_CELL_PADDING: + { + value = tableViewImpl.GetCellPadding(); + break; + } + case Toolkit::TableView::PROPERTY_LAYOUT_ANIMATION_DURATION: + { + value = tableViewImpl.GetLayoutAnimationDuration(); + break; + } + case Toolkit::TableView::PROPERTY_LAYOUT_ROWS: + { + value = tableViewImpl.GetRowHeightsPropertyValue(); + break; + } + case Toolkit::TableView::PROPERTY_LAYOUT_COLUMNS: + { + value = tableViewImpl.GetColumnWidthsPropertyValue(); + break; + } + } + } + + return value; +} + void TableView::OnControlChildAdd( Actor& child ) { if( mLayoutingChild ) @@ -745,6 +878,27 @@ void TableView::OnControlChildAdd( Actor& child ) // we're in the middle of laying out children so no point doing anything here return; } + + Toolkit::TableView::CellPosition cellPosition; + if( child.GetPropertyIndex(Toolkit::TableView::ROW_SPAN_PROPERTY_NAME) != Property::INVALID_INDEX ) + { + cellPosition.rowSpan = static_cast( child.GetProperty( child.GetPropertyIndex(Toolkit::TableView::ROW_SPAN_PROPERTY_NAME) ).Get() ); + } + if( child.GetPropertyIndex(Toolkit::TableView::COLUMN_SPAN_PROPERTY_NAME) != Property::INVALID_INDEX ) + { + cellPosition.columnSpan = static_cast( child.GetProperty( child.GetPropertyIndex(Toolkit::TableView::COLUMN_SPAN_PROPERTY_NAME) ).Get() ); + } + if( child.GetPropertyIndex(Toolkit::TableView::CELL_INDICES_PROPERTY_NAME) != Property::INVALID_INDEX ) + { + Vector2 indices = child.GetProperty( child.GetPropertyIndex(Toolkit::TableView::CELL_INDICES_PROPERTY_NAME) ).Get(); + cellPosition.rowIndex = static_cast( indices.x ); + cellPosition.columnIndex = static_cast( indices.y ); + + AddChild( child, cellPosition ); + // donot continue + return; + } + // check if we're already laying out this child somewhere on the table // walk through the layout data const unsigned int rowCount = mCellData.GetRows(); @@ -996,6 +1150,83 @@ void TableView::UpdateRelativeSizes( float& fixedHeightsTotal, float& fixedWidth } } +void TableView::SetHeightOrWidthProperty(TableView& tableViewImpl, + void(TableView::*funcFixed)(unsigned int, float), + void(TableView::*funcRelative)(unsigned int, float), + const Property::Value& value ) +{ + if( Property::MAP == value.GetType() ) + { + Property::Map map = value.Get(); + unsigned int rowIndex; + for( Property::Map::const_iterator iter = map.begin(); iter != map.end(); iter++) + { + if( istringstream(iter->first) >> rowIndex // the key is a number + && Property::MAP == (iter->second).GetType()) + { + Property::Value item = iter->second; + if( item.HasKey( "policy" ) && item.HasKey( "value" ) ) + { + Toolkit::TableView::LayoutPolicy policy = Scripting::GetEnumeration< Toolkit::TableView::LayoutPolicy >( item.GetValue("policy").Get(), LAYOUT_POLICY_STRING_TABLE, LAYOUT_POLICY_STRING_TABLE_COUNT ); + if( policy == Toolkit::TableView::Fixed ) + { + (tableViewImpl.*funcFixed)( rowIndex, item.GetValue("value").Get() ); + } + else if( policy == Toolkit::TableView::Relative ) + { + (tableViewImpl.*funcRelative)( rowIndex, item.GetValue("value").Get() ); + } + } + } + } + } +} + +Property::Value TableView::GetRowHeightsPropertyValue() +{ + Property::Map map; + GetMapPropertyValue( mFixedHeights, mRelativeHeights, map); + return Property::Value(map); +} + +Property::Value TableView::GetColumnWidthsPropertyValue() +{ + Property::Map map; + GetMapPropertyValue( mFixedWidths, mRelativeWidths, map); + return Property::Value(map); +} + +void TableView::GetMapPropertyValue( const std::vector& fixedSize, const std::vector& relativeSize, Property::Map& map ) +{ + string fixedPolicy( Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::Fixed, LAYOUT_POLICY_STRING_TABLE, LAYOUT_POLICY_STRING_TABLE_COUNT ) ); + string relativePolicy( Scripting::GetEnumerationName< Toolkit::TableView::LayoutPolicy >( Toolkit::TableView::Relative, LAYOUT_POLICY_STRING_TABLE, LAYOUT_POLICY_STRING_TABLE_COUNT ) ); + Property::StringValuePair fixedPolicyPair( "policy", fixedPolicy ); + Property::StringValuePair relativePolicyPair( "policy", relativePolicy ); + + size_t count = fixedSize.size(); + for( size_t index = 0; index < count; index++ ) + { + if( ! EqualsZero( fixedSize[index] ) ) + { + Property::StringValuePair valuePair( "value", fixedSize[index] ); + Property::Map item; + item.push_back( fixedPolicyPair ); + item.push_back( valuePair ); + + map.push_back( Property::StringValuePair( static_cast( &(std::ostringstream() << index ) )->str(), item ) ); + } + else if( ! EqualsZero( relativeSize[index] ) ) + { + Property::StringValuePair valuePair( "value", relativeSize[index] ); + Property::Map item; + item.push_back( relativePolicyPair ); + item.push_back( valuePair ); + + map.push_back( Property::StringValuePair( static_cast( &(std::ostringstream() << index ) )->str(), item ) ); + } + } +} + TableView::~TableView() { // nothing to do diff --git a/base/dali-toolkit/internal/controls/table-view/table-view-impl.h b/base/dali-toolkit/internal/controls/table-view/table-view-impl.h index e5eeb43..183c822 100644 --- a/base/dali-toolkit/internal/controls/table-view/table-view-impl.h +++ b/base/dali-toolkit/internal/controls/table-view/table-view-impl.h @@ -40,6 +40,13 @@ class TableView : public Control { public: + // Properties + enum + { + TABLEVIEW_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, + TABLEVIEW_PROPERTY_END_INDEX = TABLEVIEW_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices + }; + /** * Structure for the layout data */ @@ -187,6 +194,24 @@ public: */ unsigned int GetColumns(); + // Properties + + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] index The property index. + * @param[in] value The new property value. + */ + static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ); + + /** + * Called to retrieve a property of an object of this type. + * @param[in] object The object whose property is to be retrieved. + * @param[in] index The property index. + * @return The current value of the property. + */ + static Property::Value GetProperty( BaseObject* object, Property::Index index ); + private: // From Control /** @@ -266,6 +291,41 @@ private: // Implementation */ virtual ~TableView(); +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] value The new property value. + */ + static void SetHeightOrWidthProperty( TableView& tableViewImpl, + void(TableView::*funcFixed)(unsigned int, float), + void(TableView::*funcRelative)(unsigned int, float), + const Property::Value& map ); + + /** + * Called to retrieve the property value of row heights. + * @return The property value of row heights. + */ + Property::Value GetRowHeightsPropertyValue(); + + /** + * Called to retrieve the property value of column widths. + * @return The fixed-widths property value. + */ + Property::Value GetColumnWidthsPropertyValue(); + + /** + * Generate the map type property value from the size vectors. + * @param[in] fixedSize The vector of fixed heights or widths. + * @param[in] relativeSize The vector of relative heights or widths. + * @param[out] map The property value. + */ + void GetMapPropertyValue( const std::vector& fixedSize, const std::vector& relativeSize, Property::Map& map ); + + /** * Helper class to prevent child adds and removes from causing relayout * when we're already anyways going to do one in the end diff --git a/base/dali-toolkit/public-api/controls/table-view/table-view.cpp b/base/dali-toolkit/public-api/controls/table-view/table-view.cpp index 99e3983..06c18a9 100644 --- a/base/dali-toolkit/public-api/controls/table-view/table-view.cpp +++ b/base/dali-toolkit/public-api/controls/table-view/table-view.cpp @@ -29,6 +29,10 @@ 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() { } diff --git a/base/dali-toolkit/public-api/controls/table-view/table-view.h b/base/dali-toolkit/public-api/controls/table-view/table-view.h index 73cb39a..9051045 100644 --- a/base/dali-toolkit/public-api/controls/table-view/table-view.h +++ b/base/dali-toolkit/public-api/controls/table-view/table-view.h @@ -43,6 +43,57 @@ class TableView : public Control { public: + /// @name Properties + /** @{ */ + static const Property::Index PROPERTY_ROWS; ///< name "rows", type UNSIGNED_INTEGER + static const Property::Index PROPERTY_COLUMNS; ///< name "columns", type UNSIGNED_INTEGER + static const Property::Index PROPERTY_CELL_PADDING; ///< name "cell-padding", type VECTOR2 + static const Property::Index PROPERTY_LAYOUT_ANIMATION_DURATION; ///< name "layout-animation-duration", type FLOAT + + /* + * PROPERTY_LAYOUT_ROWS set the height of the rows + * It has the format as follows in script: + * @code + * "layout-rows": + { + "0": { "policy": "fixed", "value": 40 }, //@see SetFixedHight + "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeHeight + } + * @endcode + */ + static const Property::Index PROPERTY_LAYOUT_ROWS; ///< name "layout-rows", type MAP + + /* + * PROPERTY_LAYOUT_COLUMNS set the height of the rows + * It has the format as follows in script: + * @code + * "layout-columns": + { + "0": { "policy": "fixed", "value": 40 }, //@see SetFixedWidth + "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeWidth + } + * @endcode + */ + static const Property::Index PROPERTY_LAYOUT_COLUMNS; ///< name "layout-columns", type MAP + /** @} */ + + + // 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 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 unable to differentiate integer and float from Json string) + + + /** + * @brief Describes how the size of a row / column been set + */ + enum LayoutPolicy + { + 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 + }; + /** * Structure to specify layout position for child actor */ -- 2.7.4