From: taeyoon0.lee Date: Fri, 22 Sep 2017 08:12:25 +0000 (+0900) Subject: RTL support of FlexContainer X-Git-Tag: dali_1.3.1~5 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=314c314b2b44e77d5f9b48056c83bc9f33f58130;hp=d9a5a0e168ee7978fcea370cd3a3618e50f6b579 RTL support of FlexContainer Change-Id: Ibc703d749415cf2b58615ddcb2619284784d4119 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-FlexContainer.cpp b/automated-tests/src/dali-toolkit/utc-Dali-FlexContainer.cpp old mode 100644 new mode 100755 index f602079..26e9585 --- a/automated-tests/src/dali-toolkit/utc-Dali-FlexContainer.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-FlexContainer.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace Dali; using namespace Toolkit; @@ -494,3 +495,66 @@ int UtcDaliToolkitFlexContainerMoveFocus(void) END_TEST; } + +int UtcDaliToolkitFlexContainerRTLSupportP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitFlexContainerRTLSupportP"); + FlexContainer flexContainer = FlexContainer::New(); + DALI_TEST_CHECK( flexContainer ); + + Actor actor0 = Actor::New(); + + Stage::GetCurrent().Add( actor0 ); + actor0.Add( flexContainer ); + + // Create two actors and add them to the container + Actor actor1 = Actor::New(); + Actor actor2 = Actor::New(); + DALI_TEST_CHECK( actor1 ); + DALI_TEST_CHECK( actor2 ); + + flexContainer.Add(actor1); + flexContainer.Add(actor2); + + // Check flex direction property. + flexContainer.SetProperty( FlexContainer::Property::FLEX_DIRECTION, "row" ); + DALI_TEST_EQUALS( (FlexContainer::FlexDirection)flexContainer.GetProperty( FlexContainer::Property::FLEX_DIRECTION ), FlexContainer::ROW, TEST_LOCATION ); + + // Check content direction property. + DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::INHERIT, TEST_LOCATION ); + + actor0.SetProperty( Dali::DevelActor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT ); + DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::RTL, TEST_LOCATION ); + + actor0.SetProperty( Dali::DevelActor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT ); + DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION ); + + flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "RTL" ); + DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::RTL, TEST_LOCATION ); + + flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "LTR" ); + DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION ); + + actor0.SetProperty( Dali::DevelActor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT ); + DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION ); + + flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "inherit" ); + DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::RTL, TEST_LOCATION ); + + actor0.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT ); + DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION ); + + flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "inherit" ); + DALI_TEST_EQUALS( (FlexContainer::ContentDirection)flexContainer.GetProperty( FlexContainer::Property::CONTENT_DIRECTION ), FlexContainer::LTR, TEST_LOCATION ); + + flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "LTR" ); + application.SendNotification(); + application.Render(); + + flexContainer.SetProperty( FlexContainer::Property::CONTENT_DIRECTION, "RTL" ); + application.SendNotification(); + application.Render(); + + END_TEST; +} diff --git a/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp b/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp old mode 100644 new mode 100755 index 650e5cf..e1849bf --- a/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp +++ b/dali-toolkit/internal/controls/flex-container/flex-container-impl.cpp @@ -176,7 +176,6 @@ bool IsNodeDirty( void *itemNodes ) // style properties are changed. So should always return true here. return true; } - } // Unnamed namespace Toolkit::FlexContainer FlexContainer::New() @@ -206,12 +205,42 @@ FlexContainer::~FlexContainer() mChildrenNodes.clear(); } -void FlexContainer::SetContentDirection( Toolkit::FlexContainer::ContentDirection contentDirection ) +void FlexContainer::SetContentDirection( Toolkit::FlexContainer::ContentDirection 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(); } @@ -570,6 +599,31 @@ void FlexContainer::OnSizeSet( const Vector3& size ) Control::OnSizeSet( size ); } +void FlexContainer::OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type ) +{ + 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 ) @@ -641,7 +695,29 @@ void FlexContainer::ComputeLayout() } // Calculate the layout - layoutNode( mRootNode.node, Self().GetMaximumSize().x, Self().GetMaximumSize().y, mRootNode.node->style.direction ); + css_direction_t nodeLayoutDirection = CSS_DIRECTION_INHERIT; + switch( mContentDirection ) + { + case Dali::Toolkit::FlexContainer::LTR: + { + nodeLayoutDirection = CSS_DIRECTION_LTR; + break; + } + + case Dali::Toolkit::FlexContainer::RTL: + { + nodeLayoutDirection = CSS_DIRECTION_RTL; + break; + } + + case Dali::Toolkit::FlexContainer::INHERIT: + { + nodeLayoutDirection = CSS_DIRECTION_INHERIT; + break; + } + } + + layoutNode( mRootNode.node, Self().GetMaximumSize().x, Self().GetMaximumSize().y, nodeLayoutDirection); } } @@ -779,6 +855,8 @@ 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; diff --git a/dali-toolkit/internal/controls/flex-container/flex-container-impl.h b/dali-toolkit/internal/controls/flex-container/flex-container-impl.h old mode 100644 new mode 100755 index c56a3ca..71fec8e --- a/dali-toolkit/internal/controls/flex-container/flex-container-impl.h +++ b/dali-toolkit/internal/controls/flex-container/flex-container-impl.h @@ -205,6 +205,13 @@ private: // From Control */ virtual void OnSizeSet( const Vector3& size ); + /** + * @copydoc OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type ) + * @param[in] actor The actor whose layoutDirection is changed. + * @param[in] type The layoutDirection. + */ + void OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type ); + private: // Implementation /**