From e2342ebf88a25b6a8e951070604130262ef11082 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Wed, 18 May 2016 13:22:02 +0100 Subject: [PATCH] Support for child properties registration in FlexContainer Change-Id: I912146fe84748a789d4d02c44360dc875cc9a113 --- .../controls/flex-container/flex-container.h | 29 ++++++-- .../flex-container/flex-container-impl.cpp | 79 +++++++++------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/dali-toolkit/devel-api/controls/flex-container/flex-container.h b/dali-toolkit/devel-api/controls/flex-container/flex-container.h index 154eedd..fcf8f58 100644 --- a/dali-toolkit/devel-api/controls/flex-container/flex-container.h +++ b/dali-toolkit/devel-api/controls/flex-container/flex-container.h @@ -92,10 +92,10 @@ class FlexContainer; * "name":"icon", * "type":"ImageView", * "image":"image.png", - * "customProperties": { - * "flex":1, // property to make the item to receive the specified proportion of the free space in the container. If all items in the container use this pattern, their sizes will be proportional to the specified flex factor. - * "alignSelf":"flexStart", // property to specify how the item will align along the cross axis, if set, this overides the default alignment for all items in the container - * "flexMargin":[10, 10, 10, 10] // property to specify the space around the item, if not set, default value is [0, 0, 0, 0] + * "properties": { + * "flex":1, // property to make the item to receive the specified proportion of the free space in the container. + * "alignSelf":"flexStart", // property to specify how the item will align along the cross axis. + * "flexMargin":[10, 10, 10, 10] // property to specify the space around the item. * } * @endcode */ @@ -171,7 +171,10 @@ public: enum PropertyRange { PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, - PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices + PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ///< Reserve property indices + + CHILD_PROPERTY_START_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX, + CHILD_PROPERTY_END_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX + 1000 ///< Reserve child property indices }; /** @@ -191,7 +194,21 @@ public: }; /** - * Create a FlexContainer handle; this can be initialised with FlexContainer::New() + * @brief An enumeration of child properties belonging to the FlexContainer class. + */ + struct ChildProperty + { + enum + { + // Event side child properties + FLEX = CHILD_PROPERTY_START_INDEX, ///< name "flex", The proportion of the free space in the container the flex item will receive. If all items in the container set this property, their sizes will be proportional to the specified flex factor, type FLOAT + ALIGN_SELF, ///< name "alignSelf", The alignment of the flex item along the cross axis, which, if set, overides the default alignment for all items in the container, @see FlexContainer::Alignment, type INTEGER + FLEX_MARGIN ///< name "flexMargin", The space around the flex item, type VECTOR4 + }; + }; + + /** + * @brief Create a FlexContainer handle; this can be initialised with FlexContainer::New() * Calling member functions with an uninitialised handle is not allowed. */ FlexContainer(); diff --git a/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp b/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp index 00e1271..88724e0 100644 --- a/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp +++ b/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp @@ -31,18 +31,6 @@ using namespace Dali; namespace { -/* - * Custom properties for how to lay out the actor. - * - * When an actor is add to the flex container, the following custom properties of the actor - * are checked to decide how to lay out the actor inside the flex container. - * - * These non-animatable properties should be registered to the child which would be added - * to the flex container, and once added their values can not be changed. - */ -const char * const FLEX_PROPERTY_NAME("flex"); -const char * const ALIGN_SELF_PROPERTY_NAME("alignSelf"); -const char * const FLEX_MARGIN_PROPERTY_NAME("flexMargin"); #if defined(DEBUG_ENABLED) // debugging support, very useful when new features are added or bugs are hunted down @@ -93,12 +81,15 @@ BaseHandle Create() // Setup properties, signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN( Toolkit::FlexContainer, Toolkit::Control, Create ); -DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "contentDirection", INTEGER, CONTENT_DIRECTION ) -DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "flexDirection", INTEGER, FLEX_DIRECTION ) -DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "flexWrap", INTEGER, FLEX_WRAP ) -DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "justifyContent", INTEGER, JUSTIFY_CONTENT ) -DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "alignItems", INTEGER, ALIGN_ITEMS ) -DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "alignContent", INTEGER, ALIGN_CONTENT ) +DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "contentDirection", INTEGER, CONTENT_DIRECTION ) +DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "flexDirection", INTEGER, FLEX_DIRECTION ) +DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "flexWrap", INTEGER, FLEX_WRAP ) +DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "justifyContent", INTEGER, JUSTIFY_CONTENT ) +DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "alignItems", INTEGER, ALIGN_ITEMS ) +DALI_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "alignContent", INTEGER, ALIGN_CONTENT ) +DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "flex", FLOAT, FLEX ) +DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "alignSelf", INTEGER, ALIGN_SELF ) +DALI_CHILD_PROPERTY_REGISTRATION( Toolkit, FlexContainer, "flexMargin", VECTOR4, FLEX_MARGIN ) DALI_TYPE_REGISTRATION_END() @@ -605,41 +596,33 @@ void FlexContainer::ComputeLayout() childNode->style.maxDimensions[CSS_WIDTH] = childActor.GetMaximumSize().x; childNode->style.maxDimensions[CSS_HEIGHT] = childActor.GetMaximumSize().y; - // Test custom properties on the child - if( childActor.GetPropertyIndex( FLEX_PROPERTY_NAME ) != Property::INVALID_INDEX ) - { - childNode->style.flex = childActor.GetProperty( childActor.GetPropertyIndex(FLEX_PROPERTY_NAME) ).Get(); - } + // Check child properties on the child for how to layout it. + // These properties should be dynamically registered to the child which + // would be added to FlexContainer. - Property::Index alignSelfPropertyIndex = childActor.GetPropertyIndex( ALIGN_SELF_PROPERTY_NAME ); - if( alignSelfPropertyIndex != Property::INVALID_INDEX ) - { - Property::Value alignSelfPropertyValue = childActor.GetProperty( alignSelfPropertyIndex ); + childNode->style.flex = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::FLEX ).Get(); - Toolkit::FlexContainer::Alignment alignSelf( Toolkit::FlexContainer::ALIGN_AUTO ); - 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); + Toolkit::FlexContainer::Alignment alignSelf( Toolkit::FlexContainer::ALIGN_AUTO ); + Property::Value alignSelfPropertyValue = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::ALIGN_SELF ); + if( alignSelfPropertyValue.GetType() == Property::INTEGER ) + { + alignSelf = static_cast( alignSelfPropertyValue.Get< int >() ); } - - if( childActor.GetPropertyIndex( FLEX_MARGIN_PROPERTY_NAME ) != Property::INVALID_INDEX ) + else if( alignSelfPropertyValue.GetType() == Property::STRING ) { - Vector4 flexMargin = childActor.GetProperty( childActor.GetPropertyIndex(FLEX_MARGIN_PROPERTY_NAME) ).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; + 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; } // Calculate the layout -- 2.7.4