From c46d8cb79f848d9e1fda57a46a987aadea57a7cd Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Fri, 20 May 2016 15:35:19 +0100 Subject: [PATCH 1/1] Add child property registration for TableView Change-Id: Ib043392dea1ea27cc65042d82927f6f8b909afa0 --- .../src/dali-toolkit/utc-Dali-TableView.cpp | 16 ++++---- .../flex-container/flex-container-impl.cpp | 43 ++++++++++++--------- .../controls/table-view/table-view-impl.cpp | 44 +++++++++------------- .../public-api/controls/table-view/table-view.h | 21 ++++++++++- docs/content/programming-guide/properties.h | 3 +- 5 files changed, 74 insertions(+), 53 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp index 708fa3c..7beeb96 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp @@ -686,10 +686,10 @@ int UtcDaliTableViewSetGetProperty(void) END_TEST; } -int UtcDaliTableViewCustomProperties(void) +int UtcDaliTableViewChildProperties(void) { ToolkitTestApplication application; - tet_infoline("UtcDaliTableViewCustomProperties"); + tet_infoline("UtcDaliTableViewChildProperties"); // Create a 10x10 table-view TableView tableView = TableView::New(10,10); @@ -700,7 +700,7 @@ int UtcDaliTableViewCustomProperties(void) // Create a child actor with the custom properties Actor child1 = Actor::New(); - child1.RegisterProperty( "cellIndex", Vector2( 3, 4 ), Property::READ_WRITE ); + child1.SetProperty( TableView::ChildProperty::CELL_INDEX, Vector2( 3, 4 ) ); tableView.Add( child1 ); // Check for actors at actual positions. DALI_TEST_CHECK( tableView.GetChildAt(TableView::CellPosition(3,4)) == child1); @@ -709,9 +709,9 @@ int UtcDaliTableViewCustomProperties(void) Actor child2 = Actor::New(); float rowSpan = 3.f; float columnSpan = 2.f; - child2.RegisterProperty( "cellIndex", Vector2( 6, 1 ), Property::READ_WRITE ); - child2.RegisterProperty( "rowSpan", rowSpan, Property::READ_WRITE ); - child2.RegisterProperty( "columnSpan", columnSpan, Property::READ_WRITE ); + child2.SetProperty( TableView::ChildProperty::CELL_INDEX, Vector2( 6, 1 ) ); + child2.SetProperty( TableView::ChildProperty::ROW_SPAN, rowSpan ); + child2.SetProperty( TableView::ChildProperty::COLUMN_SPAN, columnSpan ); tableView.Add( child2 ); // Check for actors at actual positions. for( int i=0; istyle.flex = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::FLEX ).Get(); - - Toolkit::FlexContainer::Alignment alignSelf( Toolkit::FlexContainer::ALIGN_AUTO ); - Property::Value alignSelfPropertyValue = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::ALIGN_SELF ); - if( alignSelfPropertyValue.GetType() == Property::INTEGER ) + if( childActor.GetPropertyType( Toolkit::FlexContainer::ChildProperty::FLEX ) != Property::NONE ) { - alignSelf = static_cast( alignSelfPropertyValue.Get< int >() ); + childNode->style.flex = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::FLEX ).Get(); } - else if( alignSelfPropertyValue.GetType() == Property::STRING ) + + Toolkit::FlexContainer::Alignment alignSelf( Toolkit::FlexContainer::ALIGN_AUTO ); + if( childActor.GetPropertyType( Toolkit::FlexContainer::FlexContainer::ChildProperty::ALIGN_SELF ) != Property::NONE ) { - std::string value = alignSelfPropertyValue.Get(); - Scripting::GetEnumeration< Toolkit::FlexContainer::Alignment >( value.c_str(), - ALIGN_SELF_STRING_TABLE, - ALIGN_SELF_STRING_TABLE_COUNT, - alignSelf ); + Property::Value alignSelfPropertyValue = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::ALIGN_SELF ); + if( alignSelfPropertyValue.GetType() == Property::INTEGER ) + { + alignSelf = static_cast( alignSelfPropertyValue.Get< int >() ); + } + else if( alignSelfPropertyValue.GetType() == Property::STRING ) + { + std::string value = alignSelfPropertyValue.Get(); + Scripting::GetEnumeration< Toolkit::FlexContainer::Alignment >( value.c_str(), + ALIGN_SELF_STRING_TABLE, + ALIGN_SELF_STRING_TABLE_COUNT, + alignSelf ); + } } childNode->style.align_self = static_cast(alignSelf); - Vector4 flexMargin = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::FLEX_MARGIN ).Get(); - childNode->style.margin[CSS_LEFT] = flexMargin.x; - childNode->style.margin[CSS_TOP] = flexMargin.y; - childNode->style.margin[CSS_RIGHT] = flexMargin.z; - childNode->style.margin[CSS_BOTTOM] = flexMargin.w; + if( childActor.GetPropertyType( Toolkit::FlexContainer::ChildProperty::FLEX_MARGIN ) != Property::NONE ) + { + Vector4 flexMargin = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::FLEX_MARGIN ).Get(); + childNode->style.margin[CSS_LEFT] = flexMargin.x; + childNode->style.margin[CSS_TOP] = flexMargin.y; + childNode->style.margin[CSS_RIGHT] = flexMargin.z; + childNode->style.margin[CSS_BOTTOM] = flexMargin.w; + } } // Calculate the layout 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 bac0402..94ba402 100644 --- a/dali-toolkit/internal/controls/table-view/table-view-impl.cpp +++ b/dali-toolkit/internal/controls/table-view/table-view-impl.cpp @@ -31,20 +31,6 @@ using namespace Dali; namespace { -/* - * Custom properties for where to put the actor. - * - * 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 non-animatable properties should be registered to the child which would be added to the table - */ -const char * const CELL_INDEX_PROPERTY_NAME("cellIndex"); -const char * const ROW_SPAN_PROPERTY_NAME("rowSpan"); -const char * const COLUMN_SPAN_PROPERTY_NAME("columnSpan"); -const char * const CELL_HORIZONTAL_ALIGNMENT_PROPERTY_NAME("cellHorizontalAlignment"); -const char * const CELL_VERTICAL_ALIGNMENT_PROPERTY_NAME("cellVerticalAlignment"); - /** * @brief Should the tableview fit around the given actor * @@ -147,6 +133,11 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TableView, "columns", INTEGER, COLUM DALI_PROPERTY_REGISTRATION( Toolkit, TableView, "cellPadding", VECTOR2, CELL_PADDING ) DALI_PROPERTY_REGISTRATION( Toolkit, TableView, "layoutRows", MAP, LAYOUT_ROWS ) DALI_PROPERTY_REGISTRATION( Toolkit, TableView, "layoutColumns", MAP, LAYOUT_COLUMNS ) +DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "cellIndex", VECTOR2, CELL_INDEX ) +DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "rowSpan", FLOAT, ROW_SPAN ) +DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "columnSpan", FLOAT, COLUMN_SPAN ) +DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "cellHorizontalAlignment", STRING, CELL_HORIZONTAL_ALIGNMENT ) +DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, TableView, "cellVerticalAlignment", STRING, CELL_VERTICAL_ALIGNMENT ) DALI_TYPE_REGISTRATION_END() @@ -978,41 +969,42 @@ void TableView::OnChildAdd( Actor& child ) return; } - // Test properties on actor + // Check child properties on actor to decide its position inside the table HorizontalAlignment::Type horizontalAlignment = HorizontalAlignment::LEFT; VerticalAlignment::Type verticalAlignment = VerticalAlignment::TOP; - if( child.GetPropertyIndex( CELL_HORIZONTAL_ALIGNMENT_PROPERTY_NAME ) != Property::INVALID_INDEX ) + + if( child.GetPropertyType( Toolkit::TableView::ChildProperty::CELL_HORIZONTAL_ALIGNMENT ) != Property::NONE ) { - std::string value = child.GetProperty( child.GetPropertyIndex(CELL_HORIZONTAL_ALIGNMENT_PROPERTY_NAME) ).Get(); + std::string value = child.GetProperty( Toolkit::TableView::ChildProperty::CELL_HORIZONTAL_ALIGNMENT ).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 ) + + if( child.GetPropertyType( Toolkit::TableView::ChildProperty::CELL_VERTICAL_ALIGNMENT ) != Property::NONE ) { - std::string value = child.GetProperty( child.GetPropertyIndex(CELL_VERTICAL_ALIGNMENT_PROPERTY_NAME) ).Get(); + std::string value = child.GetProperty( Toolkit::TableView::ChildProperty::CELL_VERTICAL_ALIGNMENT ).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(ROW_SPAN_PROPERTY_NAME) != Property::INVALID_INDEX ) + if( child.GetPropertyType( Toolkit::TableView::ChildProperty::ROW_SPAN ) != Property::NONE ) { - cellPosition.rowSpan = static_cast( child.GetProperty( child.GetPropertyIndex(ROW_SPAN_PROPERTY_NAME) ).Get() ); + cellPosition.rowSpan = static_cast( child.GetProperty( Toolkit::TableView::ChildProperty::ROW_SPAN ).Get() ); } - if( child.GetPropertyIndex(COLUMN_SPAN_PROPERTY_NAME) != Property::INVALID_INDEX ) + if( child.GetPropertyType( Toolkit::TableView::ChildProperty::COLUMN_SPAN ) != Property::NONE ) { - cellPosition.columnSpan = static_cast( child.GetProperty( child.GetPropertyIndex(COLUMN_SPAN_PROPERTY_NAME) ).Get() ); + cellPosition.columnSpan = static_cast( child.GetProperty( Toolkit::TableView::ChildProperty::COLUMN_SPAN ).Get() ); } - if( child.GetPropertyIndex(CELL_INDEX_PROPERTY_NAME) != Property::INVALID_INDEX ) + if( child.GetPropertyType( Toolkit::TableView::ChildProperty::CELL_INDEX ) != Property::NONE ) { - Vector2 indices = child.GetProperty( child.GetPropertyIndex(CELL_INDEX_PROPERTY_NAME) ).Get(); + Vector2 indices = child.GetProperty( Toolkit::TableView::ChildProperty::CELL_INDEX ).Get(); cellPosition.rowIndex = static_cast( indices.x ); cellPosition.columnIndex = static_cast( indices.y ); 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 94257ee..e3f17b7 100644 --- a/dali-toolkit/public-api/controls/table-view/table-view.h +++ b/dali-toolkit/public-api/controls/table-view/table-view.h @@ -94,7 +94,10 @@ public: enum PropertyRange { PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0 - PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices @SINCE_1_0.0 + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ///< Reserve property indices @SINCE_1_0.0 + + CHILD_PROPERTY_START_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX, ///< @SINCE_1_1.36 + CHILD_PROPERTY_END_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX + 1000 ///< Reserve child property indices @SINCE_1_1.36 }; /** @@ -136,6 +139,22 @@ public: }; /** + * @brief An enumeration of child properties belonging to the TableView class. + * @SINCE_1_1.36 + */ + struct ChildProperty + { + enum + { + CELL_INDEX = CHILD_PROPERTY_START_INDEX, ///< name "cellIndex", The top-left cell this child occupies, if not set, the first available cell is used, type VECTOR2 @SINCE_1_1.36 + ROW_SPAN, ///< name "rowSpan", The number of rows this child occupies, if not set, default value is 1, type FLOAT @SINCE_1_1.36 + COLUMN_SPAN, ///< name "columnSpan", The number of columns this child occupies, if not set, default value is 1, type FLOAT @SINCE_1_1.36 + CELL_HORIZONTAL_ALIGNMENT, ///< name "cellHorizontalAlignment", The horizontal alignment of this child inside the cells, if not set, default value is 'left', type STRING @SINCE_1_1.36 + CELL_VERTICAL_ALIGNMENT ///< name "cellVerticalAlignment", The vertical alignment of this child inside the cells, if not set, default value is 'top', type STRING @SINCE_1_1.36 + }; + }; + + /** * @brief Describes how the size of a row / column been set * @SINCE_1_0.0 */ diff --git a/docs/content/programming-guide/properties.h b/docs/content/programming-guide/properties.h index 43d6419..2d8d7e6 100644 --- a/docs/content/programming-guide/properties.h +++ b/docs/content/programming-guide/properties.h @@ -182,7 +182,8 @@ shows the index range of the different properties in place. |:----------------------|:--------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------:| | Default | Properties defined within DALi Core, e.g. Dali::Actor, Dali::ShaderEffect default properties etc. | \link Dali::DEFAULT_OBJECT_PROPERTY_START_INDEX DEFAULT_OBJECT_PROPERTY_START_INDEX\endlink | \link Dali::DEFAULT_PROPERTY_MAX_COUNT DEFAULT_PROPERTY_MAX_COUNT\endlink (9999999) | | Registered | Properties registered using Dali::PropertyRegistration | \link Dali::PROPERTY_REGISTRATION_START_INDEX PROPERTY_REGISTRATION_START_INDEX\endlink (10000000) | \link Dali::PROPERTY_REGISTRATION_MAX_INDEX PROPERTY_REGISTRATION_MAX_INDEX\endlink (19999999) | -| Registered Animatable | Animatable properties registered using Dali::PropertyRegistration | \link Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX\endlink (20000000) | \link Dali::ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX\endlink (29999999) | +| Registered Animatable | Animatable properties registered using Dali::AnimatablePropertyRegistration | \link Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX\endlink (20000000) | \link Dali::ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX\endlink (29999999) | +| Registered Child | Child properties (which parent supports in its children) registered using Dali::ChildPropertyRegistration | \link Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX\endlink (20000000) | \link Dali::CHILD_PROPERTY_REGISTRATION_MAX_INDEX CHILD_PROPERTY_REGISTRATION_MAX_INDEX\endlink (49999999) | | Control | Property range reserved by Dali::Toolkit::Control | \link Dali::Toolkit::Control::CONTROL_PROPERTY_START_INDEX CONTROL_PROPERTY_START_INDEX\endlink (10000000) | \link Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX CONTROL_PROPERTY_END_INDEX\endlink (10001000) | | Derived Control | Property range for control deriving directly from Dali::Toolkit::Control | 10001001 | \link Dali::PROPERTY_REGISTRATION_MAX_INDEX PROPERTY_REGISTRATION_MAX_INDEX\endlink (19999999) | | Custom | Custom properties added to instance using Dali::Handle::RegisterProperty | \link Dali::PROPERTY_CUSTOM_START_INDEX PROPERTY_CUSTOM_START_INDEX\endlink (50000000) | Onwards... | -- 2.7.4