*/
// 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::Concise, false, "LOG_LAYOUT" );
+#endif
}
namespace Dali
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_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnSetChildProperties");
+
+ 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();
Toolkit::ChildLayoutData::WRAP_CONTENT );
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)
MeasureSpec parentWidthMeasureSpec,
MeasureSpec parentHeightMeasureSpec )
{
+ DALI_LOG_TRACE_METHOD( gLogFilter );
+
auto childOwner = child->GetOwner();
+
+ auto control = Toolkit::Control::DownCast( childOwner );
+
+#if defined( DEBUG_ENABLED )
+ if ( control )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChildWithMargins naturalSizewidth(%f)\n", control.GetNaturalSize().width );
+ }
+#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 );
- auto padding = GetPadding();
+ // The size of the control could have changed due to padding being altered, the XXX_SPECIFICATIONs will not have been updated.
+ // So GetNaturalSize is called, if the control's natural size includes padding then th size will be updated.
+ if ( control )
+ {
+ auto desiredSize = control.GetNaturalSize(); // Get's child control's size which could include new padding values.
+
+ // Check if WIDTH_SPECIFICATION was a size value, if so then get update to child controls's width.
+ if ( desiredWidth > 0 )
+ {
+ desiredWidth = desiredSize.width;
+ childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, LayoutLength::IntType( desiredWidth ) );
+ }
+
+ // Check if HEIGHT_SPECIFICATION was a size value, if so then get update to child controls's height.
+ if ( desiredHeight > 0)
+ {
+ desiredHeight = desiredSize.height;
+ childOwner.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, LayoutLength::IntType( desiredHeight ) );
+ }
+ }
+
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::MeasureChild desiredWidth(%d)\n", desiredWidth );
+
+ auto padding = GetPadding(); // Padding of this layout's owner, not of the child being measured.
const MeasureSpec childWidthMeasureSpec = GetChildMeasureSpec( parentWidthMeasureSpec,
padding.start + padding.end,
auto childOwner = child->GetOwner();
auto desiredWidth = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION );
auto desiredHeight = childOwner.GetProperty<int>( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION );
- auto desiredMargin = childOwner.GetProperty<Extents>( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION );
- auto padding = GetPadding();
+
+ 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 +
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 +
heightUsed, desiredHeight );
child->Measure( childWidthMeasureSpec, childHeightMeasureSpec );
auto specMode = measureSpec.GetMode();
LayoutLength specSize = measureSpec.GetSize();
- auto size = std::max( LayoutLength(0), specSize - padding );
+ auto size = std::max( LayoutLength(0), specSize - padding ); // reduce available size by the owners padding
MeasureSpec::IntType resultSize = 0;
MeasureSpec::Mode resultMode = MeasureSpec::Mode::UNSPECIFIED;
// 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
else
{
// Child wants a specific size... let him have it
- resultSize = childDimension;
+ resultSize = childDimension + padding;
resultMode = MeasureSpec::Mode::EXACTLY;
}
break;
}
}
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec resultSize(%u)\n", resultSize );
+
+
//noinspection ResourceType
return MeasureSpec( resultSize, resultMode );
}
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() )
- {
- ChildPropertyRegistration( typeInfo.GetName(), MARGIN_SPECIFICATION_NAME, Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION, Property::EXTENTS );
- }
- }
-
DoRegisterChildProperties( containerType );
}
{
LayoutItemPtr childLayout;
Toolkit::Control control = Toolkit::Control::DownCast( child );
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner(%s)\n", control.GetName().c_str() );
if( control ) // Can only support adding Controls, not Actors to layout
{
childLayout->SetAnimateLayout( IsLayoutAnimated() ); // @todo this essentially forces animation inheritance. Bad?
auto desiredSize = control.GetNaturalSize();
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner desiredSize(%f,%f) (naturalSize)\n", desiredSize.width, desiredSize.height );
+
childControlDataImpl.SetLayout( *childLayout.Get() );
- // HBoxLayout will apply default layout data for this object
+ // Default layout data for this object
child.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, LayoutLength::IntType( desiredSize.width ) );
child.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, LayoutLength::IntType( desiredSize.height ) );
- child.SetProperty( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION, Extents() );
}
Add( *childLayout.Get() );
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();
}
}
-
} // namespace Internal
} // namespace Toolkit
} // namespace Dali