X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fflex-container%2Fflex-container-impl.cpp;h=4a3b065e3e76eacf38955d2ae301db9c145f813f;hp=675709b914313ba9948896f1ecc91d66ea2ede9c;hb=1895d50b1a4867ad8e3be4bbaf13768465efe6bc;hpb=41278d3fb755de3cb89edf6d80603b18562b4e01 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 675709b..4a3b065 100644 --- a/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp +++ b/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,59 +19,57 @@ #include // EXTERNAL INCLUDES -#include +#include +#include +#include #include -#include #include -#include +#include #include -#include +#include + +#include using namespace Dali; namespace { - #if defined(DEBUG_ENABLED) // debugging support, very useful when new features are added or bugs are hunted down // currently not called from code so compiler will optimize these away, kept here for future debugging #define FLEX_CONTAINER_TAG "DALI Toolkit::FlexContainer " -#define FC_LOG(fmt, args...) Debug::LogMessage(Debug::DebugInfo, FLEX_CONTAINER_TAG fmt, ## args) -//#define FLEX_CONTAINER_DEBUG 1 +#define FC_LOG(fmt, args, ...) Debug::LogMessageWithFunctionLine(Debug::DebugInfo, FLEX_CONTAINER_TAG fmt, ##args) +// #define FLEX_CONTAINER_DEBUG 1 #if defined(FLEX_CONTAINER_DEBUG) -void PrintNode( Toolkit::Internal::FlexContainer::FlexItemNodeContainer itemNodes ) +void PrintNodes(Toolkit::Internal::FlexContainer::FlexItemNodeContainer itemNodes) { // Print the style property and layout of all the children - for( unsigned int i = 0; i < itemNodes.size(); ++i ) + for(unsigned int i = 0; i < itemNodes.size(); ++i) { - FC_LOG( "Item %d style: \n", i ); - print_css_node( itemNodes[i].node, (css_print_options_t)( CSS_PRINT_STYLE | CSS_PRINT_CHILDREN ) ); - FC_LOG( "Item %d layout: \n", i ); - print_css_node( itemNodes[i].node, (css_print_options_t)( CSS_PRINT_LAYOUT | CSS_PRINT_CHILDREN ) ); - FC_LOG( "\n" ); + FC_LOG("Item %d style: \n", i); + YGNodePrint(itemNodes[i].node, (YGPrintOptions)(YGPrintOptionsStyle | YGPrintOptionsChildren)); + FC_LOG("\n"); + FC_LOG("Item %d layout: \n", i); + YGNodePrint(itemNodes[i].node, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren)); + FC_LOG("\n"); } } #endif // defined(FLEX_CONTAINER_DEBUG) #endif // defined(DEBUG_ENABLED) - } // namespace namespace Dali { - namespace Toolkit { - namespace Internal { - namespace { - // Type registration BaseHandle Create() { @@ -79,112 +77,85 @@ 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_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_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_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() const Scripting::StringEnum ALIGN_SELF_STRING_TABLE[] = -{ - { "auto", Toolkit::FlexContainer::ALIGN_AUTO }, - { "flexStart", Toolkit::FlexContainer::ALIGN_FLEX_START }, - { "center", Toolkit::FlexContainer::ALIGN_CENTER }, - { "flexEnd", Toolkit::FlexContainer::ALIGN_FLEX_END }, - { "stretch", Toolkit::FlexContainer::ALIGN_STRETCH } -}; -const unsigned int ALIGN_SELF_STRING_TABLE_COUNT = sizeof( ALIGN_SELF_STRING_TABLE ) / sizeof( ALIGN_SELF_STRING_TABLE[0] ); + { + {"auto", Toolkit::FlexContainer::ALIGN_AUTO}, + {"flexStart", Toolkit::FlexContainer::ALIGN_FLEX_START}, + {"center", Toolkit::FlexContainer::ALIGN_CENTER}, + {"flexEnd", Toolkit::FlexContainer::ALIGN_FLEX_END}, + {"stretch", Toolkit::FlexContainer::ALIGN_STRETCH}}; +const unsigned int ALIGN_SELF_STRING_TABLE_COUNT = sizeof(ALIGN_SELF_STRING_TABLE) / sizeof(ALIGN_SELF_STRING_TABLE[0]); const Scripting::StringEnum CONTENT_DIRECTION_STRING_TABLE[] = -{ - { "inherit", Toolkit::FlexContainer::INHERIT }, - { "LTR", Toolkit::FlexContainer::LTR }, - { "RTL", Toolkit::FlexContainer::RTL } -}; -const unsigned int CONTENT_DIRECTION_STRING_TABLE_COUNT = sizeof( CONTENT_DIRECTION_STRING_TABLE ) / sizeof( CONTENT_DIRECTION_STRING_TABLE[0] ); + { + {"inherit", Toolkit::FlexContainer::INHERIT}, + {"LTR", Toolkit::FlexContainer::LTR}, + {"RTL", Toolkit::FlexContainer::RTL}}; +const unsigned int CONTENT_DIRECTION_STRING_TABLE_COUNT = sizeof(CONTENT_DIRECTION_STRING_TABLE) / sizeof(CONTENT_DIRECTION_STRING_TABLE[0]); const Scripting::StringEnum FLEX_DIRECTION_STRING_TABLE[] = -{ - { "column", Toolkit::FlexContainer::COLUMN }, - { "columnReverse", Toolkit::FlexContainer::COLUMN_REVERSE }, - { "row", Toolkit::FlexContainer::ROW }, - { "rowReverse", Toolkit::FlexContainer::ROW_REVERSE } -}; -const unsigned int FLEX_DIRECTION_STRING_TABLE_COUNT = sizeof( FLEX_DIRECTION_STRING_TABLE ) / sizeof( FLEX_DIRECTION_STRING_TABLE[0] ); + { + {"column", Toolkit::FlexContainer::COLUMN}, + {"columnReverse", Toolkit::FlexContainer::COLUMN_REVERSE}, + {"row", Toolkit::FlexContainer::ROW}, + {"rowReverse", Toolkit::FlexContainer::ROW_REVERSE}}; +const unsigned int FLEX_DIRECTION_STRING_TABLE_COUNT = sizeof(FLEX_DIRECTION_STRING_TABLE) / sizeof(FLEX_DIRECTION_STRING_TABLE[0]); const Scripting::StringEnum FLEX_WRAP_STRING_TABLE[] = -{ - { "noWrap", Toolkit::FlexContainer::NO_WRAP }, - { "wrap", Toolkit::FlexContainer::WRAP } -}; -const unsigned int FLEX_WRAP_STRING_TABLE_COUNT = sizeof( FLEX_WRAP_STRING_TABLE ) / sizeof( FLEX_WRAP_STRING_TABLE[0] ); + { + {"noWrap", Toolkit::FlexContainer::NO_WRAP}, + {"wrap", Toolkit::FlexContainer::WRAP}}; +const unsigned int FLEX_WRAP_STRING_TABLE_COUNT = sizeof(FLEX_WRAP_STRING_TABLE) / sizeof(FLEX_WRAP_STRING_TABLE[0]); const Scripting::StringEnum JUSTIFY_CONTENT_STRING_TABLE[] = -{ - { "flexStart", Toolkit::FlexContainer::JUSTIFY_FLEX_START }, - { "center", Toolkit::FlexContainer::JUSTIFY_CENTER }, - { "flexEnd", Toolkit::FlexContainer::JUSTIFY_FLEX_END }, - { "spaceBetween", Toolkit::FlexContainer::JUSTIFY_SPACE_BETWEEN }, - { "spaceAround", Toolkit::FlexContainer::JUSTIFY_SPACE_AROUND } -}; -const unsigned int JUSTIFY_CONTENT_STRING_TABLE_COUNT = sizeof( JUSTIFY_CONTENT_STRING_TABLE ) / sizeof( JUSTIFY_CONTENT_STRING_TABLE[0] ); + { + {"flexStart", Toolkit::FlexContainer::JUSTIFY_FLEX_START}, + {"center", Toolkit::FlexContainer::JUSTIFY_CENTER}, + {"flexEnd", Toolkit::FlexContainer::JUSTIFY_FLEX_END}, + {"spaceBetween", Toolkit::FlexContainer::JUSTIFY_SPACE_BETWEEN}, + {"spaceAround", Toolkit::FlexContainer::JUSTIFY_SPACE_AROUND}, + {"spaceEvenly", Toolkit::FlexContainer::JUSTIFY_SPACE_EVENLY}}; +const unsigned int JUSTIFY_CONTENT_STRING_TABLE_COUNT = sizeof(JUSTIFY_CONTENT_STRING_TABLE) / sizeof(JUSTIFY_CONTENT_STRING_TABLE[0]); const Scripting::StringEnum ALIGN_ITEMS_STRING_TABLE[] = -{ - { "flexStart", Toolkit::FlexContainer::ALIGN_FLEX_START }, - { "center", Toolkit::FlexContainer::ALIGN_CENTER }, - { "flexEnd", Toolkit::FlexContainer::ALIGN_FLEX_END }, - { "stretch", Toolkit::FlexContainer::ALIGN_STRETCH } -}; -const unsigned int ALIGN_ITEMS_STRING_TABLE_COUNT = sizeof( ALIGN_ITEMS_STRING_TABLE ) / sizeof( ALIGN_ITEMS_STRING_TABLE[0] ); + { + {"flexStart", Toolkit::FlexContainer::ALIGN_FLEX_START}, + {"center", Toolkit::FlexContainer::ALIGN_CENTER}, + {"flexEnd", Toolkit::FlexContainer::ALIGN_FLEX_END}, + {"stretch", Toolkit::FlexContainer::ALIGN_STRETCH}}; +const unsigned int ALIGN_ITEMS_STRING_TABLE_COUNT = sizeof(ALIGN_ITEMS_STRING_TABLE) / sizeof(ALIGN_ITEMS_STRING_TABLE[0]); const Scripting::StringEnum ALIGN_CONTENT_STRING_TABLE[] = -{ - { "flexStart", Toolkit::FlexContainer::ALIGN_FLEX_START }, - { "center", Toolkit::FlexContainer::ALIGN_CENTER }, - { "flexEnd", Toolkit::FlexContainer::ALIGN_FLEX_END }, - { "stretch", Toolkit::FlexContainer::ALIGN_STRETCH } -}; -const unsigned int ALIGN_CONTENT_STRING_TABLE_COUNT = sizeof( ALIGN_CONTENT_STRING_TABLE ) / sizeof( ALIGN_CONTENT_STRING_TABLE[0] ); - -/** - * The function used by the layout algorithm to be get the style properties - * and layout information of the child at the given index. - */ -css_node_t* GetChildNodeAtIndex( void *childrenNodes, int i ) -{ - FlexContainer::FlexItemNodeContainer childrenNodeContainer = *( static_cast( childrenNodes ) ); - return childrenNodeContainer[i].node; -} - -/** - * The function used by the layout algorithm to check whether the node is dirty - * for relayout. - */ -bool IsNodeDirty( void *itemNodes ) -{ - // We only calculate the layout when the child is added or removed, or when - // style properties are changed. So should always return true here. - return true; -} + { + {"flexStart", Toolkit::FlexContainer::ALIGN_FLEX_START}, + {"center", Toolkit::FlexContainer::ALIGN_CENTER}, + {"flexEnd", Toolkit::FlexContainer::ALIGN_FLEX_END}, + {"stretch", Toolkit::FlexContainer::ALIGN_STRETCH}}; +const unsigned int ALIGN_CONTENT_STRING_TABLE_COUNT = sizeof(ALIGN_CONTENT_STRING_TABLE) / sizeof(ALIGN_CONTENT_STRING_TABLE[0]); } // Unnamed namespace Toolkit::FlexContainer FlexContainer::New() { // Create the implementation, temporarily owned by this handle on stack - IntrusivePtr< FlexContainer > impl = new FlexContainer(); + IntrusivePtr impl = new FlexContainer(); // Pass ownership to CustomActor handle - Toolkit::FlexContainer handle( *impl ); + Toolkit::FlexContainer handle(*impl); // Second-phase init of the implementation // This can only be done after the CustomActor connection has been made... @@ -195,22 +166,52 @@ Toolkit::FlexContainer FlexContainer::New() FlexContainer::~FlexContainer() { - free_css_node( mRootNode.node ); + YGNodeFree(mRootNode.node); - for( unsigned int i = 0; i < mChildrenNodes.size(); i++ ) + for(unsigned int i = 0; i < mChildrenNodes.size(); i++) { - free_css_node( mChildrenNodes[i].node ); + YGNodeFree(mChildrenNodes[i].node); } mChildrenNodes.clear(); } -void FlexContainer::SetContentDirection( Toolkit::FlexContainer::ContentDirection contentDirection ) +void FlexContainer::SetContentDirection(Toolkit::FlexContainer::ContentDirection contentDirection) { - if( mContentDirection != contentDirection ) + if(mContentDirection != contentDirection) { - mContentDirection = contentDirection; - mRootNode.node->style.direction = static_cast( mContentDirection ); + Dali::CustomActor ownerActor(GetOwner()); + + if(Toolkit::FlexContainer::INHERIT != contentDirection) + { + mContentDirection = contentDirection; + + ownerActor.SetProperty(Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION, false); + + if(Toolkit::FlexContainer::LTR == contentDirection) + { + ownerActor.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT); + } + else + { + ownerActor.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT); + } + } + else + { + ownerActor.SetProperty(Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION, true); + + Dali::LayoutDirection::Type layoutDirection = static_cast(ownerActor.GetParent().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); + + if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection) + { + mContentDirection = Toolkit::FlexContainer::RTL; + } + else + { + mContentDirection = Toolkit::FlexContainer::LTR; + } + } RelayoutRequest(); } @@ -221,12 +222,12 @@ Toolkit::FlexContainer::ContentDirection FlexContainer::GetContentDirection() return mContentDirection; } -void FlexContainer::SetFlexDirection( Toolkit::FlexContainer::FlexDirection flexDirection ) +void FlexContainer::SetFlexDirection(Toolkit::FlexContainer::FlexDirection flexDirection) { - if( mFlexDirection != flexDirection ) + if(mFlexDirection != flexDirection) { mFlexDirection = flexDirection; - mRootNode.node->style.flex_direction = static_cast( mFlexDirection ); + YGNodeStyleSetFlexDirection(mRootNode.node, static_cast(flexDirection)); RelayoutRequest(); } @@ -237,12 +238,12 @@ Toolkit::FlexContainer::FlexDirection FlexContainer::GetFlexDirection() return mFlexDirection; } -void FlexContainer::SetFlexWrap( Toolkit::FlexContainer::WrapType flexWrap ) +void FlexContainer::SetFlexWrap(Toolkit::FlexContainer::WrapType flexWrap) { - if( mFlexWrap != flexWrap ) + if(mFlexWrap != flexWrap) { mFlexWrap = flexWrap; - mRootNode.node->style.flex_wrap = static_cast( mFlexWrap ); + YGNodeStyleSetFlexWrap(mRootNode.node, static_cast(flexWrap)); RelayoutRequest(); } @@ -253,12 +254,12 @@ Toolkit::FlexContainer::WrapType FlexContainer::GetFlexWrap() return mFlexWrap; } -void FlexContainer::SetJustifyContent( Toolkit::FlexContainer::Justification justifyContent ) +void FlexContainer::SetJustifyContent(Toolkit::FlexContainer::Justification justifyContent) { - if( mJustifyContent != justifyContent ) + if(mJustifyContent != justifyContent) { mJustifyContent = justifyContent; - mRootNode.node->style.justify_content = static_cast( mJustifyContent ); + YGNodeStyleSetJustifyContent(mRootNode.node, static_cast(justifyContent)); RelayoutRequest(); } @@ -269,12 +270,12 @@ Toolkit::FlexContainer::Justification FlexContainer::GetJustifyContent() return mJustifyContent; } -void FlexContainer::SetAlignItems( Toolkit::FlexContainer::Alignment alignItems ) +void FlexContainer::SetAlignItems(Toolkit::FlexContainer::Alignment alignItems) { - if( mAlignItems != alignItems ) + if(mAlignItems != alignItems) { mAlignItems = alignItems; - mRootNode.node->style.align_items = static_cast( mAlignItems ); + YGNodeStyleSetAlignItems(mRootNode.node, static_cast(alignItems)); RelayoutRequest(); } @@ -285,12 +286,12 @@ Toolkit::FlexContainer::Alignment FlexContainer::GetAlignItems() return mAlignItems; } -void FlexContainer::SetAlignContent( Toolkit::FlexContainer::Alignment alignContent ) +void FlexContainer::SetAlignContent(Toolkit::FlexContainer::Alignment alignContent) { - if( mAlignContent != alignContent ) + if(mAlignContent != alignContent) { mAlignContent = alignContent; - mRootNode.node->style.align_content = static_cast( mAlignContent ); + YGNodeStyleSetAlignContent(mRootNode.node, static_cast(alignContent)); RelayoutRequest(); } @@ -301,27 +302,27 @@ Toolkit::FlexContainer::Alignment FlexContainer::GetAlignContent() return mAlignContent; } -void FlexContainer::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +void FlexContainer::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value) { - Toolkit::FlexContainer flexContainer = Toolkit::FlexContainer::DownCast( Dali::BaseHandle( object ) ); + Toolkit::FlexContainer flexContainer = Toolkit::FlexContainer::DownCast(Dali::BaseHandle(object)); - if( flexContainer ) + if(flexContainer) { - FlexContainer& flexContainerImpl( GetImpl( flexContainer ) ); - switch( index ) + FlexContainer& flexContainerImpl(GetImpl(flexContainer)); + switch(index) { case Toolkit::FlexContainer::Property::CONTENT_DIRECTION: { - Toolkit::FlexContainer::ContentDirection contentDirection( Toolkit::FlexContainer::INHERIT ); + Toolkit::FlexContainer::ContentDirection contentDirection(Toolkit::FlexContainer::INHERIT); - if( value.GetType() == Property::INTEGER ) + if(value.GetType() == Property::INTEGER) { - flexContainerImpl.SetContentDirection( static_cast( value.Get< int >() ) ); + flexContainerImpl.SetContentDirection(static_cast(value.Get())); } - else if( Scripting::GetEnumeration< Toolkit::FlexContainer::ContentDirection >( value.Get< std::string >().c_str(), - CONTENT_DIRECTION_STRING_TABLE, - CONTENT_DIRECTION_STRING_TABLE_COUNT, - contentDirection ) ) + else if(Scripting::GetEnumeration(value.Get().c_str(), + CONTENT_DIRECTION_STRING_TABLE, + CONTENT_DIRECTION_STRING_TABLE_COUNT, + contentDirection)) { flexContainerImpl.SetContentDirection(contentDirection); } @@ -329,16 +330,16 @@ void FlexContainer::SetProperty( BaseObject* object, Property::Index index, cons } case Toolkit::FlexContainer::Property::FLEX_DIRECTION: { - Toolkit::FlexContainer::FlexDirection flexDirection( Toolkit::FlexContainer::COLUMN ); + Toolkit::FlexContainer::FlexDirection flexDirection(Toolkit::FlexContainer::COLUMN); - if( value.GetType() == Property::INTEGER ) + if(value.GetType() == Property::INTEGER) { - flexContainerImpl.SetFlexDirection( static_cast( value.Get< int >() ) ); + flexContainerImpl.SetFlexDirection(static_cast(value.Get())); } - else if( Scripting::GetEnumeration< Toolkit::FlexContainer::FlexDirection >( value.Get< std::string >().c_str(), - FLEX_DIRECTION_STRING_TABLE, - FLEX_DIRECTION_STRING_TABLE_COUNT, - flexDirection ) ) + else if(Scripting::GetEnumeration(value.Get().c_str(), + FLEX_DIRECTION_STRING_TABLE, + FLEX_DIRECTION_STRING_TABLE_COUNT, + flexDirection)) { flexContainerImpl.SetFlexDirection(flexDirection); } @@ -346,16 +347,16 @@ void FlexContainer::SetProperty( BaseObject* object, Property::Index index, cons } case Toolkit::FlexContainer::Property::FLEX_WRAP: { - Toolkit::FlexContainer::WrapType flexWrap( Toolkit::FlexContainer::NO_WRAP ); + Toolkit::FlexContainer::WrapType flexWrap(Toolkit::FlexContainer::NO_WRAP); - if( value.GetType() == Property::INTEGER ) + if(value.GetType() == Property::INTEGER) { - flexContainerImpl.SetFlexWrap( static_cast( value.Get< int >() ) ); + flexContainerImpl.SetFlexWrap(static_cast(value.Get())); } - else if( Scripting::GetEnumeration< Toolkit::FlexContainer::WrapType >( value.Get< std::string >().c_str(), - FLEX_WRAP_STRING_TABLE, - FLEX_WRAP_STRING_TABLE_COUNT, - flexWrap ) ) + else if(Scripting::GetEnumeration(value.Get().c_str(), + FLEX_WRAP_STRING_TABLE, + FLEX_WRAP_STRING_TABLE_COUNT, + flexWrap)) { flexContainerImpl.SetFlexWrap(flexWrap); } @@ -363,16 +364,16 @@ void FlexContainer::SetProperty( BaseObject* object, Property::Index index, cons } case Toolkit::FlexContainer::Property::JUSTIFY_CONTENT: { - Toolkit::FlexContainer::Justification justifyContent( Toolkit::FlexContainer::JUSTIFY_FLEX_START ); + Toolkit::FlexContainer::Justification justifyContent(Toolkit::FlexContainer::JUSTIFY_FLEX_START); - if( value.GetType() == Property::INTEGER ) + if(value.GetType() == Property::INTEGER) { - flexContainerImpl.SetJustifyContent( static_cast( value.Get< int >() ) ); + flexContainerImpl.SetJustifyContent(static_cast(value.Get())); } - else if( Scripting::GetEnumeration< Toolkit::FlexContainer::Justification >( value.Get< std::string >().c_str(), - JUSTIFY_CONTENT_STRING_TABLE, - JUSTIFY_CONTENT_STRING_TABLE_COUNT, - justifyContent ) ) + else if(Scripting::GetEnumeration(value.Get().c_str(), + JUSTIFY_CONTENT_STRING_TABLE, + JUSTIFY_CONTENT_STRING_TABLE_COUNT, + justifyContent)) { flexContainerImpl.SetJustifyContent(justifyContent); } @@ -380,16 +381,16 @@ void FlexContainer::SetProperty( BaseObject* object, Property::Index index, cons } case Toolkit::FlexContainer::Property::ALIGN_ITEMS: { - Toolkit::FlexContainer::Alignment alignItems( Toolkit::FlexContainer::ALIGN_STRETCH ); + Toolkit::FlexContainer::Alignment alignItems(Toolkit::FlexContainer::ALIGN_STRETCH); - if( value.GetType() == Property::INTEGER ) + if(value.GetType() == Property::INTEGER) { - flexContainerImpl.SetAlignItems( static_cast( value.Get< int >() ) ); + flexContainerImpl.SetAlignItems(static_cast(value.Get())); } - else if( Scripting::GetEnumeration< Toolkit::FlexContainer::Alignment >( value.Get< std::string >().c_str(), - ALIGN_ITEMS_STRING_TABLE, - ALIGN_ITEMS_STRING_TABLE_COUNT, - alignItems ) ) + else if(Scripting::GetEnumeration(value.Get().c_str(), + ALIGN_ITEMS_STRING_TABLE, + ALIGN_ITEMS_STRING_TABLE_COUNT, + alignItems)) { flexContainerImpl.SetAlignItems(alignItems); } @@ -397,16 +398,16 @@ void FlexContainer::SetProperty( BaseObject* object, Property::Index index, cons } case Toolkit::FlexContainer::Property::ALIGN_CONTENT: { - Toolkit::FlexContainer::Alignment alignContent( Toolkit::FlexContainer::ALIGN_FLEX_START ); + Toolkit::FlexContainer::Alignment alignContent(Toolkit::FlexContainer::ALIGN_FLEX_START); - if( value.GetType() == Property::INTEGER ) + if(value.GetType() == Property::INTEGER) { - flexContainerImpl.SetAlignContent( static_cast( value.Get< int >() ) ); + flexContainerImpl.SetAlignContent(static_cast(value.Get())); } - else if( Scripting::GetEnumeration< Toolkit::FlexContainer::Alignment >( value.Get< std::string >().c_str(), - ALIGN_CONTENT_STRING_TABLE, - ALIGN_CONTENT_STRING_TABLE_COUNT, - alignContent ) ) + else if(Scripting::GetEnumeration(value.Get().c_str(), + ALIGN_CONTENT_STRING_TABLE, + ALIGN_CONTENT_STRING_TABLE_COUNT, + alignContent)) { flexContainerImpl.SetAlignContent(alignContent); } @@ -416,16 +417,16 @@ void FlexContainer::SetProperty( BaseObject* object, Property::Index index, cons } } -Property::Value FlexContainer::GetProperty( BaseObject* object, Property::Index index ) +Property::Value FlexContainer::GetProperty(BaseObject* object, Property::Index index) { Property::Value value; - Toolkit::FlexContainer flexContainer = Toolkit::FlexContainer::DownCast( Dali::BaseHandle( object ) ); + Toolkit::FlexContainer flexContainer = Toolkit::FlexContainer::DownCast(Dali::BaseHandle(object)); - if( flexContainer ) + if(flexContainer) { - FlexContainer& flexContainerImpl( GetImpl( flexContainer ) ); - switch( index ) + FlexContainer& flexContainerImpl(GetImpl(flexContainer)); + switch(index) { case Toolkit::FlexContainer::Property::CONTENT_DIRECTION: { @@ -463,31 +464,29 @@ Property::Value FlexContainer::GetProperty( BaseObject* object, Property::Index return value; } -void FlexContainer::OnChildAdd( Actor& child ) +void FlexContainer::OnChildAdd(Actor& child) { - Control::OnChildAdd( child ); - - // Anchor actor to top left of the container - child.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - child.SetParentOrigin( ParentOrigin::TOP_LEFT ); - // Create a new node for the child. FlexItemNode childNode; childNode.actor = child; - childNode.node = new_css_node(); - childNode.node->get_child = GetChildNodeAtIndex; - childNode.node->is_dirty = IsNodeDirty; + childNode.node = YGNodeNew(); + mChildrenNodes.push_back(childNode); + YGNodeInsertChild(mRootNode.node, childNode.node, mChildrenNodes.size() - 1); + + Control::OnChildAdd(child); } -void FlexContainer::OnChildRemove( Actor& child ) +void FlexContainer::OnChildRemove(Actor& child) { - for( unsigned int i = 0; i < mChildrenNodes.size(); i++ ) + for(unsigned int i = 0; i < mChildrenNodes.size(); i++) { - if( mChildrenNodes[i].actor.GetHandle() == child ) + if(mChildrenNodes[i].actor.GetHandle() == child) { - free_css_node( mChildrenNodes[i].node ); - mChildrenNodes.erase( mChildrenNodes.begin() + i ); + YGNodeRemoveChild(mRootNode.node, mChildrenNodes[i].node); + YGNodeFree(mChildrenNodes[i].node); + + mChildrenNodes.erase(mChildrenNodes.begin() + i); // Relayout the container only if instances were found RelayoutRequest(); @@ -495,147 +494,193 @@ void FlexContainer::OnChildRemove( Actor& child ) } } - Control::OnChildRemove( child ); + Control::OnChildRemove(child); } -void FlexContainer::OnRelayout( const Vector2& size, RelayoutContainer& container ) +void FlexContainer::OnRelayout(const Vector2& size, RelayoutContainer& container) { - for( unsigned int i = 0; i < mChildrenNodes.size(); i++ ) + for(unsigned int i = 0; i < mChildrenNodes.size(); i++) { Actor child = mChildrenNodes[i].actor.GetHandle(); - if( child ) + if(child) { - float negotiatedWidth = child.GetRelayoutSize(Dimension::WIDTH); + // Anchor actor to top left of the container + if(child.GetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT).Get()) + { + child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + } + child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + + float negotiatedWidth = child.GetRelayoutSize(Dimension::WIDTH); float negotiatedHeight = child.GetRelayoutSize(Dimension::HEIGHT); - if( negotiatedWidth > 0 ) + if(negotiatedWidth > 0) { - mChildrenNodes[i].node->style.dimensions[CSS_WIDTH] = negotiatedWidth; + YGNodeStyleSetWidth(mChildrenNodes[i].node, negotiatedWidth); } - if( negotiatedHeight > 0 ) + if(negotiatedHeight > 0) { - mChildrenNodes[i].node->style.dimensions[CSS_HEIGHT] = negotiatedHeight; + YGNodeStyleSetHeight(mChildrenNodes[i].node, negotiatedHeight); } } } // Relayout the container RelayoutChildren(); +#if defined(FLEX_CONTAINER_DEBUG) + PrintNodes(mChildrenNodes); +#endif - for( unsigned int i = 0; i < mChildrenNodes.size(); i++ ) + for(unsigned int i = 0; i < mChildrenNodes.size(); i++) { Actor child = mChildrenNodes[i].actor.GetHandle(); - if( child ) + if(child) { - if( child.GetResizePolicy( Dimension::WIDTH ) != ResizePolicy::USE_ASSIGNED_SIZE ) + if(child.GetPropertyType(Toolkit::FlexContainer::ChildProperty::FLEX) != Property::NONE) { - child.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH ); - } - if( child.GetResizePolicy( Dimension::HEIGHT ) != ResizePolicy::USE_ASSIGNED_SIZE ) - { - child.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::HEIGHT ); - } + // Only Set to USE_ASSIGNED_SIZE if the child actor is flexible. - container.Add( child, Vector2(mChildrenNodes[i].node->layout.dimensions[CSS_WIDTH], mChildrenNodes[i].node->layout.dimensions[CSS_HEIGHT] ) ); + if(child.GetResizePolicy(Dimension::WIDTH) != ResizePolicy::USE_ASSIGNED_SIZE) + { + child.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH); + } + if(child.GetResizePolicy(Dimension::HEIGHT) != ResizePolicy::USE_ASSIGNED_SIZE) + { + child.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::HEIGHT); + } + } + container.Add(child, Vector2(YGNodeLayoutGetWidth(mChildrenNodes[i].node), YGNodeLayoutGetHeight(mChildrenNodes[i].node))); } } } -bool FlexContainer::RelayoutDependentOnChildren( Dimension::Type dimension ) +bool FlexContainer::RelayoutDependentOnChildren(Dimension::Type dimension) { return true; } -void FlexContainer::OnSizeSet( const Vector3& size ) +void FlexContainer::OnSizeSet(const Vector3& size) { - if( mRootNode.node ) + if(mRootNode.node) { Actor self = Self(); - - mRootNode.node->style.dimensions[CSS_WIDTH] = size.x; - mRootNode.node->style.dimensions[CSS_HEIGHT] = size.y; + YGNodeStyleSetWidth(mRootNode.node, size.x); + YGNodeStyleSetHeight(mRootNode.node, size.y); RelayoutRequest(); } + + Control::OnSizeSet(size); } -void FlexContainer::OnSizeAnimation( Animation& animation, const Vector3& targetSize ) +void FlexContainer::OnLayoutDirectionChanged(Dali::Actor actor, Dali::LayoutDirection::Type type) { - // @todo Animate the children to their target size and position + Toolkit::FlexContainer flexContainer = Toolkit::FlexContainer::DownCast(actor); + Toolkit::FlexContainer::ContentDirection direction; + + if(type == Dali::LayoutDirection::RIGHT_TO_LEFT) + { + direction = Toolkit::FlexContainer::RTL; + } + else + { + direction = Toolkit::FlexContainer::LTR; + } + + Toolkit::Internal::FlexContainer& flexContainerImpl = GetImpl(flexContainer); + + if(flexContainerImpl.mContentDirection != direction) + { + Dali::CustomActor ownerActor(flexContainerImpl.GetOwner()); + flexContainerImpl.mContentDirection = direction; + + flexContainerImpl.RelayoutRequest(); + } } void FlexContainer::ComputeLayout() { - if( mRootNode.node ) + if(mRootNode.node) { - mRootNode.node->children_count = mChildrenNodes.size(); - - // Intialize the layout. - mRootNode.node->layout.position[CSS_LEFT] = 0; - mRootNode.node->layout.position[CSS_TOP] = 0; - mRootNode.node->layout.position[CSS_BOTTOM] = 0; - mRootNode.node->layout.position[CSS_RIGHT] = 0; - mRootNode.node->layout.dimensions[CSS_WIDTH] = CSS_UNDEFINED; - mRootNode.node->layout.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; - - for( unsigned int i = 0; i < mChildrenNodes.size(); i++ ) + for(unsigned int i = 0; i < mChildrenNodes.size(); i++) { - css_node_t* childNode = mChildrenNodes[i].node; - Actor childActor = mChildrenNodes[i].actor.GetHandle(); - - childNode->layout.position[CSS_LEFT] = 0; - childNode->layout.position[CSS_TOP] = 0; - childNode->layout.position[CSS_BOTTOM] = 0; - childNode->layout.position[CSS_RIGHT] = 0; - childNode->layout.dimensions[CSS_WIDTH] = CSS_UNDEFINED; - childNode->layout.dimensions[CSS_HEIGHT] = CSS_UNDEFINED; + YGNodeRef childNode = mChildrenNodes[i].node; + Actor childActor = mChildrenNodes[i].actor.GetHandle(); // Intialize the style of the child. - childNode->style.minDimensions[CSS_WIDTH] = childActor.GetMinimumSize().x; - childNode->style.minDimensions[CSS_HEIGHT] = childActor.GetMinimumSize().y; - childNode->style.maxDimensions[CSS_WIDTH] = childActor.GetMaximumSize().x; - childNode->style.maxDimensions[CSS_HEIGHT] = childActor.GetMaximumSize().y; + YGNodeStyleSetMinWidth(childNode, childActor.GetProperty(Actor::Property::MINIMUM_SIZE).x); + YGNodeStyleSetMinHeight(childNode, childActor.GetProperty(Actor::Property::MINIMUM_SIZE).y); + YGNodeStyleSetMaxWidth(childNode, childActor.GetProperty(Actor::Property::MAXIMUM_SIZE).x); + YGNodeStyleSetMaxHeight(childNode, childActor.GetProperty(Actor::Property::MAXIMUM_SIZE).y); // 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. - if( childActor.GetPropertyType( Toolkit::FlexContainer::ChildProperty::FLEX ) != Property::NONE ) + if(childActor.GetPropertyType(Toolkit::FlexContainer::ChildProperty::FLEX) != Property::NONE) { - childNode->style.flex = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::FLEX ).Get(); + YGNodeStyleSetFlex(childNode, childActor.GetProperty(Toolkit::FlexContainer::ChildProperty::FLEX).Get()); } - Toolkit::FlexContainer::Alignment alignSelf( Toolkit::FlexContainer::ALIGN_AUTO ); - if( childActor.GetPropertyType( Toolkit::FlexContainer::FlexContainer::ChildProperty::ALIGN_SELF ) != Property::NONE ) + Toolkit::FlexContainer::Alignment alignSelf(Toolkit::FlexContainer::ALIGN_AUTO); + if(childActor.GetPropertyType(Toolkit::FlexContainer::ChildProperty::ALIGN_SELF) != Property::NONE) { - Property::Value alignSelfPropertyValue = childActor.GetProperty( Toolkit::FlexContainer::ChildProperty::ALIGN_SELF ); - if( alignSelfPropertyValue.GetType() == Property::INTEGER ) + Property::Value alignSelfPropertyValue = childActor.GetProperty(Toolkit::FlexContainer::ChildProperty::ALIGN_SELF); + if(alignSelfPropertyValue.GetType() == Property::INTEGER) { - alignSelf = static_cast( alignSelfPropertyValue.Get< int >() ); + alignSelf = static_cast(alignSelfPropertyValue.Get()); } - else if( alignSelfPropertyValue.GetType() == Property::STRING ) + 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 ); + Scripting::GetEnumeration(value.c_str(), + ALIGN_SELF_STRING_TABLE, + ALIGN_SELF_STRING_TABLE_COUNT, + alignSelf); } + YGNodeStyleSetAlignSelf(childNode, static_cast(alignSelf)); } - childNode->style.align_self = static_cast(alignSelf); - if( childActor.GetPropertyType( Toolkit::FlexContainer::ChildProperty::FLEX_MARGIN ) != Property::NONE ) + 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; + Vector4 flexMargin = childActor.GetProperty(Toolkit::FlexContainer::ChildProperty::FLEX_MARGIN).Get(); + YGNodeStyleSetMargin(childNode, YGEdgeLeft, flexMargin.x); + YGNodeStyleSetMargin(childNode, YGEdgeTop, flexMargin.y); + YGNodeStyleSetMargin(childNode, YGEdgeRight, flexMargin.z); + YGNodeStyleSetMargin(childNode, YGEdgeBottom, flexMargin.w); } } // Calculate the layout - layoutNode( mRootNode.node, Self().GetMaximumSize().x, Self().GetMaximumSize().y, mRootNode.node->style.direction ); + YGDirection nodeLayoutDirection = YGDirectionInherit; + switch(mContentDirection) + { + case Dali::Toolkit::FlexContainer::LTR: + { + nodeLayoutDirection = YGDirectionLTR; + break; + } + + case Dali::Toolkit::FlexContainer::RTL: + { + nodeLayoutDirection = YGDirectionRTL; + break; + } + + case Dali::Toolkit::FlexContainer::INHERIT: + { + nodeLayoutDirection = YGDirectionInherit; + break; + } + } + +#if defined(FLEX_CONTAINER_DEBUG) + YGNodePrint(mRootNode.node, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsStyle | YGPrintOptionsChildren)); +#endif + YGNodeCalculateLayout(mRootNode.node, Self().GetProperty(Actor::Property::MAXIMUM_SIZE).x, Self().GetProperty(Actor::Property::MAXIMUM_SIZE).y, nodeLayoutDirection); +#if defined(FLEX_CONTAINER_DEBUG) + YGNodePrint(mRootNode.node, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsStyle | YGPrintOptionsChildren)); +#endif } } @@ -644,13 +689,13 @@ void FlexContainer::RelayoutChildren() ComputeLayout(); // Set size and position of children according to the layout calculation - for( unsigned int i = 0; i < mChildrenNodes.size(); i++ ) + for(unsigned int i = 0; i < mChildrenNodes.size(); i++) { Dali::Actor child = mChildrenNodes[i].actor.GetHandle(); - if( child ) + if(child) { - child.SetX( mChildrenNodes[i].node->layout.position[CSS_LEFT] ); - child.SetY( mChildrenNodes[i].node->layout.position[CSS_TOP] ); + child.SetProperty(Actor::Property::POSITION_X, YGNodeLayoutGetLeft(mChildrenNodes[i].node)); + child.SetProperty(Actor::Property::POSITION_Y, YGNodeLayoutGetTop(mChildrenNodes[i].node)); } } } @@ -660,9 +705,9 @@ Actor FlexContainer::GetNextKeyboardFocusableActor(Actor currentFocusedActor, To Actor nextFocusableActor; // First check whether there is any items in the container - if( mChildrenNodes.size() > 0 ) + if(mChildrenNodes.size() > 0) { - if ( !currentFocusedActor || currentFocusedActor == Self() ) + if(!currentFocusedActor || currentFocusedActor == Self()) { // Nothing is currently focused, so the first child in the container should be focused. nextFocusableActor = mChildrenNodes[0].actor.GetHandle(); @@ -671,20 +716,20 @@ Actor FlexContainer::GetNextKeyboardFocusableActor(Actor currentFocusedActor, To { // Check whether the current focused actor is within flex container int currentFocusedActorIndex = -1; - for( unsigned int index = 0; index < mChildrenNodes.size(); index++ ) + for(unsigned int index = 0; index < mChildrenNodes.size(); index++) { - if( currentFocusedActor == mChildrenNodes[index].actor.GetHandle() ) + if(currentFocusedActor == mChildrenNodes[index].actor.GetHandle()) { currentFocusedActorIndex = index; break; } } - if( currentFocusedActorIndex > -1 ) + if(currentFocusedActorIndex > -1) { int previousCheckedActorIndex = -1; - int nextFocusedActorIndex = currentFocusedActorIndex; - switch ( direction ) + int nextFocusedActorIndex = currentFocusedActorIndex; + switch(direction) { case Toolkit::Control::KeyboardFocus::LEFT: case Toolkit::Control::KeyboardFocus::UP: @@ -693,11 +738,11 @@ Actor FlexContainer::GetNextKeyboardFocusableActor(Actor currentFocusedActor, To do { nextFocusedActorIndex--; - if( nextFocusedActorIndex < 0 ) + if(nextFocusedActorIndex < 0) { nextFocusedActorIndex = loopEnabled ? mChildrenNodes.size() - 1 : 0; } - if( nextFocusedActorIndex != previousCheckedActorIndex && nextFocusedActorIndex != currentFocusedActorIndex ) + if(nextFocusedActorIndex != previousCheckedActorIndex && nextFocusedActorIndex != currentFocusedActorIndex) { previousCheckedActorIndex = nextFocusedActorIndex; } @@ -705,7 +750,7 @@ Actor FlexContainer::GetNextKeyboardFocusableActor(Actor currentFocusedActor, To { break; } - } while ( !mChildrenNodes[nextFocusedActorIndex].actor.GetHandle().IsKeyboardFocusable() ); + } while(!mChildrenNodes[nextFocusedActorIndex].actor.GetHandle().GetProperty(Actor::Property::KEYBOARD_FOCUSABLE)); break; } case Toolkit::Control::KeyboardFocus::RIGHT: @@ -715,11 +760,11 @@ Actor FlexContainer::GetNextKeyboardFocusableActor(Actor currentFocusedActor, To do { nextFocusedActorIndex++; - if( nextFocusedActorIndex > static_cast(mChildrenNodes.size() - 1) ) + if(nextFocusedActorIndex > static_cast(mChildrenNodes.size() - 1)) { nextFocusedActorIndex = loopEnabled ? 0 : mChildrenNodes.size() - 1; } - if( nextFocusedActorIndex != previousCheckedActorIndex && nextFocusedActorIndex != currentFocusedActorIndex ) + if(nextFocusedActorIndex != previousCheckedActorIndex && nextFocusedActorIndex != currentFocusedActorIndex) { previousCheckedActorIndex = nextFocusedActorIndex; } @@ -727,12 +772,16 @@ Actor FlexContainer::GetNextKeyboardFocusableActor(Actor currentFocusedActor, To { break; } - } while ( !mChildrenNodes[nextFocusedActorIndex].actor.GetHandle().IsKeyboardFocusable() ); + } while(!mChildrenNodes[nextFocusedActorIndex].actor.GetHandle().GetProperty(Actor::Property::KEYBOARD_FOCUSABLE)); + break; + } + default: + { break; } } - if( nextFocusedActorIndex != currentFocusedActorIndex ) + if(nextFocusedActorIndex != currentFocusedActorIndex) { nextFocusableActor = mChildrenNodes[nextFocusedActorIndex].actor.GetHandle(); } @@ -754,40 +803,42 @@ Actor FlexContainer::GetNextKeyboardFocusableActor(Actor currentFocusedActor, To } FlexContainer::FlexContainer() -: Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ), - mContentDirection( Toolkit::FlexContainer::INHERIT ), - mFlexDirection( Toolkit::FlexContainer::COLUMN ), - mFlexWrap( Toolkit::FlexContainer::NO_WRAP ), - mJustifyContent( Toolkit::FlexContainer::JUSTIFY_FLEX_START ), - mAlignItems( Toolkit::FlexContainer::ALIGN_STRETCH ), - mAlignContent( Toolkit::FlexContainer::ALIGN_FLEX_START ) -{ - SetKeyboardNavigationSupport( true ); +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), + mContentDirection(Toolkit::FlexContainer::INHERIT), + mFlexDirection(Toolkit::FlexContainer::COLUMN), + mFlexWrap(Toolkit::FlexContainer::NO_WRAP), + mJustifyContent(Toolkit::FlexContainer::JUSTIFY_FLEX_START), + mAlignItems(Toolkit::FlexContainer::ALIGN_STRETCH), + mAlignContent(Toolkit::FlexContainer::ALIGN_FLEX_START) +{ + SetKeyboardNavigationSupport(true); } void FlexContainer::OnInitialize() { // Initialize the node for the flex container itself Dali::Actor self = Self(); + self.LayoutDirectionChangedSignal().Connect(this, &FlexContainer::OnLayoutDirectionChanged); + mRootNode.actor = self; - mRootNode.node = new_css_node(); - mRootNode.node->context = &mChildrenNodes; + mRootNode.node = YGNodeNew(); + YGNodeSetContext(mRootNode.node, &mChildrenNodes); // Set default style - mRootNode.node->style.direction = static_cast( mContentDirection ); - mRootNode.node->style.flex_direction = static_cast( mFlexDirection ); - mRootNode.node->style.flex_wrap = static_cast( mFlexWrap ); - mRootNode.node->style.justify_content = static_cast( mJustifyContent ); - mRootNode.node->style.align_items = static_cast( mAlignItems ); - mRootNode.node->style.align_content = static_cast( mAlignContent ); - - // Set callbacks. - mRootNode.node->get_child = GetChildNodeAtIndex; - mRootNode.node->is_dirty = IsNodeDirty; + YGNodeStyleSetFlexDirection(mRootNode.node, static_cast(mFlexDirection)); + YGNodeStyleSetFlexWrap(mRootNode.node, static_cast(mFlexWrap)); + YGNodeStyleSetJustifyContent(mRootNode.node, static_cast(mJustifyContent)); + YGNodeStyleSetAlignItems(mRootNode.node, static_cast(mAlignItems)); + YGNodeStyleSetAlignContent(mRootNode.node, static_cast(mAlignContent)); // Make self as keyboard focusable and focus group - self.SetKeyboardFocusable( true ); - SetAsKeyboardFocusGroup( true ); + self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + SetAsKeyboardFocusGroup(true); + + DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) { + return std::unique_ptr( + new DevelControl::AccessibleImpl(actor, Dali::Accessibility::Role::FILLER)); + }); } } // namespace Internal