*/
// CLASS HEADER
+#include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
+
+// EXTERNAL INCLUDES
#include <dali/public-api/object/type-registry-helper.h>
#include <dali/devel-api/actors/actor-devel.h>
#include <dali/devel-api/object/handle-devel.h>
-#include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
#include <dali-toolkit/internal/layouting/layout-group-data-impl.h>
#include <dali-toolkit/public-api/controls/control-impl.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
-
namespace
{
-const char* MARGIN_SPECIFICATION_NAME( "marginSpec" );
+#if defined(DEBUG_ENABLED)
+Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_LAYOUT" );
+#endif
}
namespace Dali
{
}
+LayoutGroupPtr LayoutGroup::New( Handle& owner )
+{
+ LayoutGroupPtr layoutPtr = new LayoutGroup();
+ return layoutPtr;
+}
+
LayoutGroup::~LayoutGroup()
{
+ // An object with a unique_ptr to an opaque structure must define it's destructor in the translation unit
+ // where the opaque structure is defined. It cannot use the default method in the header file.
}
-Toolkit::LayoutGroup::LayoutId LayoutGroup::Add( LayoutBase& child )
+Toolkit::LayoutGroup::LayoutId LayoutGroup::Add( LayoutItem& child )
{
LayoutParent* oldParent = child.GetParent();
if( oldParent )
childLayout.child = &child;
mImpl->mChildren.emplace_back( childLayout );
+ child.SetParent( this );
+
auto owner = child.GetOwner();
- // If the owner does not have any LayoutBase child properties, add them
- if( ! DevelHandle::DoesCustomPropertyExist( owner, Toolkit::LayoutBase::ChildProperty::WIDTH_SPECIFICATION ) )
+ // If the owner does not have any LayoutItem child properties, add them
+ if( ! DevelHandle::DoesCustomPropertyExist( owner, Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ) )
{
- // Set default properties for LayoutGroup and LayoutBase.
+ // Set default properties for LayoutGroup and LayoutItem.
// Deriving classes can override OnChildAdd() to add their own default properties
GenerateDefaultChildPropertyValues( owner );
}
{
if( iter->layoutId == childId )
{
- OnChildRemove( *iter->child.Get() );
+ RemoveChild( *iter->child.Get() );
mImpl->mChildren.erase(iter);
break;
}
RequestLayout();
}
-void LayoutGroup::Remove( LayoutBase& child )
+void LayoutGroup::Remove( LayoutItem& child )
{
for( auto iter = mImpl->mChildren.begin() ; iter != mImpl->mChildren.end() ; ++iter )
{
if( iter->child.Get() == &child )
{
- OnChildRemove( *iter->child.Get() );
+ RemoveChild( *iter->child.Get() );
mImpl->mChildren.erase(iter);
break;
}
RequestLayout();
}
-void LayoutGroup::RemoveAll()
+Toolkit::LayoutGroup::LayoutId LayoutGroup::Insert( LayoutItem& target, LayoutItem& child )
{
+ LayoutParent* oldParent = child.GetParent();
+ if( oldParent )
+ {
+ LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( oldParent ) );
+ if( parentGroup )
+ {
+ parentGroup->Remove( child );
+ }
+ }
+
+ // Find target position
+ std::vector< Impl::ChildLayout >::iterator position;
+ for( auto iter = mImpl->mChildren.begin(); iter != mImpl->mChildren.end(); ++iter )
+ {
+ if( iter->child.Get() == &target )
+ {
+ position = iter;
+ break;
+ }
+ }
+
+ Impl::ChildLayout childLayout;
+ childLayout.layoutId = mImpl->mNextLayoutId++;
+ childLayout.child = &child;
+ mImpl->mChildren.insert( position, childLayout );
+
+ child.SetParent( this );
+
+ auto owner = child.GetOwner();
+
+ // Inform deriving classes that this child has been added
+ OnChildAdd( *childLayout.child.Get() );
+
+ // Now listen to future changes to the child properties.
+ DevelHandle::PropertySetSignal(owner).Connect( this, &LayoutGroup::OnSetChildProperties );
+
+ RequestLayout();
+
+ return childLayout.layoutId;
+}
+
+Toolkit::LayoutGroup::LayoutId LayoutGroup::Move( LayoutItem& target, LayoutItem& child )
+{
+ // Remove child from the previous position
for( auto iter = mImpl->mChildren.begin() ; iter != mImpl->mChildren.end() ; ++iter )
{
- OnChildRemove( *iter->child.Get() );
+ if( iter->child.Get() == &child )
+ {
+ mImpl->mChildren.erase( iter );
+ break;
+ }
+ }
+
+ // Find target position
+ std::vector< Impl::ChildLayout >::iterator position;
+ for( auto iter = mImpl->mChildren.begin(); iter != mImpl->mChildren.end(); ++iter )
+ {
+ if( iter->child.Get() == &target )
+ {
+ position = iter;
+ break;
+ }
+ }
+
+ Impl::ChildLayout childLayout;
+ childLayout.layoutId = mImpl->mNextLayoutId++;
+ childLayout.child = &child;
+ mImpl->mChildren.insert( position, childLayout );
+
+ RequestLayout();
+
+ return childLayout.layoutId;
+}
+
+Toolkit::LayoutGroup::LayoutId LayoutGroup::MoveBack( LayoutItem& child )
+{
+ // Remove child from the previous position
+ for( auto iter = mImpl->mChildren.begin() ; iter != mImpl->mChildren.end() ; ++iter )
+ {
+ if( iter->child.Get() == &child )
+ {
+ mImpl->mChildren.erase( iter );
+ break;
+ }
+ }
+
+ Impl::ChildLayout childLayout;
+ childLayout.layoutId = mImpl->mNextLayoutId++;
+ childLayout.child = &child;
+ mImpl->mChildren.emplace_back( childLayout );
+
+ RequestLayout();
+
+ return childLayout.layoutId;
+}
+
+void LayoutGroup::RemoveAll()
+{
+ for( auto iter = mImpl->mChildren.begin() ; iter != mImpl->mChildren.end() ; )
+ {
+ RemoveChild( *iter->child.Get() );
iter = mImpl->mChildren.erase(iter);
}
}
return mImpl->mChildren.size();
}
-LayoutBasePtr LayoutGroup::GetChildAt( unsigned int index ) const
+LayoutItemPtr LayoutGroup::GetChildAt( unsigned int index ) const
{
DALI_ASSERT_ALWAYS( index < mImpl->mChildren.size() );
return mImpl->mChildren[ index ].child;
}
-LayoutBasePtr LayoutGroup::GetChild( Toolkit::LayoutGroup::LayoutId childId ) const
+LayoutItemPtr LayoutGroup::GetChild( Toolkit::LayoutGroup::LayoutId childId ) const
{
for( auto&& childLayout : mImpl->mChildren )
{
return NULL;
}
-Toolkit::LayoutGroup::LayoutId LayoutGroup::GetChildId( LayoutBase& child ) const
+Toolkit::LayoutGroup::LayoutId LayoutGroup::GetChildId( LayoutItem& child ) const
{
for( auto&& childLayout : mImpl->mChildren )
{
return Toolkit::LayoutGroup::UNKNOWN_ID;
}
-void LayoutGroup::OnChildAdd( LayoutBase& child )
+void LayoutGroup::OnChildAdd( LayoutItem& child )
{
}
-void LayoutGroup::OnChildRemove( LayoutBase& child )
+void LayoutGroup::OnChildRemove( LayoutItem& child )
{
}
void LayoutGroup::OnSetChildProperties( Handle& handle, Property::Index index, Property::Value value )
{
- if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties property(" << handle.GetPropertyName(index) << ")\n" );
+
+ if ( ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) &&
+ ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
+ ||
+ ( index == Toolkit::Control::Property::MARGIN || index == Toolkit::Control::Property::PADDING ) )
{
// If any child properties are set, must perform relayout
- RequestLayout();
+ for( auto&& child : mImpl->mChildren )
+ {
+ if( child.child->GetOwner() == handle )
+ {
+ child.child->RequestLayout();
+ break;
+ }
+ }
}
}
void LayoutGroup::GenerateDefaultChildPropertyValues( Handle child )
{
- child.SetProperty( Toolkit::LayoutBase::ChildProperty::WIDTH_SPECIFICATION,
+ child.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION,
Toolkit::ChildLayoutData::WRAP_CONTENT );
- child.SetProperty( Toolkit::LayoutBase::ChildProperty::HEIGHT_SPECIFICATION,
+ child.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,
Toolkit::ChildLayoutData::WRAP_CONTENT );
- child.SetProperty( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION, Extents() );
}
void LayoutGroup::MeasureChildren( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec)
}
}
-void LayoutGroup::MeasureChild( LayoutBasePtr child,
+void LayoutGroup::MeasureChild( LayoutItemPtr child,
MeasureSpec parentWidthMeasureSpec,
MeasureSpec parentHeightMeasureSpec )
{
+ DALI_LOG_TRACE_METHOD( gLogFilter );
+
auto childOwner = child->GetOwner();
- auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutBase::ChildProperty::WIDTH_SPECIFICATION );
- auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutBase::ChildProperty::HEIGHT_SPECIFICATION );
- auto padding = GetPadding();
+ auto control = Toolkit::Control::DownCast( childOwner );
+
+#if defined( DEBUG_ENABLED )
+ if ( control )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild(%s) natural size(%f, %f)\n",
+ control.GetName().c_str(), control.GetNaturalSize().width, control.GetNaturalSize().height );
+ }
+#endif
+
+ // Get last stored width and height specifications for the child
+ auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
+ auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild desiredWidth(%d) desiredHeight(%d)\n", desiredWidth, desiredHeight );
+
+ auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured.
const MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec,
padding.start + padding.end,
child->Measure( childWidthMeasureSpec, childHeightMeasureSpec );
}
-void LayoutGroup::MeasureChildWithMargins( LayoutBasePtr child,
+void LayoutGroup::MeasureChildWithMargins( LayoutItemPtr child,
MeasureSpec parentWidthMeasureSpec, LayoutLength widthUsed,
MeasureSpec parentHeightMeasureSpec, LayoutLength heightUsed)
{
auto childOwner = child->GetOwner();
- auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutBase::ChildProperty::WIDTH_SPECIFICATION );
- auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutBase::ChildProperty::HEIGHT_SPECIFICATION );
- auto desiredMargin = childOwner.GetProperty<Extents>( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION );
- auto padding = GetPadding();
+ auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
+ auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
+
+ auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured.
+
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredWidth(%d)\n", desiredWidth );
MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec,
- padding.start + padding.end +
- desiredMargin.start + desiredMargin.end +
+ LayoutLength( padding.start + padding.end ) +
widthUsed, desiredWidth );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins desiredHeight(%d)\n", desiredHeight );
+
MeasureSpec childHeightMeasureSpec = GetChildMeasureSpec( parentHeightMeasureSpec,
- padding.top + padding.bottom +
- desiredMargin.top + desiredMargin.end +
+ LayoutLength( padding.top + padding.bottom )+
heightUsed, desiredHeight );
child->Measure( childWidthMeasureSpec, childHeightMeasureSpec );
auto specMode = measureSpec.GetMode();
LayoutLength specSize = measureSpec.GetSize();
- auto size = std::max( LayoutLength(0), specSize - padding );
+ LayoutLength size = std::max( LayoutLength(0), specSize - padding ); // reduce available size by the owners padding
- MeasureSpec::IntType resultSize = 0;
+ LayoutLength resultSize = 0;
MeasureSpec::Mode resultMode = MeasureSpec::Mode::UNSPECIFIED;
switch( specMode )
// Parent has imposed an exact size on us
case MeasureSpec::Mode::EXACTLY:
{
-
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec MeasureSpec::Mode::EXACTLY\n");
if (childDimension == Toolkit::ChildLayoutData::MATCH_PARENT)
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension MATCH_PARENT\n");
+
// Child wants to be our size. So be it.
resultSize = size;
resultMode = MeasureSpec::Mode::EXACTLY;
}
else if (childDimension == Toolkit::ChildLayoutData::WRAP_CONTENT)
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension WRAP_CONTENT\n");
+
// Child wants to determine its own size. It can't be
// bigger than us.
resultSize = size;
}
else
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension UNSPECIFIED\n");
resultSize = childDimension;
resultMode = MeasureSpec::Mode::EXACTLY;
}
// Parent has imposed a maximum size on us
case MeasureSpec::Mode::AT_MOST:
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec MeasureSpec::Mode::AT_MOST\n");
if (childDimension == Toolkit::ChildLayoutData::MATCH_PARENT)
{
// Child wants to be our size, but our size is not fixed.
else
{
// Child wants a specific size... so be it
- resultSize = childDimension;
+ resultSize = childDimension + padding;
resultMode = MeasureSpec::Mode::EXACTLY;
}
// Parent asked to see how big we want to be
case MeasureSpec::Mode::UNSPECIFIED:
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec MeasureSpec::Mode::UNSPECIFIED\n");
+
if (childDimension == Toolkit::ChildLayoutData::MATCH_PARENT)
{
// Child wants to be our size... find out how big it should be
- resultSize = LayoutBase::Impl::sUseZeroUnspecifiedMeasureSpec ? LayoutLength(0) : size;
+ resultSize = LayoutItem::Impl::sUseZeroUnspecifiedMeasureSpec ? LayoutLength(0) : size;
resultMode = MeasureSpec::Mode::UNSPECIFIED;
}
else if (childDimension == Toolkit::ChildLayoutData::WRAP_CONTENT)
{
// Child wants to determine its own size.... find out how big
// it should be
- resultSize = LayoutBase::Impl::sUseZeroUnspecifiedMeasureSpec ? LayoutLength(0) : size;
+ resultSize = LayoutItem::Impl::sUseZeroUnspecifiedMeasureSpec ? LayoutLength(0) : size;
resultMode = MeasureSpec::Mode::UNSPECIFIED;
}
else
{
// Child wants a specific size... let him have it
- resultSize = childDimension;
+ resultSize = childDimension + padding;
resultMode = MeasureSpec::Mode::EXACTLY;
}
break;
}
}
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec resultSize(" << resultSize << ")\n" );
+
//noinspection ResourceType
return MeasureSpec( resultSize, resultMode );
}
DevelActor::ChildAddedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildAddedToOwner );
DevelActor::ChildRemovedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildRemovedFromOwner );
+ DevelActor::ChildOrderChangedSignal( control ).Connect( mSlotDelegate, &LayoutGroup::ChildOrderChanged );
DevelHandle::PropertySetSignal( control ).Connect( mSlotDelegate, &LayoutGroup::OnOwnerPropertySet );
- }
-}
-
-void LayoutGroup::OnRegisterChildProperties( const std::string& containerType )
-{
- auto typeInfo = TypeRegistry::Get().GetTypeInfo( containerType );
- if( typeInfo )
- {
- Property::IndexContainer indices;
- typeInfo.GetChildPropertyIndices( indices );
- if( std::find( indices.Begin(), indices.End(), Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION ) ==
- indices.End() )
+ if( control.GetParent() )
{
- ChildPropertyRegistration( typeInfo.GetName(), MARGIN_SPECIFICATION_NAME, Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION, Property::EXTENTS );
+ auto parent = Toolkit::Control::DownCast( control.GetParent() );
+ if( parent )
+ {
+ auto parentLayout = Toolkit::LayoutGroup::DownCast( DevelControl::GetLayout( parent ) );
+ if( parentLayout )
+ {
+ Internal::LayoutGroup& parentLayoutImpl = GetImplementation( parentLayout );
+
+ unsigned int count = parent.GetChildCount();
+ unsigned int index = static_cast< unsigned int >( control.GetProperty< int >( DevelActor::Property::SIBLING_ORDER ) );
+
+ // Find insertion position
+ while( ++index < count )
+ {
+ auto sibling = Toolkit::Control::DownCast( parent.GetChildAt( index ) );
+ if( sibling )
+ {
+ auto siblingLayout = DevelControl::GetLayout( sibling );
+ if( siblingLayout )
+ {
+ Internal::LayoutItem& siblingLayoutImpl = GetImplementation( siblingLayout );
+ parentLayoutImpl.Insert( siblingLayoutImpl, *this );
+ break;
+ }
+ }
+ }
+
+ if( index >= count )
+ {
+ parentLayoutImpl.Add( *this );
+ }
+ }
+ }
}
}
+}
+void LayoutGroup::OnRegisterChildProperties( const std::string& containerType )
+{
DoRegisterChildProperties( containerType );
}
void LayoutGroup::OnUnparent()
{
+ // Remove children
RemoveAll();
}
+void LayoutGroup::RemoveChild( LayoutItem& item )
+{
+ item.SetParent( nullptr );
+ OnChildRemove( item );
+}
+
void LayoutGroup::ChildAddedToOwner( Actor child )
{
- LayoutBasePtr childLayout;
+ LayoutItemPtr childLayout;
Toolkit::Control control = Toolkit::Control::DownCast( child );
+#if defined(DEBUG_ENABLED)
+ auto parent = Toolkit::Control::DownCast( GetOwner() );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control(%s) owner(%s)\n", control?control.GetName().c_str():"Invalid", parent?parent.GetName().c_str():"Invalid" );
+#endif
+
if( control ) // Can only support adding Controls, not Actors to layout
{
Internal::Control& childControlImpl = GetImplementation( control );
if( ! childLayout )
{
- // If the child doesn't already have a layout, then create a LayoutBase for it.
- childLayout = LayoutBase::New( control );
+ // If the child doesn't already have a layout, then create a LayoutItem or LayoutGroup for it.
+ // If control behaviour flag set to Layout then set a LayoutGroup.
+ if( DevelControl::IsLayoutingRequired( control ) )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner Creating default LayoutGroup for control:%s\n", control?control.GetName().c_str():"Invalid" );
+ childLayout = LayoutGroup::New( control );
+ }
+ else
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner Creating default LayoutItem for control:%s\n", control?control.GetName().c_str():"Invalid" );
+ childLayout = LayoutItem::New( control );
+ }
childLayout->SetAnimateLayout( IsLayoutAnimated() ); // @todo this essentially forces animation inheritance. Bad?
- auto desiredSize = control.GetNaturalSize();
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control:" << control.GetName() <<
+ " desiredWidth: " << control.GetNaturalSize().width << " desiredHeight:" << control.GetNaturalSize().height );
+
childControlDataImpl.SetLayout( *childLayout.Get() );
- // HBoxLayout will apply default layout data for this object
- child.SetProperty( Toolkit::LayoutBase::ChildProperty::WIDTH_SPECIFICATION, LayoutLength::IntType( desiredSize.width ) );
- child.SetProperty( Toolkit::LayoutBase::ChildProperty::HEIGHT_SPECIFICATION, LayoutLength::IntType( desiredSize.height ) );
- child.SetProperty( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION, Extents() );
+ Vector3 size = child.GetTargetSize();
+ // If the size of the control is set explicitly make sure that the control size
+ // stays the same after the layout except it is over written with match parent specs.
+ if ( size.x != 0 )
+ {
+ childLayout->SetMinimumWidth( size.x );
+ }
+
+ if ( size.y != 0 )
+ {
+ childLayout->SetMinimumHeight( size.y );
+ }
+ // Default layout data will be generated by Add().
+ }
+ else
+ {
+ LayoutGroupPtr layoutGroup( dynamic_cast< LayoutGroup* >( childLayout.Get() ) );
+ if( !layoutGroup )
+ {
+ // Set only in case of leaf children
+ childLayout->SetAnimateLayout( IsLayoutAnimated() );
+ }
}
Add( *childLayout.Get() );
}
}
+void LayoutGroup::ChildOrderChanged( Actor child )
+{
+ Toolkit::Control childControl = Toolkit::Control::DownCast( child );
+ if( childControl )
+ {
+ Internal::Control& childControlImpl = GetImplementation( childControl );
+ Internal::Control::Impl& childControlDataImpl = Internal::Control::Impl::Get( childControlImpl );
+
+ auto childLayout = childControlDataImpl.GetLayout();
+ if( childLayout )
+ {
+ Toolkit::Control control = Toolkit::Control::DownCast( GetOwner() );
+ unsigned int count = control.GetChildCount();
+ unsigned int index = static_cast< unsigned int >( childControl.GetProperty< int >( DevelActor::Property::SIBLING_ORDER ) );
+
+ // Find insertion position
+ while( ++index < count )
+ {
+ auto sibling = Toolkit::Control::DownCast( control.GetChildAt( index ) );
+ if( sibling )
+ {
+ auto siblingLayout = DevelControl::GetLayout( sibling );
+ if( siblingLayout )
+ {
+ Internal::LayoutItem& siblingLayoutImpl = GetImplementation( siblingLayout );
+ Move( siblingLayoutImpl, *childLayout );
+ return;
+ }
+ }
+ }
+
+ MoveBack( *childLayout );
+ }
+ }
+}
+
void LayoutGroup::OnOwnerPropertySet( Handle& handle, Property::Index index, Property::Value value )
{
+ DALI_LOG_INFO( gLogFilter, Debug::Concise, "LayoutGroup::OnOwnerPropertySet\n");
auto actor = Actor::DownCast( handle );
- if( actor && index == Actor::Property::LAYOUT_DIRECTION )
+ if( actor &&
+ (
+ index == Actor::Property::LAYOUT_DIRECTION ||
+ index == Toolkit::Control::Property::PADDING ||
+ index == Toolkit::Control::Property::MARGIN
+ )
+ )
{
RequestLayout();
}
}
+void LayoutGroup::OnAnimationStateChanged( bool animateLayout )
+{
+ // Change children's animation state
+ for( auto&& child : mImpl->mChildren )
+ {
+ LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( child.child.Get() ) );
+ if( ! parentGroup )
+ {
+ // Change state only in case of leaf children
+ child.child->SetAnimateLayout( animateLayout );
+ }
+ }
+}
+
+void LayoutGroup::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec )
+{
+ auto childCount = GetChildCount();
+
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose,
+ "LayoutGroup::OnMeasure Actor Id:" << Actor::DownCast(GetOwner()).GetId() <<
+ " Owner:" << Actor::DownCast(GetOwner()).GetName() <<
+ " Child Count:" << childCount <<
+ " MeasureSpecs( width:"<<widthMeasureSpec<<", height:"<<heightMeasureSpec );
+
+ auto widthMode = widthMeasureSpec.GetMode();
+ auto heightMode = heightMeasureSpec.GetMode();
+ LayoutLength widthSpecSize = widthMeasureSpec.GetSize();
+ LayoutLength heightSpecSize = heightMeasureSpec.GetSize();
+
+ bool exactWidth ( false );
+ bool exactHeight ( false );
+
+ // Default Layouting behaviour if not overridden
+ // EXACT, width and height as provided.
+ // MATCH_PARENT, width and hewidthSpecSizeight that of parent
+
+ // WRAP_CONTENT, take width of widest child and height size of longest child (within given limit)
+ // UNSPECIFIED, take width of widest child and height size of longest child.
+
+ LayoutLength layoutWidth( 0 );
+ LayoutLength layoutHeight( 0 );
+
+ // If LayoutGroup has children then measure children to get max dimensions
+ if ( childCount > 0 )
+ {
+ for( unsigned int i=0; i<childCount; ++i )
+ {
+ auto childLayout = GetChildAt( i );
+ if( childLayout )
+ {
+ auto childOwner = childLayout->GetOwner();
+
+ // Get size of child
+ MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec );
+ LayoutLength childWidth = childLayout->GetMeasuredWidth();
+ LayoutLength childHeight = childLayout->GetMeasuredHeight();
+ Extents childMargin = childLayout->GetMargin();
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure child width[" << childWidth << "] height[" << childHeight << "]\n" );
+
+ layoutWidth = std::max( layoutWidth, childWidth + childMargin.start + childMargin.end );
+ layoutHeight = std::max( layoutHeight, childHeight + childMargin.top + childMargin.bottom );
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure calculated child width[" << layoutWidth << "] height[" << layoutHeight << "]\n" );
+ }
+ else
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure Not a layout\n" );
+ }
+ }
+
+ Extents padding = GetPadding();
+ layoutWidth += padding.start + padding.end;
+ layoutHeight += padding.top + padding.bottom;
+ }
+ else
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnMeasure Getting default size as a leaf\n" );
+ // LayoutGroup does not contain any children so must be a leaf
+ layoutWidth = GetDefaultSize( GetSuggestedMinimumWidth(), widthMeasureSpec );
+ layoutHeight = GetDefaultSize( GetSuggestedMinimumHeight(), heightMeasureSpec );
+ }
+
+ // Can't exceed specified width
+ if( widthMode == MeasureSpec::Mode::EXACTLY )
+ {
+ exactWidth = true;
+ }
+ else if ( widthMode == MeasureSpec::Mode::AT_MOST )
+ {
+ layoutWidth = std::min( layoutWidth, widthSpecSize );
+ }
+
+ // Can't exceed specified height
+ if( heightMode == MeasureSpec::Mode::EXACTLY )
+ {
+ exactHeight = true;
+ }
+ else if ( heightMode == MeasureSpec::Mode::AT_MOST )
+ {
+ layoutHeight = std::min( layoutHeight, heightSpecSize );
+ }
+
+ layoutWidth = std::max( layoutWidth, GetSuggestedMinimumWidth() );
+ layoutHeight = std::max( layoutHeight, GetSuggestedMinimumHeight() );
+
+ if( exactWidth )
+ {
+ layoutWidth = widthSpecSize;
+ }
+
+ if( exactHeight )
+ {
+ layoutHeight = heightSpecSize;
+ }
+
+ DALI_LOG_STREAM( gLogFilter, Debug::General, "LayoutGroup::OnMeasure Measured size(" << layoutWidth << "," << layoutHeight << ") for : " << Actor::DownCast(GetOwner()).GetName() << " \n" );
+ SetMeasuredDimensions( MeasuredSize( layoutWidth ), MeasuredSize( layoutHeight ) );
+}
+
+void LayoutGroup::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom )
+{
+ auto count = GetChildCount();
+
+ DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup OnLayout owner:" << ( ( Toolkit::Control::DownCast(GetOwner())) ? Toolkit::Control::DownCast(GetOwner()).GetName() : "invalid" ) << " childCount:" << count );
+
+ for( unsigned int childIndex = 0; childIndex < count; childIndex++)
+ {
+ LayoutItemPtr childLayout = GetChildAt( childIndex );
+ if( childLayout != nullptr )
+ {
+
+ auto childOwner = childLayout->GetOwner();
+ LayoutLength childWidth = childLayout->GetMeasuredWidth();
+ LayoutLength childHeight = childLayout->GetMeasuredHeight();
+ Extents childMargin = childLayout->GetMargin();
+ auto control = Toolkit::Control::DownCast( childOwner );
+ Extents padding = GetPadding();
+
+ auto childPosition = control.GetProperty< Vector3 >( Actor::Property::POSITION );
+ auto anchorPoint = control.GetProperty< Vector3 >( Actor::Property::ANCHOR_POINT );
+
+ DALI_LOG_STREAM( gLogFilter, Debug::General, "LayoutGroup::OnLayout child[" << control.GetName() <<
+ "] position(" << childPosition << ") child width[" << childWidth << "] height[" << childHeight << "]\n" );
+
+ // Margin and Padding only supported when child anchor point is TOP_LEFT.
+ int paddingAndMarginOffsetX = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.top + childMargin.top ) : 0;
+ int paddingAndMarginOffsetY = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.start + childMargin.start ) : 0;
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnLayout paddingMargin offset(%d,%d)\n", paddingAndMarginOffsetX, paddingAndMarginOffsetY );
+
+ LayoutLength childLeft = childPosition.x + paddingAndMarginOffsetX;
+ LayoutLength childTop = childPosition.y + paddingAndMarginOffsetY;
+
+ childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
+ }
+ }
+}
+
} // namespace Internal
} // namespace Toolkit