From e8ea0328f92e38164592f09b9c978258622c0939 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Fri, 27 Apr 2018 17:08:45 +0100 Subject: [PATCH] Control Padding and Margin Properties used for layouts Layout base gets and sets padding and margin using Control Properties. Control::Property::PADDING Control::Property::MARGIN Extra logging and GetNaturalSize fix squashed in Change-Id: I4a8acbb2bf9761fea153581a66c1f76d620f852b --- .../src/dali-toolkit/utc-Dali-Layouting.cpp | 299 ++++++++++++++++++++- .../devel-api/layouting/layout-group-impl.cpp | 117 +++++--- .../devel-api/layouting/layout-item-impl.cpp | 43 ++- .../devel-api/layouting/layout-item-impl.h | 9 +- .../internal/layouting/hbox-layout-impl.cpp | 16 +- .../internal/layouting/layout-controller-impl.cpp | 11 + .../internal/layouting/layout-item-data-impl.cpp | 2 +- .../internal/layouting/layout-item-data-impl.h | 3 - .../internal/layouting/vbox-layout-impl.cpp | 7 +- 9 files changed, 451 insertions(+), 56 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp index 989ad95..deb8eb8 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp @@ -109,9 +109,6 @@ int UtcDaliLayouting_HboxLayout01(void) END_TEST; } - - - int UtcDaliLayouting_HboxLayout02(void) { ToolkitTestApplication application; @@ -317,9 +314,6 @@ int UtcDaliLayouting_HboxLayout03(void) END_TEST; } - - - int UtcDaliLayouting_HboxLayout04(void) { ToolkitTestApplication application; @@ -420,6 +414,299 @@ int UtcDaliLayouting_HboxLayout04(void) END_TEST; } +// Padding tests + +int UtcDaliLayouting_HboxLayout_Padding01(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliLayouting_HboxLayout_Padding01 - Adding Padding to a single child"); + + Stage stage = Stage::GetCurrent(); + auto hbox = Control::New(); + auto hboxLayout = HboxLayout::New(); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox"); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + controls.push_back( CreateLeafControl( 60, 40 ) ); + controls.push_back( CreateLeafControl( 80, 40 ) ); + controls.push_back( CreateLeafControl( 100, 40 ) ); + + const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 ); + tet_printf( "\nAdding Padding to control at index %u \n", 1 ); + controls[1].SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING ); + + for( auto&& iter : controls ) + { + hbox.Add( iter ); + } + hbox.SetParentOrigin( ParentOrigin::CENTER ); + hbox.SetAnchorPoint( AnchorPoint::CENTER ); + stage.Add( hbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + // hbox centers elements vertically, it fills test harness stage, which is 480x800. + // hbox left justifies elements + tet_infoline("Test Child Actor Position"); + float xPositionOfControlBeingTested = 0.0f; + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + 380.0f, + 0.0f ), 0.0001f, TEST_LOCATION ); + xPositionOfControlBeingTested += 40.0f; + + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + 380.0f - ( ( CONTROL_PADDING.top + CONTROL_PADDING.bottom) * 0.5f ), 0.0f ), + 0.0001f, TEST_LOCATION ); + + xPositionOfControlBeingTested += 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end; + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + xPositionOfControlBeingTested += 80.0f; + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,380.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + tet_infoline("Test Child Actor Size"); + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ), Vector3( 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end, + 40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom , 0.0f ), + 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliLayouting_HboxLayout_Padding02(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliLayouting_HboxLayout_Padding02 - Adding Padding to a all children"); + + Stage stage = Stage::GetCurrent(); + auto hbox = Control::New(); + auto hboxLayout = HboxLayout::New(); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox"); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + controls.push_back( CreateLeafControl( 60, 40 ) ); + controls.push_back( CreateLeafControl( 80, 40 ) ); + controls.push_back( CreateLeafControl( 100, 40 ) ); + + const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 ); + + for( auto&& iter : controls ) + { + iter.SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING ); + hbox.Add( iter ); + } + hbox.SetParentOrigin( ParentOrigin::CENTER ); + hbox.SetAnchorPoint( AnchorPoint::CENTER ); + stage.Add( hbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + // hbox centers elements vertically, it fills test harness stage, which is 480x800. + // hbox left justifies elements + tet_infoline("Test Child Actor Position"); + float xPositionOfControlBeingTested = 0.0f; + float yPositionOfControlBeingTested = ( 800.0f * 0.5) - ( 0.5 * ( 40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom ) ); + + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + yPositionOfControlBeingTested, + 0.0f ), 0.0001f, TEST_LOCATION ); + xPositionOfControlBeingTested += 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end; + + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + yPositionOfControlBeingTested, + 0.0f ), + 0.0001f, TEST_LOCATION ); + + xPositionOfControlBeingTested += 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end; + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + yPositionOfControlBeingTested, + 0.0f ), 0.0001f, TEST_LOCATION ); + + xPositionOfControlBeingTested += 80.0f + CONTROL_PADDING.start + CONTROL_PADDING.end; + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + yPositionOfControlBeingTested, + 0.0f ), 0.0001f, TEST_LOCATION ); + + tet_infoline("Test Child Actor Size"); + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end, + 40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom, + 0.0f ), 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ), Vector3( 60.0f + CONTROL_PADDING.start + CONTROL_PADDING.end, + 40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom, + 0.0f ), 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::SIZE ), Vector3( 80.0f + CONTROL_PADDING.start + CONTROL_PADDING.end , + 40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom, + 0.0f ), 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f + CONTROL_PADDING.start + CONTROL_PADDING.end, + 40.0f + CONTROL_PADDING.top + CONTROL_PADDING.bottom, + 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliLayouting_HboxLayout_Padding03(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliLayouting_HboxLayout_Padding03 - Adding Changing padding on a single child"); + + Stage stage = Stage::GetCurrent(); + auto hbox = Control::New(); + auto hboxLayout = HboxLayout::New(); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox"); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + controls.push_back( CreateLeafControl( 40, 40 ) ); + controls.push_back( CreateLeafControl( 40, 40 ) ); + + const Extents CONTROL_PADDING = Extents(5, 10, 20, 2 ); + tet_printf( "\nAdding Padding to control at index 1 \n" ); + controls[1].SetProperty(Toolkit::Control::Property::PADDING, CONTROL_PADDING ); + + for( auto&& iter : controls ) + { + hbox.Add( iter ); + } + hbox.SetParentOrigin( ParentOrigin::CENTER ); + hbox.SetAnchorPoint( AnchorPoint::CENTER ); + stage.Add( hbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + // hbox centers elements vertically, it fills test harness stage, which is 480x800. + // hbox left justifies elements + tet_infoline("Test Child Actor Position"); + float xPositionOfControlBeingTested = 0.0f; + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + 380.0f, + 0.0f ), 0.0001f, TEST_LOCATION ); + xPositionOfControlBeingTested += 40.0f; + + DALI_TEST_EQUALS( controls[ 1 ].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + 380.0f - ( ( CONTROL_PADDING.top + CONTROL_PADDING.bottom) * 0.5f ), 0.0f ), + 0.0001f, TEST_LOCATION ); + + xPositionOfControlBeingTested += 40.0f + CONTROL_PADDING.start + CONTROL_PADDING.end; + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + const Extents NEW_CONTROL_PADDING = Extents(10, 10, 20, 2 ); + tet_printf( "\nChanging Padding to control at index 1 \n" ); + controls[1].SetProperty(Toolkit::Control::Property::PADDING, NEW_CONTROL_PADDING ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + xPositionOfControlBeingTested = 0.0f; // reset + + tet_infoline("Test Child Actor Position"); + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + 380.0f, + 0.0f ), 0.0001f, TEST_LOCATION ); + xPositionOfControlBeingTested += 40.0f; + + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + 380.0f - ( ( NEW_CONTROL_PADDING.top + NEW_CONTROL_PADDING.bottom) * 0.5f ), 0.0f ), + 0.0001f, TEST_LOCATION ); + + xPositionOfControlBeingTested += 40.0f + NEW_CONTROL_PADDING.start + NEW_CONTROL_PADDING.end; + tet_printf( "\nIf x position %u then change has not been processed \n", 40 + 40 + CONTROL_PADDING.start + CONTROL_PADDING.end ); + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + tet_infoline("Test Child Actor Size"); + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ) , Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ) , Vector3( 40.0f + NEW_CONTROL_PADDING.start + NEW_CONTROL_PADDING.end, + 40.0f + NEW_CONTROL_PADDING.top + NEW_CONTROL_PADDING.bottom , 0.0f ), + 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::SIZE ) , Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + +// Margin Tests + +int UtcDaliLayouting_HboxLayout_Margin01(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliLayouting_HboxLayout_Margin01 - Adding a margin to a single child"); + + Stage stage = Stage::GetCurrent(); + auto hbox = Control::New(); + auto hboxLayout = HboxLayout::New(); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox"); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + controls.push_back( CreateLeafControl( 60, 40 ) ); + controls.push_back( CreateLeafControl( 80, 40 ) ); + controls.push_back( CreateLeafControl( 100, 40 ) ); + + const Extents CONTROL_MARGIN = Extents(5, 10, 20, 0 ); + tet_printf( "\nAdding Margin to control at index 1 \n" ); + controls[1].SetProperty(Toolkit::Control::Property::MARGIN, CONTROL_MARGIN ); + + for( auto&& iter : controls ) + { + hbox.Add( iter ); + } + hbox.SetParentOrigin( ParentOrigin::CENTER ); + hbox.SetAnchorPoint( AnchorPoint::CENTER ); + stage.Add( hbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + // hbox centers elements vertically, it fills test harness stage, which is 480x800. + // hbox left justifies elements + tet_infoline("Test Child Actor Position"); + auto xPositionOfControlBeingTested = 0.0f; + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + 380.0f, + 0.0f ), 0.0001f, TEST_LOCATION ); + xPositionOfControlBeingTested += 40.0f + CONTROL_MARGIN.start; + + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, + 380.0f + CONTROL_MARGIN.top, 0.0f ), + 0.0001f, TEST_LOCATION ); + + xPositionOfControlBeingTested += 60.0f + CONTROL_MARGIN.end; + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested, 380.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + xPositionOfControlBeingTested += 80.0f; + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::POSITION ), Vector3( xPositionOfControlBeingTested,380.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + tet_infoline("Test Child Actor Size is the same after Margin added"); + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[1].GetProperty( Actor::Property::SIZE ), Vector3( 60.0f, 40.0f , 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[2].GetProperty( Actor::Property::SIZE ), Vector3( 80.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[3].GetProperty( Actor::Property::SIZE ), Vector3( 100.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliLayouting_VboxLayout01(void) { diff --git a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp index 21fb391..9df05c6 100644 --- a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp @@ -15,18 +15,24 @@ */ // CLASS HEADER +#include + +// EXTERNAL INCLUDES #include #include #include -#include +#include + +// INTERNAL INCLUDES #include #include #include - 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 @@ -176,7 +182,12 @@ void LayoutGroup::DoRegisterChildProperties( const std::string& containerType ) 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(); @@ -189,7 +200,6 @@ void LayoutGroup::GenerateDefaultChildPropertyValues( Handle child ) 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) @@ -207,11 +217,47 @@ void LayoutGroup::MeasureChild( LayoutItemPtr child, 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( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); auto desiredHeight = childOwner.GetProperty( 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, @@ -230,17 +276,20 @@ void LayoutGroup::MeasureChildWithMargins( LayoutItemPtr child, auto childOwner = child->GetOwner(); auto desiredWidth = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION ); auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); - auto desiredMargin = childOwner.GetProperty( 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 ); @@ -255,7 +304,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( 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; @@ -265,15 +314,19 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( // 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; @@ -281,6 +334,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( } else { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::GetChildMeasureSpec childDimension UNSPECIFIED\n"); resultSize = childDimension; resultMode = MeasureSpec::Mode::EXACTLY; } @@ -291,6 +345,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( // 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. @@ -308,7 +363,7 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( else { // Child wants a specific size... so be it - resultSize = childDimension; + resultSize = childDimension + padding; resultMode = MeasureSpec::Mode::EXACTLY; } @@ -318,6 +373,8 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( // 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 @@ -334,13 +391,16 @@ MeasureSpec LayoutGroup::GetChildMeasureSpec( 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 ); } @@ -366,19 +426,6 @@ void LayoutGroup::OnInitialize() 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 ); } @@ -391,6 +438,7 @@ 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() ); if( control ) // Can only support adding Controls, not Actors to layout { @@ -405,12 +453,13 @@ void LayoutGroup::ChildAddedToOwner( Actor child ) 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() ); @@ -434,14 +483,20 @@ void LayoutGroup::ChildRemovedFromOwner( Actor child ) 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 diff --git a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp index e31045f..be5b0ed 100644 --- a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp @@ -22,12 +22,13 @@ #include #include +namespace +{ + #if defined(DEBUG_ENABLED) - Debug::Filter* gLayoutFilter = Debug::Filter::New( Debug::Verbose, false, "LOG_LAYOUT" ); +Debug::Filter* gLayoutFilter = Debug::Filter::New( Debug::Verbose, false, "LOG_LAYOUT" ); #endif -namespace -{ const char* WIDTH_SPECIFICATION_NAME( "widthSpecification" ); const char* HEIGHT_SPECIFICATION_NAME( "heightSpecification" ); @@ -121,6 +122,8 @@ void LayoutItem::OnRegisterChildProperties( const std::string& containerType ) void LayoutItem::Measure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) { + DALI_LOG_TRACE_METHOD( gLayoutFilter ); + const bool forceLayout = mImpl->GetPrivateFlag( Impl::PRIVATE_FLAG_FORCE_LAYOUT ); const bool specChanged = @@ -199,7 +202,34 @@ void LayoutItem::SetMinimumHeight( LayoutLength minimumHeight ) Extents LayoutItem::GetPadding() const { - return mImpl->mPadding; + Toolkit::Control control = Toolkit::Control::DownCast( mImpl->mOwner ); + if( control ) + { + Extents padding = control.GetProperty( Toolkit::Control::Property::PADDING ); + + DALI_LOG_INFO( gLayoutFilter, Debug::Verbose, "LayoutBase::Padding for %s : (%d,%d,%d,%d) \n", + control.GetName().c_str(), + padding.start, padding.end, padding.top, padding.bottom + ); + return padding; + } + else + { + return Extents(); + } +} + +Extents LayoutItem::GetMargin() const +{ + Toolkit::Control control = Toolkit::Control::DownCast( mImpl->mOwner ); + if ( control ) + { + return control.GetProperty( Toolkit::Control::Property::MARGIN ); + } + else + { + return Extents(); + } } LayoutLength LayoutItem::GetDefaultSize( LayoutLength size, MeasureSpec measureSpec ) @@ -255,6 +285,11 @@ bool LayoutItem::IsLayoutRequested() const void LayoutItem::SetMeasuredDimensions( MeasuredSize measuredWidth, MeasuredSize measuredHeight ) { + DALI_LOG_INFO( gLayoutFilter, Debug::Verbose, "LayoutBase::SetMeasuredDimensions width(%d) height(%d) \n", + MeasureSpec::IntType( measuredWidth.GetSize() ), + MeasureSpec::IntType( measuredHeight.GetSize() ) + ); + mImpl->SetPrivateFlag( Impl::PRIVATE_FLAG_MEASURED_DIMENSION_SET ); mImpl->mMeasuredWidth = measuredWidth; mImpl->mMeasuredHeight = measuredHeight; diff --git a/dali-toolkit/devel-api/layouting/layout-item-impl.h b/dali-toolkit/devel-api/layouting/layout-item-impl.h index fb12913..e91e7f9 100644 --- a/dali-toolkit/devel-api/layouting/layout-item-impl.h +++ b/dali-toolkit/devel-api/layouting/layout-item-impl.h @@ -289,11 +289,17 @@ public: LayoutLength GetMinimumHeight() const; /** - * Get the padding information + * Get the padding information. * @return The padding information */ Extents GetPadding() const; + /** + * Get the margin information. + * @return The margin information + */ + Extents GetMargin() const; + protected: /** * @brief Allow directly deriving classes to remove layout children when unparented @@ -307,7 +313,6 @@ protected: */ virtual void OnRegisterChildProperties( const std::string& containerType ); - /** * @brief Measure the layout and its content to determine the measured width and the * measured height. diff --git a/dali-toolkit/internal/layouting/hbox-layout-impl.cpp b/dali-toolkit/internal/layouting/hbox-layout-impl.cpp index ca86db6..0caf08d 100644 --- a/dali-toolkit/internal/layouting/hbox-layout-impl.cpp +++ b/dali-toolkit/internal/layouting/hbox-layout-impl.cpp @@ -26,10 +26,12 @@ #include #include - +namespace +{ #if defined(DEBUG_ENABLED) static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_LAYOUT" ); #endif +} namespace Dali { @@ -106,6 +108,8 @@ void HboxLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeas DALI_LOG_INFO( gLogFilter, Debug::Concise, oss.str().c_str() ); #endif + DALI_LOG_INFO( gLogFilter, Debug::Concise, "HboxLayout::OnMeasure widthSize(%d) \n", widthMeasureSpec.GetSize()); + auto widthMode = widthMeasureSpec.GetMode(); auto heightMode = heightMeasureSpec.GetMode(); bool isExactly = (widthMode == MeasureSpec::Mode::EXACTLY); @@ -128,9 +132,12 @@ void HboxLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeas auto childOwner = childLayout->GetOwner(); auto desiredHeight = childOwner.GetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION ); - MeasureChildWithMargins( childLayout, widthMeasureSpec, 0, heightMeasureSpec, 0 ); + MeasureChild( childLayout, widthMeasureSpec, heightMeasureSpec ); auto childWidth = childLayout->GetMeasuredWidth(); - auto childMargin = childOwner.GetProperty( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION ); + auto childMargin = childLayout->GetMargin(); + + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "HboxLayout::OnMeasure childWidth(%d)\n", MeasureSpec::IntType( childWidth ) ); + auto length = childWidth + LayoutLength::IntType(childMargin.start + childMargin.end); auto cellPadding = iGetMeasuredWidth(); auto childHeight = childLayout->GetMeasuredHeight(); - auto childOwner = childLayout->GetOwner(); - auto childMargin = childOwner.GetProperty( Toolkit::LayoutGroup::ChildProperty::MARGIN_SPECIFICATION ); + auto childMargin = childLayout->GetMargin(); childTop = LayoutLength(padding.top) + ((childSpace - childHeight) / 2) + childMargin.top - childMargin.bottom; diff --git a/dali-toolkit/internal/layouting/layout-controller-impl.cpp b/dali-toolkit/internal/layouting/layout-controller-impl.cpp index 90f125b..0ca1847 100644 --- a/dali-toolkit/internal/layouting/layout-controller-impl.cpp +++ b/dali-toolkit/internal/layouting/layout-controller-impl.cpp @@ -25,10 +25,15 @@ using namespace Dali; +namespace +{ + #if defined(DEBUG_ENABLED) static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_LAYOUT" ); #endif +} + namespace Dali { namespace Toolkit @@ -105,7 +110,9 @@ void LayoutController::MeasureHierarchy( Actor root, MeasureSpec widthSpec, Meas Toolkit::Control control = Toolkit::Control::DownCast( root ); if( control ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::Measuring leaf\n" ); Internal::Control& controlImpl = GetImplementation( control ); + Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl ); LayoutItemPtr layout = controlDataImpl.GetLayout(); @@ -116,6 +123,7 @@ void LayoutController::MeasureHierarchy( Actor root, MeasureSpec widthSpec, Meas } else { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::Measuring (%u) children\n", root.GetChildCount() ); // Depth first descent through actor children for( unsigned int i = 0, count = root.GetChildCount(); i < count; ++i ) { @@ -130,17 +138,20 @@ void LayoutController::PerformLayout( Actor root, int left, int top, int right, Toolkit::Control control = Toolkit::Control::DownCast( root ); if( control ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::PerformLayout on leaf\n" ); Internal::Control& controlImpl = GetImplementation( control ); Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl ); LayoutItemPtr layout = controlDataImpl.GetLayout(); if( layout ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::PerformLayout on layout\n" ); layout->Layout( left, top, right, bottom ); } } else { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::PerformLayout (%u) children\n", root.GetChildCount() ); // Depth first descent through actor children for( unsigned int i = 0, count = root.GetChildCount(); i < count; ++i ) { diff --git a/dali-toolkit/internal/layouting/layout-item-data-impl.cpp b/dali-toolkit/internal/layouting/layout-item-data-impl.cpp index d3b394d..cd0460d 100644 --- a/dali-toolkit/internal/layouting/layout-item-data-impl.cpp +++ b/dali-toolkit/internal/layouting/layout-item-data-impl.cpp @@ -41,7 +41,7 @@ LayoutItem::Impl::Impl() mBottom( 0 ), mViewFlags( 0 ), mPrivateFlags( 0 ), - mAnimated(false) + mAnimated( false ) { } diff --git a/dali-toolkit/internal/layouting/layout-item-data-impl.h b/dali-toolkit/internal/layouting/layout-item-data-impl.h index 3758460..0e5c0e7 100644 --- a/dali-toolkit/internal/layouting/layout-item-data-impl.h +++ b/dali-toolkit/internal/layouting/layout-item-data-impl.h @@ -46,9 +46,6 @@ public: MeasuredSize mMeasuredWidth; MeasuredSize mMeasuredHeight; - Extents mMargin; ///< Distances in pixels from the edges of this view to this view's parent. - Extents mPadding; ///< Distances in pixels from the edges of this view to this view's content. - LayoutLength mLeft; LayoutLength mRight; LayoutLength mTop; diff --git a/dali-toolkit/internal/layouting/vbox-layout-impl.cpp b/dali-toolkit/internal/layouting/vbox-layout-impl.cpp index 56fb230..3097a21 100644 --- a/dali-toolkit/internal/layouting/vbox-layout-impl.cpp +++ b/dali-toolkit/internal/layouting/vbox-layout-impl.cpp @@ -17,7 +17,6 @@ //CLASS HEADER #include -//EXTERNAL HEADERS //INTERNAL HEADERS #include #include @@ -27,10 +26,12 @@ #include #include - +namespace +{ #if defined(DEBUG_ENABLED) static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_LAYOUT" ); #endif +} namespace Dali { @@ -165,7 +166,6 @@ void VboxLayout::OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeas alternativeMaxWidth = std::max( alternativeMaxWidth, matchWidthLocally ? marginWidth : childWidth ); } } - Extents padding = GetPadding(); mTotalLength += padding.top + padding.bottom; auto heightSize = mTotalLength; @@ -223,7 +223,6 @@ void VboxLayout::ForceUniformWidth( int count, MeasureSpec heightMeasureSpec ) void VboxLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom ) { - auto owner = GetOwner(); Extents padding = GetPadding(); LayoutLength childTop( 0 ); -- 2.7.4