Add child property registration for TableView 96/70796/2
authorRichard Huang <r.huang@samsung.com>
Fri, 20 May 2016 14:35:19 +0000 (15:35 +0100)
committerRichard Huang <r.huang@samsung.com>
Fri, 20 May 2016 15:49:32 +0000 (16:49 +0100)
Change-Id: Ib043392dea1ea27cc65042d82927f6f8b909afa0

automated-tests/src/dali-toolkit/utc-Dali-TableView.cpp
dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp
dali-toolkit/internal/controls/table-view/table-view-impl.cpp
dali-toolkit/public-api/controls/table-view/table-view.h
docs/content/programming-guide/properties.h

index 708fa3c..7beeb96 100644 (file)
@@ -686,10 +686,10 @@ int UtcDaliTableViewSetGetProperty(void)
   END_TEST;
 }
 
   END_TEST;
 }
 
-int UtcDaliTableViewCustomProperties(void)
+int UtcDaliTableViewChildProperties(void)
 {
   ToolkitTestApplication application;
 {
   ToolkitTestApplication application;
-  tet_infoline("UtcDaliTableViewCustomProperties");
+  tet_infoline("UtcDaliTableViewChildProperties");
 
   // Create a 10x10 table-view
   TableView tableView = TableView::New(10,10);
 
   // 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();
 
   // 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);
   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;
   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; i<rowSpan; i++ )
   tableView.Add( child2 );
   // Check for actors at actual positions.
   for( int i=0; i<rowSpan; i++ )
@@ -725,8 +725,8 @@ int UtcDaliTableViewCustomProperties(void)
   // Create a third child actor with the cell alignment properties
   Actor child3 = Actor::New();
   child3.SetSize( 5.f,5.f );
   // Create a third child actor with the cell alignment properties
   Actor child3 = Actor::New();
   child3.SetSize( 5.f,5.f );
-  child3.RegisterProperty( "cellHorizontalAlignment",   "center", Property::READ_WRITE );
-  child3.RegisterProperty( "cellVerticalAlignment",   "bottom", Property::READ_WRITE );
+  child3.SetProperty( TableView::ChildProperty::CELL_HORIZONTAL_ALIGNMENT, "center" );
+  child3.SetProperty( TableView::ChildProperty::CELL_VERTICAL_ALIGNMENT,   "bottom" );
   tableView.Add( child3 );
 
   // store the actor in the first available cell
   tableView.Add( child3 );
 
   // store the actor in the first available cell
index 88724e0..6a52fb1 100644 (file)
@@ -600,29 +600,38 @@ void FlexContainer::ComputeLayout()
       // These properties should be dynamically registered to the child which
       // would be added to FlexContainer.
 
       // These properties should be dynamically registered to the child which
       // would be added to FlexContainer.
 
-      childNode->style.flex = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::FLEX ).Get<float>();
-
-      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<Toolkit::FlexContainer::Alignment>( alignSelfPropertyValue.Get< int >() );
+        childNode->style.flex = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::FLEX ).Get<float>();
       }
       }
-      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<std::string>();
-        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<Toolkit::FlexContainer::Alignment>( alignSelfPropertyValue.Get< int >() );
+        }
+        else if( alignSelfPropertyValue.GetType() == Property::STRING )
+        {
+          std::string value = alignSelfPropertyValue.Get<std::string>();
+          Scripting::GetEnumeration< Toolkit::FlexContainer::Alignment >( value.c_str(),
+                                                                          ALIGN_SELF_STRING_TABLE,
+                                                                          ALIGN_SELF_STRING_TABLE_COUNT,
+                                                                          alignSelf );
+        }
       }
       childNode->style.align_self = static_cast<css_align_t>(alignSelf);
 
       }
       childNode->style.align_self = static_cast<css_align_t>(alignSelf);
 
-      Vector4 flexMargin = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::FLEX_MARGIN ).Get<Vector4>();
-      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<Vector4>();
+        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
     }
 
     // Calculate the layout
index bac0402..94ba402 100644 (file)
@@ -31,20 +31,6 @@ using namespace Dali;
 
 namespace
 {
 
 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
  *
 /**
  * @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_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()
 
 
 DALI_TYPE_REGISTRATION_END()
 
@@ -978,41 +969,42 @@ void TableView::OnChildAdd( Actor& child )
     return;
   }
 
     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;
   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 >();
+    std::string value = child.GetProperty( Toolkit::TableView::ChildProperty::CELL_HORIZONTAL_ALIGNMENT ).Get<std::string >();
     Scripting::GetEnumeration< HorizontalAlignment::Type >( value.c_str(),
                                                             HORIZONTAL_ALIGNMENT_STRING_TABLE,
                                                             HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
                                                             horizontalAlignment );
   }
     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 >();
+    std::string value = child.GetProperty( Toolkit::TableView::ChildProperty::CELL_VERTICAL_ALIGNMENT ).Get<std::string >();
     Scripting::GetEnumeration< VerticalAlignment::Type >( value.c_str(),
                                                           VERTICAL_ALIGNMENT_STRING_TABLE,
                                                           VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
                                                           verticalAlignment );
   }
 
     Scripting::GetEnumeration< VerticalAlignment::Type >( value.c_str(),
                                                           VERTICAL_ALIGNMENT_STRING_TABLE,
                                                           VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
                                                           verticalAlignment );
   }
 
-
   Toolkit::TableView::CellPosition cellPosition;
   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<unsigned int>( child.GetProperty( child.GetPropertyIndex(ROW_SPAN_PROPERTY_NAME) ).Get<float>() );
+    cellPosition.rowSpan = static_cast<unsigned int>( child.GetProperty( Toolkit::TableView::ChildProperty::ROW_SPAN ).Get<float>() );
   }
 
   }
 
-  if( child.GetPropertyIndex(COLUMN_SPAN_PROPERTY_NAME) != Property::INVALID_INDEX )
+  if( child.GetPropertyType( Toolkit::TableView::ChildProperty::COLUMN_SPAN ) != Property::NONE )
   {
   {
-    cellPosition.columnSpan = static_cast<unsigned int>( child.GetProperty( child.GetPropertyIndex(COLUMN_SPAN_PROPERTY_NAME) ).Get<float>() );
+    cellPosition.columnSpan = static_cast<unsigned int>( child.GetProperty( Toolkit::TableView::ChildProperty::COLUMN_SPAN ).Get<float>() );
   }
 
   }
 
-  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 >();
+    Vector2 indices = child.GetProperty( Toolkit::TableView::ChildProperty::CELL_INDEX ).Get<Vector2 >();
     cellPosition.rowIndex = static_cast<unsigned int>( indices.x );
     cellPosition.columnIndex = static_cast<unsigned int>( indices.y );
 
     cellPosition.rowIndex = static_cast<unsigned int>( indices.x );
     cellPosition.columnIndex = static_cast<unsigned int>( indices.y );
 
index 94257ee..e3f17b7 100644 (file)
@@ -94,7 +94,10 @@ public:
   enum PropertyRange
   {
     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
   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
    */
    * @brief Describes how the size of a row / column been set
    * @SINCE_1_0.0
    */
index 43d6419..2d8d7e6 100644 (file)
@@ -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)                                     |
 |:----------------------|:--------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------:|
 | 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...                                                                                                                         |
 | 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...                                                                                                                         |