Dali-demo: Replace constraints with SizeMode 67/35367/5
authorTom Robinson <tom.robinson@samsung.com>
Thu, 12 Feb 2015 15:14:24 +0000 (15:14 +0000)
committerTom Robinson <tom.robinson@samsung.com>
Wed, 18 Feb 2015 10:33:27 +0000 (10:33 +0000)
Change-Id: I7a7f59aa5f557a8a57385e876fd881d87c101a28

demo/dali-table-view.cpp
examples/blocks/blocks-example.cpp
examples/cluster/cluster-example.cpp
examples/image/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp
examples/item-view/item-view-example.cpp
examples/scroll-view/scroll-view-example.cpp
examples/shadows/shadow-bone-lighting-example.cpp
examples/shared/view.h

index 0516a07..b0376ec 100644 (file)
@@ -258,8 +258,9 @@ void DaliTableView::Initialize( Application& application )
 
   mScrollView.SetAnchorPoint( AnchorPoint::CENTER );
   mScrollView.SetParentOrigin( ParentOrigin::CENTER );
-  mScrollView.ApplyConstraint( Dali::Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ),
-                                                                     Dali::RelativeToConstraint( SCROLLVIEW_RELATIVE_SIZE ) ) );
+  // Note: Currently, changing mScrollView to use SizeMode RELATIVE_TO_PARENT
+  // will cause scroll ends to appear in the wrong position.
+  mScrollView.ApplyConstraint( Dali::Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ), Dali::RelativeToConstraint( SCROLLVIEW_RELATIVE_SIZE ) ) );
   mScrollView.SetAxisAutoLock( true );
   mScrollView.ScrollCompletedSignal().Connect( this, &DaliTableView::OnScrollComplete );
   mScrollView.ScrollStartedSignal().Connect( this, &DaliTableView::OnScrollStart );
@@ -356,7 +357,7 @@ void DaliTableView::Populate()
 
       page.SetAnchorPoint( AnchorPoint::CENTER );
       page.SetParentOrigin( ParentOrigin::CENTER );
-      page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
+      page.SetSizeMode( SIZE_EQUAL_TO_PARENT );
 
       // add cells to table
       const float margin = 4.0f;
@@ -465,7 +466,7 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit
     image.SetAnchorPoint( AnchorPoint::CENTER );
     image.SetParentOrigin( ParentOrigin::CENTER );
     // make the image 100% of tile
-    image.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
+    image.SetSizeMode( SIZE_EQUAL_TO_PARENT );
     // move image back to get text appear in front
     image.SetZ( -1 );
     image.SetStyle( ImageActor::STYLE_NINE_PATCH );
@@ -474,7 +475,7 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit
 
     // Add stencil
     ImageActor stencil = NewStencilImage();
-    stencil.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
+    stencil.SetSizeMode( SIZE_EQUAL_TO_PARENT );
     image.Add( stencil );
   }
 
@@ -733,7 +734,7 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BitmapImage dis
     Constraint animConstraint = Constraint::New < Vector3 > ( Actor::POSITION,
       Source( mScrollView, mScrollView.GetPropertyIndex( ScrollView::SCROLL_POSITION_PROPERTY_NAME ) ),
       Dali::ParentSource( Dali::Actor::SIZE ),
-      AnimateBubbleConstraint( actorPos, Random::Range( -0.85f, 0.35f ), randSize ) );
+      AnimateBubbleConstraint( actorPos, Random::Range( -0.85f, 0.25f ), randSize ) );
     dfActor.ApplyConstraint( animConstraint );
 
     // Kickoff animation
index c844a0b..e984286 100644 (file)
@@ -423,7 +423,7 @@ private:
     mLevelContainer = Actor::New();
     mLevelContainer.SetAnchorPoint( AnchorPoint::CENTER );
     mLevelContainer.SetParentOrigin( ParentOrigin::CENTER );
-    mLevelContainer.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
+    mLevelContainer.SetSizeMode( SIZE_EQUAL_TO_PARENT );
     mContentLayer.Add( mLevelContainer );
 
     mBrickCount = 0;
index 29f06f7..04a7202 100644 (file)
@@ -199,33 +199,6 @@ struct CarouselEffectOrientationConstraint
 };
 
 /**
- * RescaleConstraint
- * Rescales the inputer scale by the ratio of the height:width of it's parent.
- */
-struct RescaleConstraint
-{
-  /**
-   * Constructor
-   * @param[in] value0 Constant multiplication operand (K).
-   */
-  RescaleConstraint()
-  {
-  }
-
-  /**
-   * @param[in] current The object's current property value
-   * @param[in] property0 The first property to multiplication operand
-   * @return The object's new property value
-   */
-  Vector3 operator()(const Vector3&    current,
-                     const PropertyInput& property0)
-  {
-    return current * Vector3( property0.GetVector3().y / property0.GetVector3().x, 1.0f, 1.0f );
-  }
-
-};
-
-/**
  * ShearEffectConstraint
  *
  * Constrains ShearEffect's tilt to be a function of scrollview's
@@ -514,12 +487,8 @@ public:
     mScrollView.SetAnchorPoint(AnchorPoint::CENTER);
     mScrollView.SetParentOrigin(ParentOrigin::CENTER);
 
-    // Scale ScrollView to fit within parent (mContentLayer)
-    Constraint constraint = Constraint::New<Vector3>( Actor::SCALE,
-                                                    LocalSource( Actor::SIZE ),
-                                                    ParentSource( Actor::SIZE ),
-                                                    ScaleToFitConstraint() );
-    mScrollView.ApplyConstraint(constraint);
+    // Scale ScrollView to fit parent (mContentLayer)
+    mScrollView.SetSizeMode( SIZE_EQUAL_TO_PARENT );
 
     // Add the scroll view to the content layer
     mContentLayer.Add(mScrollView);
@@ -649,14 +618,7 @@ public:
     mScrollView.Add(pageView);
     pageView.SetParentOrigin(ParentOrigin::CENTER);
     pageView.SetPosition(Vector3(stageSize.width * column, 0.0f, 0.0f));
-    pageView.SetSize(stageSize);
-
-    // Resize pageView (which contains a Cluster)
-    Constraint constraintScale = Constraint::New<Vector3>( Actor::SCALE,
-                                                           ParentSource( Actor::SCALE ),
-                                                           RescaleConstraint() );
-    constraintScale.SetRemoveAction(Constraint::Discard);
-    pageView.ApplyConstraint(constraintScale);
+    pageView.SetSizeMode( SIZE_EQUAL_TO_PARENT );
 
     // Create cluster actors, add them to scroll view, and set the shear effect with the given center point.
     Cluster cluster = CreateClusterActor(clusterType, style);
index 856654f..e0276c2 100644 (file)
@@ -416,7 +416,7 @@ public:
     // coordinates in a frame defined by a parent actor:
 
     Actor gridActor = Actor::New();
-    gridActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
+    gridActor.SetSizeMode( SIZE_EQUAL_TO_PARENT );
     gridActor.SetParentOrigin( ParentOrigin::CENTER );
     gridActor.SetAnchorPoint( AnchorPoint::CENTER );
 
index bc2833b..00da668 100644 (file)
@@ -164,15 +164,6 @@ const Vector4           DEFAULT_TEXT_STYLE_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
 
 const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f );
 
-struct BorderSizeConstraintFunction
-{
-  Vector3 operator()(const Vector3&       current,
-                     const PropertyInput& parentSize)
-  {
-    return parentSize.GetVector3() + ITEM_BORDER_MARGIN_SIZE;
-  }
-};
-
 static Vector3 DepthLayoutItemSizeFunctionPortrait(unsigned int numberOfColumns, float layoutWidth)
 {
   float width = (layoutWidth / static_cast<float>(numberOfColumns + 1)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
@@ -897,9 +888,8 @@ public: // From ItemFactory
     borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH );
     borderActor.SetNinePatchBorder( Vector4( ITEM_IMAGE_BORDER_LEFT, ITEM_IMAGE_BORDER_TOP, ITEM_IMAGE_BORDER_RIGHT, ITEM_IMAGE_BORDER_BOTTOM ) );
     borderActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); // darken with parent image-actor
-
-    Constraint constraint = Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), BorderSizeConstraintFunction() );
-    borderActor.ApplyConstraint(constraint);
+    borderActor.SetSizeMode( SIZE_FIXED_OFFSET_FROM_PARENT );
+    borderActor.SetSizeModeFactor( ITEM_BORDER_MARGIN_SIZE );
     actor.Add(borderActor);
     actor.SetKeyboardFocusable( true );
 
index f1a4c05..8c8e31a 100644 (file)
@@ -298,7 +298,7 @@ private:
   Actor CreatePage()
   {
     Actor page = Actor::New();
-    page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
+    page.SetSizeMode( SIZE_EQUAL_TO_PARENT );
     page.SetParentOrigin( ParentOrigin::CENTER );
     page.SetAnchorPoint( AnchorPoint::CENTER );
 
@@ -450,7 +450,7 @@ private:
    void ApplyEffectToPage(Actor page)
    {
      page.RemoveConstraints();
-     page.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
+     page.SetSizeMode( SIZE_EQUAL_TO_PARENT );
 
      switch( mEffectMode )
      {
index eb4985f..a4882a2 100644 (file)
@@ -233,7 +233,7 @@ public:
     mShadowView.SetName("Container");
     mShadowView.SetParentOrigin(ParentOrigin::CENTER);
     mShadowView.SetAnchorPoint(AnchorPoint::CENTER);
-    mShadowView.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
+    mShadowView.SetSizeMode( SIZE_EQUAL_TO_PARENT );
     mShadowView.SetPointLightFieldOfView( Math::PI / 2.0f);
     mContents.Add(mShadowView);
 
index 5c2a773..13c8da9 100644 (file)
@@ -99,8 +99,8 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar,
   toolBar.SetBackground( toolBarBackground );
   toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER );
   toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER );
-  toolBar.ApplyConstraint( Dali::Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ), Dali::EqualToConstraint() ) );
   toolBar.SetSize( 0.0f, style.mToolBarHeight );
+  toolBar.SetSizeMode( Dali::SIZE_EQUAL_TO_PARENT );
   toolBarBackground.SetSortModifier(1.0f);
 
   // Add the tool bar to the too bar layer.
@@ -166,7 +166,7 @@ Dali::Layer CreateView( Dali::Application& application,
   Dali::Layer contentLayer = Dali::Layer::New();
   contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER );
   contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER );
-  contentLayer.ApplyConstraint( Dali::Constraint::New<Dali::Vector3>( Dali::Actor::SIZE, Dali::ParentSource( Dali::Actor::SIZE ), Dali::EqualToConstraint() ) );
+  contentLayer.SetSizeMode( Dali::SIZE_EQUAL_TO_PARENT );
   view.AddContentLayer( contentLayer );
   contentLayer.LowerBelow( toolBarLayer );