Actor size property should return preferred size if size is fixed as set by SetSize 62/113462/5
authorRichard Huang <r.huang@samsung.com>
Tue, 7 Feb 2017 17:11:16 +0000 (17:11 +0000)
committerRichard Huang <r.huang@samsung.com>
Thu, 16 Feb 2017 17:13:10 +0000 (17:13 +0000)
Change-Id: I8662795c67ef377c6417ef4ff7abde394d28cc94

automated-tests/src/dali/utc-Dali-Actor.cpp
dali/internal/event/actors/actor-impl.cpp

index 4b8d3a2..e233b1b 100644 (file)
@@ -721,11 +721,44 @@ int UtcDaliActorSetSize01(void)
 
   actor.SetSize(vector.x, vector.y);
 
-  // flush the queue and render once
+  // Immediately retrieve the size after setting
+  Vector3 currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Change the resize policy and check whether the size stays the same
+  actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Set a new size after resize policy is changed and check the new size
+  actor.SetSize( Vector3( 0.1f, 0.2f, 0.0f ) );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 0.1f, 0.2f, 0.0f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Change the resize policy again and check whether the new size stays the same
+  actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 0.1f, 0.2f, 0.0f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Set another new size after resize policy is changed and check the new size
+  actor.SetSize( Vector3( 50.0f, 60.0f, 0.0f ) );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 50.0f, 60.0f, 0.0f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -741,11 +774,20 @@ int UtcDaliActorSetSize02(void)
 
   actor.SetSize(vector.x, vector.y, vector.z);
 
+  // Immediately check the size after setting
+  Vector3 currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -761,11 +803,20 @@ int UtcDaliActorSetSize03(void)
 
   actor.SetSize(Vector2(vector.x, vector.y));
 
+  // Immediately check the size after setting
+  Vector3 currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -781,20 +832,34 @@ int UtcDaliActorSetSize04(void)
 
   actor.SetSize(vector);
 
+  // Immediately check the size after setting
+  Vector3 currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, vector, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_CHECK(vector == actor.GetCurrentSize());
 
   Stage::GetCurrent().Add( actor );
   actor.SetSize( Vector3( 0.1f, 0.2f, 0.3f ) );
 
+  // Immediately check the size after setting
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 0.1f, 0.2f, 0.3f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the size in the new frame
   DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), actor.GetCurrentSize(), TEST_LOCATION );
+
+  currentSize = actor.GetProperty( Actor::Property::SIZE ).Get< Vector3 >();
+  DALI_TEST_EQUALS( currentSize, Vector3( 0.1f, 0.2f, 0.3f ), Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   Stage::GetCurrent().Remove( actor );
   END_TEST;
 }
@@ -810,28 +875,76 @@ int UtcDaliActorSetSizeIndividual(void)
 
   actor.SetProperty( Actor::Property::SIZE_WIDTH, vector.width );
 
+  // Immediately check the width after setting
+  float sizeWidth = actor.GetProperty( Actor::Property::SIZE_WIDTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeWidth, vector.width, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the width in the new frame
   DALI_TEST_EQUALS( vector.width, actor.GetCurrentSize().width, TEST_LOCATION );
 
+  sizeWidth = actor.GetProperty( Actor::Property::SIZE_WIDTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeWidth, vector.width, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   actor.SetProperty( Actor::Property::SIZE_HEIGHT, vector.height );
 
+  // Immediately check the height after setting
+  float sizeHeight = actor.GetProperty( Actor::Property::SIZE_HEIGHT ).Get< float >();
+  DALI_TEST_EQUALS( sizeHeight, vector.height, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the height in the new frame
   DALI_TEST_EQUALS( vector.height, actor.GetCurrentSize().height, TEST_LOCATION );
 
+  sizeHeight = actor.GetProperty( Actor::Property::SIZE_HEIGHT ).Get< float >();
+  DALI_TEST_EQUALS( sizeHeight, vector.height, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   actor.SetProperty( Actor::Property::SIZE_DEPTH, vector.depth );
 
+  // Immediately check the depth after setting
+  float sizeDepth = actor.GetProperty( Actor::Property::SIZE_DEPTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeDepth, vector.depth, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   // flush the queue and render once
   application.SendNotification();
   application.Render();
 
+  // Check the depth in the new frame
   DALI_TEST_EQUALS( vector.depth, actor.GetCurrentSize().depth, TEST_LOCATION );
 
+  sizeDepth = actor.GetProperty( Actor::Property::SIZE_DEPTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeDepth, vector.depth, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Change the resize policy and check whether the size stays the same
+  actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+
+  sizeWidth = actor.GetProperty( Actor::Property::SIZE_WIDTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeWidth, vector.width, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  sizeHeight = actor.GetProperty( Actor::Property::SIZE_HEIGHT ).Get< float >();
+  DALI_TEST_EQUALS( sizeHeight, vector.height, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  sizeDepth = actor.GetProperty( Actor::Property::SIZE_DEPTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeDepth, vector.depth, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Change the resize policy again and check whether the size stays the same
+  actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+
+  sizeWidth = actor.GetProperty( Actor::Property::SIZE_WIDTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeWidth, vector.width, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  sizeHeight = actor.GetProperty( Actor::Property::SIZE_HEIGHT ).Get< float >();
+  DALI_TEST_EQUALS( sizeHeight, vector.height, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  sizeDepth = actor.GetProperty( Actor::Property::SIZE_DEPTH ).Get< float >();
+  DALI_TEST_EQUALS( sizeDepth, vector.depth, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
   END_TEST;
 }
 
index cc51c2d..68d81d4 100644 (file)
@@ -1295,6 +1295,9 @@ void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimensio
 {
   EnsureRelayoutData();
 
+  ResizePolicy::Type originalWidthPolicy = GetResizePolicy(Dimension::WIDTH);
+  ResizePolicy::Type originalHeightPolicy = GetResizePolicy(Dimension::HEIGHT);
+
   for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
   {
     if( dimension & ( 1 << i ) )
@@ -1319,6 +1322,34 @@ void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimensio
   // If calling SetResizePolicy, assume we want relayout enabled
   SetRelayoutEnabled( true );
 
+  // If the resize policy is set to be FIXED, the preferred size
+  // should be overrided by the target size. Otherwise the target
+  // size should be overrided by the preferred size.
+
+  if( dimension & Dimension::WIDTH )
+  {
+    if( originalWidthPolicy != ResizePolicy::FIXED && policy == ResizePolicy::FIXED )
+    {
+      mRelayoutData->preferredSize.width = mTargetSize.width;
+    }
+    else if( originalWidthPolicy == ResizePolicy::FIXED && policy != ResizePolicy::FIXED )
+    {
+      mTargetSize.width = mRelayoutData->preferredSize.width;
+    }
+  }
+
+  if( dimension & Dimension::HEIGHT )
+  {
+    if( originalHeightPolicy != ResizePolicy::FIXED && policy == ResizePolicy::FIXED )
+    {
+      mRelayoutData->preferredSize.height = mTargetSize.height;
+    }
+    else if( originalHeightPolicy == ResizePolicy::FIXED && policy != ResizePolicy::FIXED )
+    {
+      mTargetSize.height = mRelayoutData->preferredSize.height;
+    }
+  }
+
   OnSetResizePolicy( policy, dimension );
 
   // Trigger relayout on this control
@@ -2911,19 +2942,48 @@ Property::Value Actor::GetDefaultProperty( Property::Index index ) const
 
     case Dali::Actor::Property::SIZE:
     {
-      value = GetTargetSize();
+      Vector3 size = GetTargetSize();
+
+      // Should return preferred size if size is fixed as set by SetSize
+      if( GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::FIXED )
+      {
+        size.width = GetPreferredSize().width;
+      }
+      if( GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::FIXED )
+      {
+        size.height = GetPreferredSize().height;
+      }
+
+      value = size;
+
       break;
     }
 
     case Dali::Actor::Property::SIZE_WIDTH:
     {
-      value = GetTargetSize().width;
+      if( GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::FIXED )
+      {
+        // Should return preferred size if size is fixed as set by SetSize
+        value = GetPreferredSize().width;
+      }
+      else
+      {
+        value = GetTargetSize().width;
+      }
       break;
     }
 
     case Dali::Actor::Property::SIZE_HEIGHT:
     {
-      value = GetTargetSize().height;
+      if( GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::FIXED )
+      {
+        // Should return preferred size if size is fixed as set by SetSize
+        value = GetPreferredSize().height;
+      }
+      else
+      {
+        value = GetTargetSize().height;
+      }
       break;
     }