childLayout.child = &child;
mImpl->mChildren.emplace_back( childLayout );
+ child.SetParent( this );
+
auto owner = child.GetOwner();
// If the owner does not have any LayoutItem child properties, add them
{
if( iter->layoutId == childId )
{
- OnChildRemove( *iter->child.Get() );
+ RemoveChild( *iter->child.Get() );
mImpl->mChildren.erase(iter);
break;
}
{
if( iter->child.Get() == &child )
{
- OnChildRemove( *iter->child.Get() );
+ RemoveChild( *iter->child.Get() );
mImpl->mChildren.erase(iter);
break;
}
RequestLayout();
}
+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 )
+ {
+ 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() ; )
{
- OnChildRemove( *iter->child.Get() );
+ RemoveChild( *iter->child.Get() );
iter = mImpl->mChildren.erase(iter);
}
}
void LayoutGroup::OnSetChildProperties( Handle& handle, Property::Index index, Property::Value value )
{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties\n");
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties property(%s)\n", handle.GetPropertyName(index).c_str());
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->SetLayoutRequested();
+ child.child->RequestLayout();
break;
}
}
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 );
+
+ if( control.GetParent() )
+ {
+ 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::OnUnparent()
{
+ // Remove children
RemoveAll();
}
+void LayoutGroup::RemoveChild( LayoutItem& item )
+{
+ item.SetParent( nullptr );
+ OnChildRemove( item );
+}
+
void LayoutGroup::ChildAddedToOwner( Actor child )
{
LayoutItemPtr childLayout;
Toolkit::Control control = Toolkit::Control::DownCast( child );
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner(%s)\n", control.GetName().c_str() );
+
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control(%s)\n", control?control.GetName().c_str():"Invalid" );
if( control ) // Can only support adding Controls, not Actors to layout
{
#endif
childControlDataImpl.SetLayout( *childLayout.Get() );
+ 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");
}
}
+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 );
+ }
+ }
+}
+
} // namespace Internal
} // namespace Toolkit
} // namespace Dali