From: agnelo vaz Date: Tue, 4 Sep 2018 18:13:48 +0000 (+0100) Subject: API for Control to set LayoutRequired flag X-Git-Tag: dali_1.3.41~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=refs%2Fchanges%2F06%2F188406%2F7 API for Control to set LayoutRequired flag Control behaviour can be set to need a layout and use the Layout system or not and use the legacy size negotiation. Change-Id: I90848cc238d8857d9ea380d9a6d5f6d82a431085 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp index 28ada5a..6e8cc16 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp @@ -2788,19 +2788,21 @@ int UtcDaliLayouting_LayoutGroup01(void) DevelControl::SetLayout( hbox, hboxLayout ); hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 ); hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); + DevelControl::SetLayoutingRequired( hbox, true ); hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // LinearLayout will eventually do this internally. - tet_infoline("Add a control without SetLayout being called"); + tet_infoline("Add a control without SetLayout being called but with layout required set true"); auto control = Control::New(); control.SetName("Control1"); + DevelControl::SetLayoutingRequired( control, true ); hbox.Add( control ); control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); - tet_infoline("Add a Textlabel to the control"); auto textLabel = TextLabel::New("Test text"); textLabel.SetName("TextLabel"); + control.Add( textLabel ); // Ensure layouting happens @@ -2826,17 +2828,18 @@ int UtcDaliLayouting_LayoutGroup02(void) // Create a parent layout auto hbox = Control::New(); auto hboxLayout = LinearLayout::New(); + DevelControl::SetLayout( hbox, hboxLayout ); hbox.SetName( "HBox"); rootControl.Add( hbox ); - DevelControl::SetLayout( hbox, hboxLayout ); hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 ); hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // LinearLayout will eventually do this internally. - tet_infoline("Add a control without SetLayout being called"); + tet_infoline("Add a control without SetLayout being called but with layout required set true"); auto control = Control::New(); control.SetName("Control1"); + DevelControl::SetLayoutingRequired( control, true ); hbox.Add( control ); control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); @@ -2874,7 +2877,7 @@ int UtcDaliLayouting_LayoutGroup02(void) int UtcDaliLayouting_LayoutGroup03(void) { ToolkitTestApplication application; - tet_infoline("UtcDaliLayouting_LayoutGroup03 - Test control witha LayoutGroup as a leaf"); + tet_infoline("UtcDaliLayouting_LayoutGroup03 - Test control with a LayoutGroup as a leaf"); Control rootControl; SetupRootLayoutControl( rootControl ); @@ -2882,9 +2885,47 @@ int UtcDaliLayouting_LayoutGroup03(void) // Create a parent layout auto hbox = Control::New(); auto hboxLayout = LinearLayout::New(); + DevelControl::SetLayout( hbox, hboxLayout ); hbox.SetName( "HBox"); rootControl.Add( hbox ); + hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 ); + hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); + hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // LinearLayout will eventually do this internally. + + tet_infoline("Add a control without SetLayout being called"); + + auto control = Control::New(); + control.SetName("Control1"); + hbox.Add( control ); + control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 100 ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + tet_infoline("Test control is width of it's parent and exact given height"); + DALI_TEST_EQUALS( control.GetProperty( Actor::Property::SIZE ), Vector3( 600.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( control.GetProperty( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliLayouting_LayoutGroup04(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliLayouting_LayoutGroup04 - Test control with a LayoutGroup as a leaf and with SetLayotRequired = true"); + + Control rootControl; + SetupRootLayoutControl( rootControl ); + + // Create a parent layout + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox"); + rootControl.Add( hbox ); hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 ); hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // LinearLayout will eventually do this internally. @@ -2893,6 +2934,7 @@ int UtcDaliLayouting_LayoutGroup03(void) auto control = Control::New(); control.SetName("Control1"); + DevelControl::SetLayoutingRequired( control, true ); hbox.Add( control ); control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 100 ); @@ -2908,6 +2950,44 @@ int UtcDaliLayouting_LayoutGroup03(void) END_TEST; } +int UtcDaliLayouting_IsLayoutingRequired(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliLayouting_IsLayoutingRequired - Test setting the SetLayoutRequired and then check if flag was set"); + + Control rootControl; + SetupRootLayoutControl( rootControl ); + + // Create a parent layout + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "HBox"); + rootControl.Add( hbox ); + hbox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 600 ); + hbox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); + hbox.SetAnchorPoint( AnchorPoint::TOP_LEFT ); // LinearLayout will eventually do this internally. + + tet_infoline("Add a control without SetLayout being called"); + + auto control = Control::New(); + control.SetName("Control1"); + DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), false, TEST_LOCATION ); + DevelControl::SetLayoutingRequired( control, true ); + hbox.Add( control ); + control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 100 ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + tet_infoline("Test control is width of it's parent and exact given height"); + DALI_TEST_EQUALS( DevelControl::IsLayoutingRequired( control ), true, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliLayouting_LayoutGroupWithPadding01(void) { ToolkitTestApplication application; @@ -2930,6 +3010,7 @@ int UtcDaliLayouting_LayoutGroupWithPadding01(void) auto control = Control::New(); control.SetName("Control1"); + DevelControl::SetLayoutingRequired( control, true ); hbox.Add( control ); control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); @@ -2977,6 +3058,7 @@ int UtcDaliLayouting_LayoutGroupWithChildMargin01(void) auto control = Control::New(); control.SetName("Control1"); + DevelControl::SetLayoutingRequired( control, true ); hbox.Add( control ); control.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); control.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT ); diff --git a/dali-toolkit/devel-api/controls/control-devel.cpp b/dali-toolkit/devel-api/controls/control-devel.cpp index 01f240f..c17b944 100755 --- a/dali-toolkit/devel-api/controls/control-devel.cpp +++ b/dali-toolkit/devel-api/controls/control-devel.cpp @@ -152,6 +152,19 @@ void RequestLayout( Internal::Control& control ) layoutItem->RequestLayout(); } } +void SetLayoutingRequired( Control control, bool layoutingRequired ) +{ + Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control ); + Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( internalControl ); + controlDataImpl.SetLayoutingRequired( layoutingRequired ); +} + +bool IsLayoutingRequired( Control control ) +{ + Internal::Control& internalControl = Toolkit::Internal::GetImplementation( control ); + Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( internalControl ); + return controlDataImpl.IsLayoutingRequired(); +} } // namespace DevelControl diff --git a/dali-toolkit/devel-api/controls/control-devel.h b/dali-toolkit/devel-api/controls/control-devel.h index 879c767..e2fcc86 100755 --- a/dali-toolkit/devel-api/controls/control-devel.h +++ b/dali-toolkit/devel-api/controls/control-devel.h @@ -307,6 +307,20 @@ DALI_TOOLKIT_API void SetLayout( Control control, Toolkit::LayoutItem layout ); */ DALI_TOOLKIT_API void RequestLayout( Internal::Control& control ); +/** + * @brief Set whether the control should have a layout + * @param[in] control The Control to set the behaviour on + * @param[in] layoutingRequired true if the control should have a layout + */ +DALI_TOOLKIT_API void SetLayoutingRequired( Control control, bool layoutingRequired ); + +/** + * @brief Check if the control has been set to require layouting + * @param[in] control The Control to query + * @return true if the control needs layouting + */ +DALI_TOOLKIT_API bool IsLayoutingRequired( Control control ); + } // namespace DevelControl } // namespace Toolkit diff --git a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp index 9f54f56..8cdd8bc 100644 --- a/dali-toolkit/devel-api/layouting/layout-group-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-group-impl.cpp @@ -588,13 +588,25 @@ void LayoutGroup::ChildAddedToOwner( Actor child ) if( ! childLayout ) { - // If the child doesn't already have a layout, then create a LayoutItem for it. - childLayout = LayoutGroup::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? -#if defined(DEBUG_ENABLED) - auto desiredSize = control.GetNaturalSize(); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner desiredSize(%f,%f) (naturalSize)\n", desiredSize.width, desiredSize.height ); -#endif + + DALI_LOG_STREAM( gLogFilter, Debug::Verbose, "LayoutGroup::ChildAddedToOwner control:" << control.GetName().c_str() << + " desiredWidth: " << control.GetNaturalSize().width << + " desiredHeight:" << control.GetNaturalSize().height + ); + childControlDataImpl.SetLayout( *childLayout.Get() ); Vector3 size = child.GetTargetSize(); @@ -698,7 +710,7 @@ void LayoutGroup::OnAnimationStateChanged( bool animateLayout ) for( auto&& child : mImpl->mChildren ) { LayoutGroupPtr parentGroup( dynamic_cast< LayoutGroup* >( child.child.Get() ) ); - if( parentGroup && ( 0 == parentGroup->GetChildCount() ) ) // A leaf LayoutGroup will have no children. + if( ! parentGroup ) { // Change state only in case of leaf children child.child->SetAnimateLayout( animateLayout ); @@ -708,14 +720,14 @@ void LayoutGroup::OnAnimationStateChanged( bool 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:"<( Actor::Property::POSITION ); auto anchorPoint = control.GetProperty< Vector3 >( Actor::Property::ANCHOR_POINT ); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutGroup::OnLayout child[%s] position(%f,%f)\n", control.GetName().c_str(), childPosition.x, childPosition.y ); + DALI_LOG_INFO( gLogFilter, Debug::General, "LayoutGroup::OnLayout child[%s] position(%f,%f) child width[%d] height(%d)\n", + control.GetName().c_str(), + childPosition.x, childPosition.y, + childWidth.mValue, childHeight.mValue + ); // Margin and Padding only supported when child anchor point is TOP_LEFT. int paddingAndMarginOffsetX = ( AnchorPoint::TOP_LEFT == anchorPoint ) ? ( padding.top + childMargin.top ) : 0; diff --git a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp index 85fab8a..987b799 100644 --- a/dali-toolkit/devel-api/layouting/layout-item-impl.cpp +++ b/dali-toolkit/devel-api/layouting/layout-item-impl.cpp @@ -95,15 +95,11 @@ void LayoutItem::Unparent() void LayoutItem::SetAnimateLayout( bool animateLayout ) { - DALI_LOG_INFO( gLayoutFilter, Debug::Verbose, "LayoutItem::SetAnimateLayout animateLayout(%s)\n", (animateLayout)?"true":"false" ); - auto owner = GetOwner(); auto actor = Actor::DownCast(owner); - if( actor ) - { - DALI_LOG_INFO( gLayoutFilter, Debug::Verbose, "LayoutItem::SetAnimateLayout animateLayout(%s) owner(%s)\n", (animateLayout)?"true":"false", actor.GetName().c_str() ); - } + DALI_LOG_INFO( gLayoutFilter, Debug::Verbose, "LayoutItem::SetAnimateLayout animateLayout(%s) owner(%s)\n", (animateLayout)?"true":"false", + ( ( Actor::DownCast( owner) ) ? Actor::DownCast(owner).GetName().c_str() : "Invalid Actor" ) ); mImpl->mAnimated = animateLayout; @@ -163,7 +159,7 @@ void LayoutItem::Measure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasur const bool needsLayout = specChanged && ( !isSpecExactly || !matchesSpecSize ); - DALI_LOG_STREAM( gLayoutFilter, Debug::Verbose, "LayoutItem::Measure("<ClearPrivateFlag( Impl::PRIVATE_FLAG_MEASURE_NEEDED_BEFORE_LAYOUT ); // flag not set, setMeasuredDimension() was not invoked, we raise an exception to warn the developer DALI_ASSERT_ALWAYS( mImpl->GetPrivateFlag( Impl::PRIVATE_FLAG_MEASURED_DIMENSION_SET ) && - "Layout's OnMeasure() mension()" ); + "Layout's OnMeasure() Measured dimension flag not set" ); mImpl->SetPrivateFlag( Impl::PRIVATE_FLAG_LAYOUT_REQUIRED ); } diff --git a/dali-toolkit/internal/controls/control/control-data-impl.cpp b/dali-toolkit/internal/controls/control/control-data-impl.cpp index cbeb4c5..12f09c8 100755 --- a/dali-toolkit/internal/controls/control/control-data-impl.cpp +++ b/dali-toolkit/internal/controls/control/control-data-impl.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -339,7 +340,8 @@ Control::Impl::Impl( Control& controlImpl ) mInputMethodContext(), mFlags( Control::ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), mIsKeyboardNavigationSupported( false ), - mIsKeyboardFocusGroup( false ) + mIsKeyboardFocusGroup( false ), + mIsLayoutingRequired( false ) { } @@ -1457,6 +1459,16 @@ void Control::Impl::RemoveLayout() } } +void Control::Impl::SetLayoutingRequired( bool layoutingRequired ) +{ + mControlImpl.mImpl->mIsLayoutingRequired = layoutingRequired; +} + +bool Control::Impl::IsLayoutingRequired() +{ + return mControlImpl.mImpl->mIsLayoutingRequired; +} + } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/control/control-data-impl.h b/dali-toolkit/internal/controls/control/control-data-impl.h index d2eb48e..1afa0a2 100755 --- a/dali-toolkit/internal/controls/control/control-data-impl.h +++ b/dali-toolkit/internal/controls/control/control-data-impl.h @@ -345,6 +345,16 @@ public: */ void RemoveLayout(); + /** + * @copydoc DevelControl::SetLayoutingRequired + */ + void SetLayoutingRequired( bool layoutingRequired ); + + /** + * @copydoc DevelControl::IsLayoutingRequired() + */ + bool IsLayoutingRequired(); + private: /** @@ -423,6 +433,7 @@ public: ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor. bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control. bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group. + bool mIsLayoutingRequired :1; ///< Stores whether the control needs to be Layout RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready diff --git a/dali-toolkit/internal/layouting/absolute-layout-impl.cpp b/dali-toolkit/internal/layouting/absolute-layout-impl.cpp index 14fed57..5c5989d 100644 --- a/dali-toolkit/internal/layouting/absolute-layout-impl.cpp +++ b/dali-toolkit/internal/layouting/absolute-layout-impl.cpp @@ -157,6 +157,12 @@ void AbsoluteLayout::OnLayout( bool changed, LayoutLength left, LayoutLength top auto childTop = childPosition.y; auto childLeft = childPosition.x; + DALI_LOG_INFO( gLogFilter, Debug::General, "AbsoluteLayout::OnLayout child[%s] position(%f,%f) child width[%d] height(%d)\n", + Toolkit::Control::DownCast( childOwner ).GetName().c_str(), + childPosition.x, childPosition.y, + childWidth.mValue, childHeight.mValue + ); + childLayout->Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight ); } } diff --git a/dali-toolkit/internal/layouting/layout-controller-impl.cpp b/dali-toolkit/internal/layouting/layout-controller-impl.cpp index 0e8d925..cfceb62 100644 --- a/dali-toolkit/internal/layouting/layout-controller-impl.cpp +++ b/dali-toolkit/internal/layouting/layout-controller-impl.cpp @@ -110,7 +110,7 @@ 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 control\n" ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "LayoutController::Measuring control:%s\n", control.GetName().c_str() ); Internal::Control& controlImpl = GetImplementation( control ); Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl );