Merge "Add MARGIN and PADDING property in Control" into devel/master
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Tue, 17 Oct 2017 08:29:55 +0000 (08:29 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Tue, 17 Oct 2017 08:29:55 +0000 (08:29 +0000)
16 files changed:
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-compare-types.h
automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp
automated-tests/src/dali-toolkit/utc-Dali-Control.cpp
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/devel-api/controls/control-devel.h
dali-toolkit/internal/builder/builder-declarations.h
dali-toolkit/internal/builder/builder-get-is.inl.h
dali-toolkit/internal/builder/builder-set-property.cpp
dali-toolkit/internal/builder/replacement.cpp
dali-toolkit/internal/builder/replacement.h
dali-toolkit/internal/controls/control/control-data-impl.cpp
dali-toolkit/internal/controls/control/control-data-impl.h
dali-toolkit/internal/controls/image-view/image-view-impl.cpp
dali-toolkit/public-api/controls/control-impl.cpp
dali-toolkit/public-api/controls/control.h
dali-toolkit/public-api/visuals/visual-properties.h

index dd6ba24..5870028 100644 (file)
@@ -105,6 +105,15 @@ inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
 }
 
 template <>
+inline bool CompareType<Extents>(Extents extents1, Extents extents2, float epsilon)
+{
+  return (extents1.start == extents2.start) &&
+         (extents1.end == extents2.end) &&
+         (extents1.top == extents2.top) &&
+         (extents1.bottom == extents2.bottom);
+}
+
+template <>
 inline bool CompareType<Property::Value>(Property::Value q1, Property::Value q2, float epsilon)
 {
   Property::Type type = q1.GetType();
@@ -191,6 +200,14 @@ inline bool CompareType<Property::Value>(Property::Value q1, Property::Value q2,
       result = false;
       break;
     }
+    case Property::EXTENTS:
+    {
+      Extents a, b;
+      q1.Get(a);
+      q2.Get(b);
+      result = CompareType<Extents>( a, b, epsilon );
+      break;
+    }
     case Property::NONE:
     {
       result = false;
index f134be3..511d2ef 100644 (file)
@@ -1727,7 +1727,8 @@ int UtcDaliBuilderTypeCasts(void)
          "\"sensitive\":   { \"typeCast\":\"boolean\", \"value\":false },"
          "\"orientation\": { \"typeCast\":\"rotation\", \"value\":[10,10,10,10] },"
          "\"colorMode\":   { \"typeCast\":\"string\", \"value\":\"USE_OWN_MULTIPLY_PARENT_COLOR\" },"
-         "\"clippingBox\": { \"typeCast\":\"rect\", \"value\":[10,10,10,10] }"
+         "\"clippingBox\": { \"typeCast\":\"rect\", \"value\":[10,10,10,10] },"
+         "\"padding\":     { \"typeCast\":\"extents\", \"value\":[10,10,10,10] }"
       "}]"
     "}"
   );
index ffe1ee7..bfb390c 100644 (file)
@@ -865,3 +865,53 @@ int UtcDaliControlResourcesReady(void)
 
   END_TEST;
 }
+
+int UtcDaliControlMarginProperty(void)
+{
+  ToolkitTestApplication application;
+
+  Control control = Control::New();
+  control.SetBackgroundColor( Color::BLUE );
+
+  control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
+
+  Stage::GetCurrent().Add( control );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
+
+  // Parent control has one ImageView as a Child.
+  ImageView image = ImageView::New();
+  image.SetBackgroundColor( Color::RED );
+  image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+  image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
+  control.Add( image );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliControlPaddingProperty(void)
+{
+  ToolkitTestApplication application;
+
+  Control control = Control::New();
+  control.SetBackgroundColor( Color::BLUE );
+
+  control.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
+
+  Stage::GetCurrent().Add( control );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
+
+  END_TEST;
+}
index b22239e..51df879 100644 (file)
@@ -476,6 +476,7 @@ int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
 
   ImageView imageView = ImageView::New();
   imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
+  imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
 
   // By default, Aysnc loading is used
   // loading is not started if the actor is offStage
index 2d20ee2..f6fd3a4 100644 (file)
@@ -54,6 +54,8 @@ enum
   BACKGROUND_IMAGE  = Control::Property::BACKGROUND_IMAGE,
   KEY_INPUT_FOCUS   = Control::Property::KEY_INPUT_FOCUS,
   BACKGROUND        = Control::Property::BACKGROUND,
+  MARGIN            = Control::Property::MARGIN,
+  PADDING           = Control::Property::PADDING,
 
   /**
    * @brief Displays a tooltip when the control is hovered over.
@@ -66,7 +68,7 @@ enum
    * @note When retrieved, a Property::MAP is returned.
    * @see Toolkit::Tooltip
    */
-  TOOLTIP = BACKGROUND + 1,
+  TOOLTIP = PADDING + 1,
 
   /**
    * @brief The current state of the control.
@@ -74,7 +76,7 @@ enum
    *
    * @see DevelControl::State
    */
-  STATE = BACKGROUND + 2,
+  STATE = PADDING + 2,
 
   /**
    * @brief The current sub state of the control.
@@ -82,35 +84,35 @@ enum
    *
    * @see DevelControl::State
    */
-  SUB_STATE = BACKGROUND + 3,
+  SUB_STATE = PADDING + 3,
 
   /**
    * @brief The actor ID of the left focusable control.
    * @details Name "leftFocusableActorId", type Property::INTEGER.
    *
    */
-  LEFT_FOCUSABLE_ACTOR_ID = BACKGROUND + 4,
+  LEFT_FOCUSABLE_ACTOR_ID = PADDING + 4,
 
   /**
    * @brief The actor ID of the right focusable control.
    * @details Name "rightFocusableActorId", type Property::INTEGER.
    *
    */
-  RIGHT_FOCUSABLE_ACTOR_ID = BACKGROUND + 5,
+  RIGHT_FOCUSABLE_ACTOR_ID = PADDING + 5,
 
   /**
    * @brief The actor ID of the up focusable control.
    * @details Name "upFocusableActorId", type Property::INTEGER.
    *
    */
-  UP_FOCUSABLE_ACTOR_ID = BACKGROUND + 6,
+  UP_FOCUSABLE_ACTOR_ID = PADDING + 6,
 
   /**
    * @brief The actor ID of the down focusable control.
    * @details Name "downFocusableActorId", type Property::INTEGER.
    *
    */
-  DOWN_FOCUSABLE_ACTOR_ID = BACKGROUND + 7
+  DOWN_FOCUSABLE_ACTOR_ID = PADDING + 7
 };
 
 } // namespace Property
index 03627ba..831a478 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_BUILDER_DECLARATIONS_H__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -19,6 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/common/extents.h>
 #include <dali/public-api/math/rect.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/vector3.h>
@@ -46,5 +47,6 @@ typedef OptionalValue<std::string> OptionalString;
 typedef OptionalValue<Dali::Matrix> OptionalMatrix;
 typedef OptionalValue<Dali::Matrix3> OptionalMatrix3;
 typedef OptionalValue<Dali::Rect<int> > OptionalRect;
+typedef OptionalValue<Dali::Extents> OptionalExtents;
 
 #endif // __DALI_TOOLKIT_BUILDER_DECLARATIONS_H__
index ae17837..63cd31e 100644 (file)
@@ -260,6 +260,24 @@ inline OptionalRect IsRect(const OptionalChild& node)
   return ret;
 }
 
+inline OptionalExtents IsExtents(const OptionalChild& node)
+{
+  OptionalExtents extents;
+  if(node && (*node).Size())
+  {
+    if((*node).Size() >= 4)
+    {
+      TreeNode::ConstIterator iter((*node).CBegin());
+      int v[4];
+      if( CopyNumbers((*node).CBegin(), 4, v) )
+      {
+        extents = OptionalExtents(Dali::Extents(v[0], v[1], v[2], v[3]));
+      }
+    }
+  }
+  return extents;
+}
+
 //
 //
 //
@@ -313,6 +331,11 @@ inline OptionalRect IsRect(const TreeNode &parent, const std::string& childName)
   return IsRect( IsChild(&parent, childName) );
 }
 
+inline OptionalExtents IsExtents(const TreeNode &parent, const std::string& childName)
+{
+  return IsExtents( IsChild(&parent, childName) );
+}
+
 //
 //
 //
@@ -366,6 +389,11 @@ inline OptionalRect IsRect(const TreeNode &node )
   return IsRect( OptionalChild( node ) );
 }
 
+inline OptionalExtents IsExtents(const TreeNode &node )
+{
+  return IsExtents( OptionalChild( node ) );
+}
+
 //
 //
 //
index 93a1fbe..367c527 100644 (file)
@@ -97,6 +97,10 @@ bool Disambiguated(const TreeNode& child,
     {
       return DeterminePropertyFromNode( *childValue, Dali::Property::ARRAY, value, replacement);
     }
+    else if(*childType == "extents")
+    {
+      return DeterminePropertyFromNode( *childValue, Dali::Property::EXTENTS, value, replacement);
+    }
   }
 
   // else we failed to disambiguate
@@ -317,6 +321,15 @@ bool DeterminePropertyFromNode( const TreeNode& node, Property::Type type, Prope
       }
       break;
     }
+    case Property::EXTENTS:
+    {
+      if( OptionalExtents v = replacer.IsExtents(node) )
+      {
+        value = *v;
+        done = true;
+      }
+      break;
+    }
     case Property::NONE:
     {
       break;
index 07240be..a15ef21 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -429,7 +429,23 @@ OptionalRect Replacement::IsRect( const TreeNode & node ) const
   return ret;
 }
 
-
+OptionalExtents Replacement::IsExtents( const TreeNode & node ) const
+{
+  OptionalExtents extents;
+  if( OptionalString replace = HasFullReplacement( node ) )
+  {
+    Property::Value value = GetFullReplacement( *replace );
+    if( Property::EXTENTS == value.GetType() )
+    {
+      extents = value.Get<Extents>();
+    }
+  }
+  else
+  {
+    extents = ::IsExtents( node );
+  }
+  return extents;
+}
 
 OptionalFloat Replacement::IsFloat( OptionalChild child ) const
 {
@@ -578,6 +594,18 @@ bool Replacement::IsArray( OptionalChild child, Property::Value& out ) const
   return ret;
 }
 
+OptionalExtents Replacement::IsExtents( OptionalChild child ) const
+{
+  if( child )
+  {
+    return IsExtents( *child );
+  }
+  else
+  {
+    return OptionalExtents();
+  }
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index 3c4d829..1c4d34c 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_INTERNAL_BUILDER_REPLACEMENT__
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -141,6 +141,13 @@ public:
 
   /* @brief Check node for a type
    *
+   * @param node The TreeNode to check
+   * @return Optional value
+   */
+  OptionalExtents IsExtents( const TreeNode & node ) const;
+
+  /* @brief Check node for a type
+   *
    * @param child The optional child TreeNode
    * @return Optional value
    */
@@ -223,6 +230,13 @@ public:
    */
   bool IsArray( OptionalChild child, Property::Value& out ) const;
 
+  /* @brief Check node for a type
+   *
+   * @param child The optional child TreeNode
+   * @return Optional value
+   */
+  OptionalExtents IsExtents( OptionalChild child ) const;
+
 private:
   // Overriding map (overrides the default map). The map is not owned.
   const Property::Map* const mOverrideMap;
index 43f3161..57cb46d 100644 (file)
@@ -302,14 +302,15 @@ const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgro
 const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage",        Toolkit::Control::Property::BACKGROUND_IMAGE,             Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
 const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus",          Toolkit::Control::Property::KEY_INPUT_FOCUS,              Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
 const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background",             Toolkit::Control::Property::BACKGROUND,                   Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip",                Toolkit::DevelControl::Property::TOOLTIP,                 Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state",                  Toolkit::DevelControl::Property::STATE,                   Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState",               Toolkit::DevelControl::Property::SUB_STATE,               Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "leftFocusableActorId",   Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "upFocusableActorId",    Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID,   Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "downFocusableActorId",  Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-
+const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "margin",                 Toolkit::Control::Property::MARGIN,                       Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "padding",                Toolkit::Control::Property::PADDING,                      Property::EXTENTS, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "tooltip",                Toolkit::DevelControl::Property::TOOLTIP,                 Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "state",                  Toolkit::DevelControl::Property::STATE,                   Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "subState",               Toolkit::DevelControl::Property::SUB_STATE,               Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "leftFocusableActorId",   Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_13( typeRegistration, "upFocusableActorId",    Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID,   Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_14( typeRegistration, "downFocusableActorId",  Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
 
 
 Control::Impl::Impl( Control& controlImpl )
@@ -323,6 +324,8 @@ Control::Impl::Impl( Control& controlImpl )
   mStyleName(""),
   mBackgroundColor(Color::TRANSPARENT),
   mStartingPinchScale( NULL ),
+  mMargin( 0, 0, 0, 0 ),
+  mPadding( 0, 0, 0, 0 ),
   mKeyEventSignal(),
   mPinchGestureDetector(),
   mPanGestureDetector(),
@@ -910,6 +913,26 @@ void Control::Impl::SetProperty( BaseObject* object, Property::Index index, cons
         break;
       }
 
+      case Toolkit::Control::Property::MARGIN:
+      {
+        Extents margin;
+        if( value.Get( margin ) )
+        {
+          controlImpl.mImpl->SetMargin( margin );
+        }
+        break;
+      }
+
+      case Toolkit::Control::Property::PADDING:
+      {
+        Extents padding;
+        if( value.Get( padding ) )
+        {
+          controlImpl.mImpl->SetPadding( padding );
+        }
+        break;
+      }
+
       case Toolkit::DevelControl::Property::TOOLTIP:
       {
         TooltipPtr& tooltipPtr = controlImpl.mImpl->mTooltip;
@@ -918,7 +941,9 @@ void Control::Impl::SetProperty( BaseObject* object, Property::Index index, cons
           tooltipPtr = Tooltip::New( control );
         }
         tooltipPtr->SetProperties( value );
+        break;
       }
+
     }
   }
 }
@@ -1016,6 +1041,18 @@ Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index
         break;
       }
 
+      case Toolkit::Control::Property::MARGIN:
+      {
+        value = controlImpl.mImpl->GetMargin();
+        break;
+      }
+
+      case Toolkit::Control::Property::PADDING:
+      {
+        value = controlImpl.mImpl->GetPadding();
+        break;
+      }
+
       case Toolkit::DevelControl::Property::TOOLTIP:
       {
         Property::Map map;
@@ -1026,7 +1063,6 @@ Property::Value Control::Impl::GetProperty( BaseObject* object, Property::Index
         value = map;
         break;
       }
-
     }
   }
 
@@ -1298,6 +1334,26 @@ void Control::Impl::OnStageDisconnection()
   mRemoveVisuals.Clear();
 }
 
+void Control::Impl::SetMargin( Extents margin )
+{
+  mControlImpl.mImpl->mMargin = margin;
+}
+
+Extents Control::Impl::GetMargin() const
+{
+  return mControlImpl.mImpl->mMargin;
+}
+
+void Control::Impl::SetPadding( Extents padding )
+{
+  mControlImpl.mImpl->mPadding = padding;
+}
+
+Extents Control::Impl::GetPadding() const
+{
+  return mControlImpl.mImpl->mPadding;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index dc00d60..2e1d4c9 100644 (file)
@@ -265,6 +265,30 @@ public:
    */
   void OnStageDisconnection();
 
+  /**
+   * @brief Sets the margin.
+   * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
+   */
+  void SetMargin( Extents margin );
+
+  /**
+   * @brief Returns the value of margin
+   * @return The value of margin
+   */
+  Extents GetMargin() const;
+
+  /**
+   * @brief Sets the padding.
+   * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
+   */
+  void SetPadding( Extents padding );
+
+  /**
+   * @brief Returns the value of padding
+   * @return The value of padding
+   */
+  Extents GetPadding() const;
+
 private:
 
   /**
@@ -319,6 +343,8 @@ public:
   std::string mStyleName;
   Vector4 mBackgroundColor;               ///< The color of the background visual
   Vector3* mStartingPinchScale;           ///< The scale when a pinch gesture starts, TODO: consider removing this
+  Extents mMargin;                        ///< The margin values
+  Extents mPadding;                       ///< The padding values
   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
   Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
@@ -352,6 +378,8 @@ public:
   static const PropertyRegistration PROPERTY_10;
   static const PropertyRegistration PROPERTY_11;
   static const PropertyRegistration PROPERTY_12;
+  static const PropertyRegistration PROPERTY_13;
+  static const PropertyRegistration PROPERTY_14;
 };
 
 
index e7514b0..37b2dd5 100644 (file)
@@ -180,6 +180,12 @@ Vector3 ImageView::GetNaturalSize()
   {
     Vector2 rendererNaturalSize;
     mVisual.GetNaturalSize( rendererNaturalSize );
+
+    Extents padding;
+    padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
+
+    rendererNaturalSize.width += ( padding.start + padding.end );
+    rendererNaturalSize.height += ( padding.top + padding.bottom );
     return Vector3( rendererNaturalSize );
   }
 
@@ -189,25 +195,31 @@ Vector3 ImageView::GetNaturalSize()
 
 float ImageView::GetHeightForWidth( float width )
 {
+  Extents padding;
+  padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
+
   if( mVisual )
   {
-    return mVisual.GetHeightForWidth( width );
+    return mVisual.GetHeightForWidth( width ) + padding.top + padding.bottom;
   }
   else
   {
-    return Control::GetHeightForWidth( width );
+    return Control::GetHeightForWidth( width ) + padding.top + padding.bottom;
   }
 }
 
 float ImageView::GetWidthForHeight( float height )
 {
+  Extents padding;
+  padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
+
   if( mVisual )
   {
-    return mVisual.GetWidthForHeight( height );
+    return mVisual.GetWidthForHeight( height ) + padding.start + padding.end;
   }
   else
   {
-    return Control::GetWidthForHeight( height );
+    return Control::GetWidthForHeight( height ) + padding.start + padding.end;
   }
 }
 
@@ -217,9 +229,25 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container )
 
   if( mVisual )
   {
-    // Pass in an empty map which uses default transform values meaning our visual fills the control
+    Extents margin;
+    margin = Self().GetProperty<Extents>( Toolkit::Control::Property::MARGIN );
+
+    Extents padding;
+    padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
+
+    Property::Map transformMap = Property::Map();
+
+    if( ( padding.start != 0 ) || ( padding.end != 0 ) || ( padding.top != 0 ) || ( padding.bottom != 0 ) ||
+        ( margin.start != 0 ) || ( margin.end != 0 ) || ( margin.top != 0 ) || ( margin.bottom != 0 ) )
+    {
+      transformMap.Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( margin.start + padding.start, margin.top + padding.top ) )
+                  .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+                  .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
+                  .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
+    }
+
     // Should provide a transform that handles aspect ratio according to image size
-    mVisual.SetTransformAndSize( Property::Map(), size );
+    mVisual.SetTransformAndSize( transformMap, size );
   }
 }
 
index 68fd55a..d7df20a 100644 (file)
@@ -83,6 +83,46 @@ void CreateClippingRenderer( Control& controlImpl )
   }
 }
 
+/**
+ * @brief Sets Control::Property::BACKGROUND visual
+ * @param[in] controlImpl The control implementation
+ * @param[in] visual The control background visual
+ * @param[in] size The current size
+ */
+void SetBackgroundVisual( Control::Impl& controlImpl, Toolkit::Visual::Base& visual, const Vector2& size )
+{
+  Property::Map transformMap = Property::Map();
+
+  Vector2 newSize( 0.f, 0.f );
+  newSize.width = size.width + ( controlImpl.mPadding.start + controlImpl.mPadding.end );
+  newSize.height = size.height + ( controlImpl.mPadding.top + controlImpl.mPadding.bottom );
+
+  if( ( controlImpl.mMargin.start != 0 ) ||
+      ( controlImpl.mMargin.end != 0 ) ||
+      ( controlImpl.mMargin.top != 0 ) ||
+      ( controlImpl.mMargin.bottom != 0 ) )
+  {
+    transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, newSize )
+                .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+                .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( controlImpl.mMargin.start, controlImpl.mMargin.top ) )
+                .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+                .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
+                .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
+  }
+  else if( ( controlImpl.mPadding.start != 0 ) ||
+           ( controlImpl.mPadding.end != 0 ) ||
+           ( controlImpl.mPadding.top != 0 ) ||
+           ( controlImpl.mPadding.bottom != 0 ) )
+  {
+    transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, newSize )
+                .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+                .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
+                .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
+  }
+
+  visual.SetTransformAndSize( transformMap, newSize ); // Send an empty map as we do not want to modify the visual's set transform
+}
+
 } // unnamed namespace
 
 
@@ -563,7 +603,8 @@ void Control::OnSizeSet(const Vector3& targetSize)
   if( visual )
   {
     Vector2 size( targetSize );
-    visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
+    SetBackgroundVisual( *mImpl, visual, size );
+
   }
 }
 
@@ -596,13 +637,30 @@ void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
 {
   for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i )
   {
-    container.Add( Self().GetChildAt( i ), size );
+    Actor child = Self().GetChildAt( i );
+    Vector2 newChildSize( size );
+
+    // When set the padding or margin on the control, child should be resized and repositioned.
+    if( ( mImpl->mPadding.start != 0 ) || ( mImpl->mPadding.end != 0 ) || ( mImpl->mPadding.top != 0 ) || ( mImpl->mPadding.bottom != 0 ) ||
+        ( mImpl->mMargin.start != 0 ) || ( mImpl->mMargin.end != 0 ) || ( mImpl->mMargin.top != 0 ) || ( mImpl->mMargin.bottom != 0 ) )
+    {
+      newChildSize.width = size.width - ( mImpl->mPadding.start + mImpl->mPadding.end );
+      newChildSize.height = size.height - ( mImpl->mPadding.top + mImpl->mPadding.bottom );
+
+      Vector3 childPosition = child.GetTargetSize();
+      childPosition.x += ( mImpl->mMargin.start + mImpl->mPadding.start );
+      childPosition.y += ( mImpl->mMargin.top + mImpl->mPadding.top );
+
+      child.SetPosition( childPosition );
+    }
+
+    container.Add( child, newChildSize );
   }
 
   Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
   if( visual )
   {
-    visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
+    SetBackgroundVisual( *mImpl, visual, size );
   }
 }
 
@@ -617,6 +675,8 @@ Vector3 Control::GetNaturalSize()
   {
     Vector2 naturalSize;
     visual.GetNaturalSize( naturalSize );
+    naturalSize.width += ( mImpl->mPadding.start + mImpl->mPadding.end );
+    naturalSize.height += ( mImpl->mPadding.top + mImpl->mPadding.bottom );
     return Vector3( naturalSize );
   }
   return Vector3::ZERO;
index c68d41a..5fd8933 100644 (file)
@@ -97,35 +97,64 @@ public:
     enum
     {
       /**
-       * @brief name "styleName", type std::string.
+       * @brief The name of the style to be applied to the control.
+       * @details Name "styleName", type Property::STRING.
+       * @see Toolkit::Control::SetStyleName()
        * @SINCE_1_0.0
-       * @see SetStyleName
        */
       STYLE_NAME = PROPERTY_START_INDEX,
+
       /**
        * @DEPRECATED_1_1.3
-       * @brief name "backgroundColor", mutually exclusive with BACKGROUND_IMAGE & BACKGROUND,  type Vector4.
+       * @brief The background color of the control.
+       *
+       * Mutually exclusive with BACKGROUND_IMAGE & BACKGROUND.
+       * @details Name "backgroundColor", type Property::VECTOR4.
+       * @see Toolkit::Control::SetStyleName()
        * @SINCE_1_0.0
-       * @see SetStyleName
        */
       BACKGROUND_COLOR,
+
       /**
        * @DEPRECATED_1_1.3
-       * @brief name "backgroundImage", mutually exclusive with BACKGROUND_COLOR & BACKGROUND,  type Map.
+       * @brief The background image of the control.
+       *
+       * Mutually exclusive with BACKGROUND_COLOR & BACKGROUND.
+       * @details Name "backgroundImage", type Property::MAP.
        * @SINCE_1_0.0
        */
       BACKGROUND_IMAGE,
+
       /**
-       * @brief name "keyInputFocus", type bool.
+       * @brief Receives key events to the control.
+       * @details Name "keyInputFocus", type Property::BOOLEAN.
+       * @see Toolkit::Control::SetKeyInputFocus()
        * @SINCE_1_0.0
-       * @see SetKeyInputFocus
        */
       KEY_INPUT_FOCUS,
+
       /**
-       * @brief name "background", mutually exclusive with BACKGROUND_COLOR & BACKGROUND_IMAGE, type Map or std::string for URL or Vector4 for Color.
+       * @brief The background of the control.
+       *
+       * Mutually exclusive with BACKGROUND_COLOR & BACKGROUND_IMAGE.
+       * @details Name "background", type Property::MAP or std::string for URL or Property::VECTOR4 for Color.
        * @SINCE_1_1.3
        */
       BACKGROUND,
+
+      /**
+       * @brief The outer space around the control.
+       * @details Name "margin", type Property::EXTENTS.
+       * @SINCE_1_2.62
+       */
+      MARGIN,
+
+      /**
+       * @brief The inner space of the control.
+       * @details Name "padding", type Property::EXTENTS.
+       * @SINCE_1_2.62
+       */
+      PADDING
     };
   };
 
index 5617198..54a4350 100644 (file)
@@ -95,7 +95,7 @@ enum
    * @details Name "transform", type Property::MAP.
    * @SINCE_1_2.60
    * @note Optional.
-   * @see DevelVisual::Transform::Property
+   * @see Toolkit::Visual::Transform::Property
    */
   TRANSFORM,
 
@@ -196,8 +196,8 @@ enum Type
    * control.SetProperty( ..., // Some visual based property
    *                      Property::Map().Add( ... ) // Properties to set up visual
    *                                     .Add( Visual::Property::TRANSFORM,
-   *                                           Property::Array().Add( DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( Policy::ABSOLUTE, Policy::RELATIVE ) ) )
-   *                                                            .Add( DevelVisual::Transform::Property::OFFSET, Vector2( 10, 1.0f ) ) );
+   *                                           Property::Array().Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Policy::ABSOLUTE, Policy::RELATIVE ) ) )
+   *                                                            .Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( 10, 1.0f ) ) );
    * @endcode
    *
    * JSON: