Merge "Allow ImageView padding to be set to Zero" into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 2 May 2019 15:00:48 +0000 (15:00 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 2 May 2019 15:00:48 +0000 (15:00 +0000)
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/internal/controls/image-view/image-view-impl.cpp
dali-toolkit/internal/controls/image-view/image-view-impl.h

index 20686c6..965e258 100644 (file)
@@ -1915,6 +1915,146 @@ int UtcDaliImageViewPaddingProperty02(void)
   END_TEST;
 }
 
+int UtcDaliImageViewPaddingProperty03(void)
+{
+  tet_infoline("Test Setting Image Padding then removing it.");
+
+  ToolkitTestApplication application;
+
+  ImageView imageView = ImageView::New();
+  Property::Map imagePropertyMap;
+  imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
+  imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
+  imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
+  imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
+  imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
+  imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
+  imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
+  Stage::GetCurrent().Add( imageView );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
+
+  tet_infoline("Remove Padding and test Visual is position correctly");
+
+  imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
+
+  application.SendNotification();
+  application.Render();
+
+  // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
+  Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
+  Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
+  Property::Map resultMap;
+  imageVisual.CreatePropertyMap( resultMap );
+
+  Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
+  DALI_TEST_CHECK( transformValue );
+  Property::Map* retMap = transformValue->GetMap();
+  DALI_TEST_CHECK( retMap );
+
+  // Image Visual should be positioned depending on ImageView's padding
+  DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliImageViewPaddingProperty04(void)
+{
+  tet_infoline("Test Setting Image Padding then removing it. Visual Fitting Mode as Fill");
+
+  ToolkitTestApplication application;
+
+  ImageView imageView = ImageView::New();
+  Property::Map imagePropertyMap;
+  imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
+  imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
+  imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
+  imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
+  imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FILL;
+  imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
+  imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
+  Stage::GetCurrent().Add( imageView );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
+
+  tet_infoline("Remove Padding and test Visual is position correctly");
+
+  imageView.SetProperty( Control::Property::PADDING, Extents( 0, 0, 0, 0 ) );
+
+  application.SendNotification();
+  application.Render();
+
+  // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
+  Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
+  Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
+  Property::Map resultMap;
+  imageVisual.CreatePropertyMap( resultMap );
+
+  Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
+  DALI_TEST_CHECK( transformValue );
+  Property::Map* retMap = transformValue->GetMap();
+  DALI_TEST_CHECK( retMap );
+
+  // Image Visual should be positioned depending on ImageView's padding
+  DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 0, 0 ), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliImageViewTransformTest01(void)
+{
+  tet_infoline("Test Setting a offset transform on the ImageView");
+
+  ToolkitTestApplication application;
+
+  ImageView imageView = ImageView::New();
+  Property::Map imagePropertyMap;
+  imagePropertyMap.Add( Toolkit::Visual::Property::TYPE,Toolkit::Visual::IMAGE )
+                  .Add( Toolkit::ImageVisual::Property::URL,TEST_RESOURCE_DIR "/Kid1.svg" )
+                  .Add( ImageVisual::Property::DESIRED_WIDTH,120 )
+                  .Add( ImageVisual::Property::DESIRED_HEIGHT,120 )
+                  .Add( DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL )
+                  .Add( Visual::Property::TRANSFORM,
+                        Property::Map().Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY,
+                                             Vector2( Visual::Transform::Policy::ABSOLUTE, Visual::Transform::Policy::ABSOLUTE ) )
+                                       .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( 8, 8 ) ) );
+
+  imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
+  imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  Stage::GetCurrent().Add( imageView );
+
+  application.SendNotification();
+  application.Render();
+
+  // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
+  Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
+  Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
+  Property::Map resultMap;
+  imageVisual.CreatePropertyMap( resultMap );
+
+  Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
+  DALI_TEST_CHECK( transformValue );
+  Property::Map* retMap = transformValue->GetMap();
+  DALI_TEST_CHECK( retMap );
+
+  // Image Visual should be positioned depending on ImageView's padding
+  DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 8, 8 ), TEST_LOCATION );
+  DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET_POLICY )->Get< Vector2 >(), Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ), TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
 {
   ToolkitTestApplication application;
@@ -1945,7 +2085,7 @@ int UtcDaliImageViewFillMode(void)
   ToolkitTestApplication application;
 
   tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
-  tet_infoline( "  There should be no need to change the transform, our size-policy should be relative and size shoudl be [1,1]");
+  tet_infoline( "  There should be no need to change the transform, our size-policy should be relative and size should be [1,1]");
 
   ImageView imageView = ImageView::New();
   Property::Map imageMap;
index b2814a4..edff0e3 100755 (executable)
@@ -65,7 +65,8 @@ using namespace Dali;
 
 ImageView::ImageView()
 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
-  mImageSize()
+  mImageSize(),
+  mImageVisualPaddingSetByTransform( false )
 {
 }
 
@@ -293,7 +294,8 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container )
     Extents padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
     const Visual::FittingMode fittingMode = Toolkit::GetImplementation(mVisual).GetFittingMode();
 
-    if( ( padding != Extents() ) || // If padding is not zero
+    bool zeroPadding = ( padding == Extents() );
+    if( ( !zeroPadding ) || // If padding is not zero
         ( fittingMode == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ) )
     {
       Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
@@ -305,6 +307,7 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container )
       }
 
       auto finalOffset = Vector2( padding.start, padding.top );
+      mImageVisualPaddingSetByTransform = true;
 
       // remove padding from the size to know how much is left for the visual
       auto finalSize = size - Vector2( padding.start + padding.end, padding.top + padding.bottom );
@@ -335,6 +338,15 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container )
                   .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY,
                       Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) );
     }
+    else if ( mImageVisualPaddingSetByTransform && zeroPadding )  // Reset offset to zero only if padding applied previously
+    {
+      mImageVisualPaddingSetByTransform = false;
+      // Reset the transform map
+      transformMap.Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2::ZERO )
+                  .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY,
+                        Vector2( Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::RELATIVE ) );
+    }
+
 
     mVisual.SetTransformAndSize( transformMap, size );
   }
index 4f05648..334754b 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__
-#define __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__
+#ifndef DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H
+#define DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -168,6 +168,8 @@ private:
   Property::Map    mPropertyMap;  ///< the Property::Map if the image came from a Property::Map, empty otherwise
   Property::Map    mShaderMap;    ///< the Property::Map if the custom shader is set, empty otherwise
   ImageDimensions  mImageSize;    ///< the image size
+
+  bool mImageVisualPaddingSetByTransform :1; //< Flag to indicate Padding was set using a transform.
 };
 
 } // namespace Internal
@@ -191,4 +193,4 @@ inline const Toolkit::Internal::ImageView& GetImpl( const Toolkit::ImageView& ob
 
 } // namespace Dali
 
-#endif // __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__
+#endif // DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H