Actor's position and size is not updated after DevelControl::SetLayout. 49/188149/2
authorAnton Obzhirov <a.obzhirov@samsung.com>
Fri, 31 Aug 2018 15:50:01 +0000 (16:50 +0100)
committerAnton Obzhirov <a.obzhirov@samsung.com>
Mon, 3 Sep 2018 13:47:59 +0000 (14:47 +0100)
In case of reusing a layout LayoutItem::SetFrame
might fail to update actor position/size if the new and
the old layout bounds are the same.

Change-Id: I5c189afae93413866147c8814e3a10f2335872a7

automated-tests/src/dali-toolkit/utc-Dali-Layouting.cpp
dali-toolkit/devel-api/layouting/layout-item-impl.cpp
dali-toolkit/internal/layouting/layout-item-data-impl.h

index 9206215..27222a9 100644 (file)
@@ -2555,3 +2555,89 @@ int UtcDaliLayouting_LayoutGroupWithChildMargin01(void)
 
   END_TEST;
 }
+
+int UtcDaliLayouting_SetLayout(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliLayouting_SetLayout - Test reusing layouts");
+
+  Control rootControl;
+  SetupRootLayoutControl( rootControl );
+
+  auto container = Control::New();
+  auto horizontalLayout = LinearLayout::New();
+  horizontalLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
+  DevelControl::SetLayout( container, horizontalLayout );
+  container.SetName( "Container" );
+  rootControl.Add( container );
+
+  std::vector< Control > controls;
+  controls.push_back( CreateLeafControl( 40, 40 ) );
+  controls.push_back( CreateLeafControl( 60, 60 ) );
+
+  for( auto&& iter : controls )
+  {
+    container.Add( iter );
+  }
+
+  container.SetParentOrigin( ParentOrigin::CENTER );
+  container.SetAnchorPoint( AnchorPoint::CENTER );
+
+  // Ensure layouting happens
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( container.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 40.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( container.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  // Change a layout
+  auto verticalLayout = LinearLayout::New();
+  verticalLayout.SetOrientation( LinearLayout::Orientation::VERTICAL );
+  DevelControl::SetLayout( container, verticalLayout );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( container.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( container.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  // Second round
+  DevelControl::SetLayout( container, horizontalLayout );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( container.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 10.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 40.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( container.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 100.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  // Change a layout
+  DevelControl::SetLayout( container, verticalLayout );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( container.GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::POSITION ), Vector3( 0.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( container.GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 100.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[0].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( controls[1].GetProperty<Vector3>( Actor::Property::SIZE ), Vector3( 60.0f, 60.0f, 0.0f ), 0.0001f, TEST_LOCATION );
+
+  END_TEST;
+}
index 20e23f3..85fab8a 100644 (file)
@@ -314,6 +314,10 @@ void LayoutItem::OnLayout( bool changed, LayoutLength left, LayoutLength top, La
 void LayoutItem::SetParent( LayoutParent* parent )
 {
   mImpl->mLayoutParent = parent;
+  if ( parent == nullptr )
+  {
+    mImpl->ClearPrivateFlag( Impl::PRIVATE_FLAG_FORCE_SET_FRAME );
+  }
 }
 
 LayoutParent* LayoutItem::GetParent()
@@ -441,7 +445,7 @@ bool LayoutItem::SetFrame( LayoutLength left, LayoutLength top, LayoutLength rig
 
   DALI_LOG_INFO( gLayoutFilter, Debug::Verbose, "LayoutItem::SetFrame enter(%d, %d, %d, %d)\n", left.mValue, top.mValue, right.mValue, bottom.mValue );
 
-  if( mImpl->mLeft != left || mImpl->mRight != right || mImpl->mTop != top || mImpl->mBottom != bottom )
+  if( mImpl->mLeft != left || mImpl->mRight != right || mImpl->mTop != top || mImpl->mBottom != bottom || !mImpl->GetPrivateFlag( Impl::PRIVATE_FLAG_FORCE_SET_FRAME ) )
   {
     changed = true;
 
@@ -456,7 +460,7 @@ bool LayoutItem::SetFrame( LayoutLength left, LayoutLength top, LayoutLength rig
     mImpl->mRight = right;
     mImpl->mBottom = bottom;
 
-    mImpl->SetPrivateFlag( Impl::PRIVATE_FLAG_HAS_BOUNDS );
+    mImpl->SetPrivateFlag( Impl::PRIVATE_FLAG_FORCE_SET_FRAME );
 
 
     // Reflect up to parent control
index 0e5c0e7..a2d2855 100644 (file)
@@ -51,39 +51,12 @@ public:
   LayoutLength mTop;
   LayoutLength mBottom;
 
-  /**
-   * This view is visible.
-   * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
-   * android:visibility}.
-   */
-  static const int VISIBLE = 0x00000000;
-
-  /**
-   * This view is invisible, but it still takes up space for layout purposes.
-   * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
-   * android:visibility}.
-   */
-  static const int INVISIBLE = 0x00000004;
-
-  /**
-   * This view is invisible, and it doesn't take any space for layout
-   * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
-   * android:visibility}.
-   */
-  static const int GONE = 0x00000008;
-
-  /**
-   * Mask for use with setFlags indicating bits used for visibility.
-   * {@hide}
-   */
-  static const int VISIBILITY_MASK = 0x0000000C;
-
   static const int PRIVATE_FLAG_MEASURED_DIMENSION_SET        = 0x00000001;
   static const int PRIVATE_FLAG_FORCE_LAYOUT                  = 0x00000002;
   static const int PRIVATE_FLAG_LAYOUT_REQUIRED               = 0x00000004;
   static const int PRIVATE_FLAG_IS_LAID_OUT                   = 0x00000008;
   static const int PRIVATE_FLAG_MEASURE_NEEDED_BEFORE_LAYOUT  = 0x00000010; ///< Flag indicating that a call to measure() was skipped and should be done instead when layout() is invoked.
-  static const int PRIVATE_FLAG_HAS_BOUNDS                    = 0x00000020;
+  static const int PRIVATE_FLAG_FORCE_SET_FRAME               = 0x00000020;
 
   int mViewFlags;
   int mPrivateFlags;