(ImageView) Use Relayout method rather than OnSizeSet 97/100297/2
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 25 Nov 2016 17:57:11 +0000 (17:57 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 25 Nov 2016 18:12:00 +0000 (18:12 +0000)
We shouldn't rely on the OnSizeSet method as the size specified in this could
be different when our size is negotiated.

Change-Id: Iaca7de5b8641eb953ab3de312561d6feee61182c

dali-toolkit/internal/controls/image-view/image-view-impl.cpp
dali-toolkit/internal/controls/image-view/image-view-impl.h

index c2569bd..89e4c7b 100644 (file)
@@ -43,19 +43,6 @@ DALI_PROPERTY_REGISTRATION( Toolkit, ImageView, "preMultipliedAlpha", BOOLEAN, P
 DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, ImageView, "pixelArea", Vector4(0.f, 0.f, 1.f, 1.f), PIXEL_AREA )
 DALI_TYPE_REGISTRATION_END()
 
-
-void SetDefaultTransformMap( Property::Map& transformMap )
-{
-  transformMap.Clear();
-  transformMap
-    .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
-    .Add( Toolkit::DevelVisual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
-    .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
-    .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
-    .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO );
-
-}
-
 } // anonymous namespace
 
 using namespace Dali;
@@ -154,12 +141,6 @@ void ImageView::SetImage( const std::string& url, ImageDimensions size )
     mVisual =  Toolkit::VisualFactory::Get().CreateVisual( url, size );
     RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual );
 
-    // This transform fills the control
-    // Should provide a transform that handles aspect ratio according to image size
-    Property::Map transformMap;
-    SetDefaultTransformMap( transformMap );
-    mVisual.SetTransformAndSize( transformMap, mSizeSet );
-
     RelayoutRequest();
   }
 }
@@ -243,26 +224,15 @@ float ImageView::GetWidthForHeight( float height )
   }
 }
 
-
-///////////////////////////////////////////////////////////
-//
-// Private methods
-//
-
-void ImageView::OnSizeSet( const Vector3& targetSize )
+void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container )
 {
-  Control::OnSizeSet( targetSize );
-  mSizeSet = targetSize;
+  Control::OnRelayout( size, container );
 
   if( mVisual )
   {
-    Vector2 size( targetSize );
-
-    // This transform fills the control
+    // Pass in an empty map which uses default transform values meaning our visual fills the control
     // Should provide a transform that handles aspect ratio according to image size
-    Property::Map transformMap;
-    SetDefaultTransformMap( transformMap );
-    mVisual.SetTransformAndSize( transformMap, size );
+    mVisual.SetTransformAndSize( Property::Map(), size );
   }
 }
 
index f4f38b6..df0e66b 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -123,11 +123,6 @@ public:
 private: // From Control
 
   /**
-   * @copydoc Toolkit::Control::OnSizeSet()
-   */
-  virtual void OnSizeSet( const Vector3& targetSize );
-
-  /**
    * @copydoc Toolkit::Control::GetNaturalSize
    */
   virtual Vector3 GetNaturalSize();
@@ -142,6 +137,11 @@ private: // From Control
    */
   virtual float GetWidthForHeight( float height );
 
+  /**
+   * @copydoc Toolkit::Control::OnRelayout()
+   */
+  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
+
 private:
   // Undefined
   ImageView( const ImageView& );
@@ -150,7 +150,6 @@ private:
 private:
   Toolkit::Visual::Base  mVisual;
   ImageDimensions        mImageSize;
-  Vector2                mSizeSet;
 
   std::string      mUrl;          ///< the url for the image if the image came from a URL, empty otherwise
   Image            mImage;        ///< the Image if the image came from a Image, null otherwise