/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
#include <dali/public-api/object/ref-object.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/devel-api/actors/actor-devel.h>
#include <dali/devel-api/scripting/scripting.h>
#include <dali/public-api/size-negotiation/relayout-container.h>
#include <dali/integration-api/debug.h>
// style properties are changed. So should always return true here.
return true;
}
-
} // Unnamed namespace
Toolkit::FlexContainer FlexContainer::New()
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<css_direction_t>( 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<Dali::LayoutDirection::Type>( ownerActor.GetParent().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
+
+ if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
+ {
+ mContentDirection = Toolkit::FlexContainer::RTL;
+ }
+ else
+ {
+ mContentDirection = Toolkit::FlexContainer::LTR;
+ }
+ }
RelayoutRequest();
}
void FlexContainer::OnChildAdd( Actor& 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;
Actor child = mChildrenNodes[i].actor.GetHandle();
if( child )
{
+ // Anchor actor to top left of the container
+ if( child.GetProperty( DevelActor::Property::POSITION_USES_ANCHOR_POINT ).Get< bool >() )
+ {
+ child.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ }
+ child.SetParentOrigin( ParentOrigin::TOP_LEFT );
+
float negotiatedWidth = child.GetRelayoutSize(Dimension::WIDTH);
float negotiatedHeight = child.GetRelayoutSize(Dimension::HEIGHT);
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 )
}
Toolkit::FlexContainer::Alignment alignSelf( Toolkit::FlexContainer::ALIGN_AUTO );
- if( childActor.GetPropertyType( Toolkit::FlexContainer::FlexContainer::ChildProperty::ALIGN_SELF ) != Property::NONE )
+ 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 )
}
// 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);
}
}
{
// 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;