Removal of Actor::Insert API 61/43861/2
authorTom Robinson <tom.robinson@samsung.com>
Tue, 14 Jul 2015 15:10:32 +0000 (16:10 +0100)
committerTom Robinson <tom.robinson@samsung.com>
Tue, 14 Jul 2015 15:19:15 +0000 (08:19 -0700)
Change-Id: If2d5520bc496167acd6341d6cf8a06e1cb9df540

dali-toolkit/internal/controls/buttons/button-impl.cpp
dali-toolkit/internal/controls/buttons/button-impl.h
dali-toolkit/internal/controls/buttons/push-button-impl.cpp
dali-toolkit/public-api/controls/control-impl.cpp

index 3031d4f..2883c9a 100644 (file)
@@ -143,8 +143,11 @@ void Button::SetDisabled( bool disabled )
       //(2) mDisabledBackgroundContent (Inserted)
       //(1) mBackgroundContent
 
       //(2) mDisabledBackgroundContent (Inserted)
       //(1) mBackgroundContent
 
-      TransitionInBetween( mUnselectedContent, mLabel, mDisabledContent );
-      TransitionInAbove( mBackgroundContent, mDisabledBackgroundContent );
+      AddButtonImage( mBackgroundContent );
+      TransitionButtonImage( mDisabledBackgroundContent );
+      AddButtonImage( mUnselectedContent );
+      TransitionButtonImage( mDisabledContent );
+      ReAddLabel();
 
       TransitionOut( mUnselectedContent );
       TransitionOut( mSelectedContent );
 
       TransitionOut( mUnselectedContent );
       TransitionOut( mSelectedContent );
@@ -164,8 +167,12 @@ void Button::SetDisabled( bool disabled )
       //(2) mSelectedBackgroundContent
       //(1) mBackgroundContent
 
       //(2) mSelectedBackgroundContent
       //(1) mBackgroundContent
 
-      TransitionInBetween( mSelectedContent, mLabel, mDisabledSelectedContent );
-      TransitionInAbove( mSelectedBackgroundContent, mDisabledBackgroundContent );
+      AddButtonImage( mBackgroundContent );
+      AddButtonImage( mSelectedBackgroundContent );
+      TransitionButtonImage( mDisabledBackgroundContent );
+      AddButtonImage( mSelectedContent );
+      TransitionButtonImage( mDisabledSelectedContent );
+      ReAddLabel();
 
       TransitionOut( mUnselectedContent );
       TransitionOut( mSelectedContent );
 
       TransitionOut( mUnselectedContent );
       TransitionOut( mSelectedContent );
@@ -184,8 +191,11 @@ void Button::SetDisabled( bool disabled )
       //(2) mBackgroundContent (Inserted)
       //(1) mDisabledBackgroundContent
 
       //(2) mBackgroundContent (Inserted)
       //(1) mDisabledBackgroundContent
 
-      TransitionInBetween( mDisabledContent, mLabel, mUnselectedContent );
-      TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent );
+      AddButtonImage( mDisabledBackgroundContent );
+      TransitionButtonImage( mBackgroundContent );
+      AddButtonImage( mDisabledContent );
+      TransitionButtonImage( mUnselectedContent );
+      ReAddLabel();
 
       TransitionOut( mSelectedContent );
       TransitionOut( mSelectedBackgroundContent );
 
       TransitionOut( mSelectedContent );
       TransitionOut( mSelectedBackgroundContent );
@@ -205,9 +215,12 @@ void Button::SetDisabled( bool disabled )
       //(2) mBackgroundContent (Inserted)
       //(1) mDisabledBackgroundContent
 
       //(2) mBackgroundContent (Inserted)
       //(1) mDisabledBackgroundContent
 
-      TransitionInBetween( mDisabledSelectedContent, mLabel, mSelectedContent );
-      TransitionInAbove( mDisabledBackgroundContent, mSelectedBackgroundContent );
-      TransitionInAbove( mDisabledBackgroundContent, mBackgroundContent );
+      AddButtonImage( mDisabledBackgroundContent );
+      TransitionButtonImage( mBackgroundContent );
+      TransitionButtonImage( mSelectedBackgroundContent );
+      AddButtonImage( mDisabledSelectedContent );
+      TransitionButtonImage( mSelectedContent );
+      ReAddLabel();
 
       TransitionOut( mUnselectedContent );
       TransitionOut( mDisabledContent );
 
       TransitionOut( mUnselectedContent );
       TransitionOut( mDisabledContent );
@@ -314,9 +327,11 @@ void Button::SetSelected( bool selected, bool emitSignal )
       //(2) mSelectedBackgroundContent (Inserted)
       //(1) mBackgroundContent
 
       //(2) mSelectedBackgroundContent (Inserted)
       //(1) mBackgroundContent
 
-      TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent );
-      TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent );
-      TransitionInAtIndex( 0, mBackgroundContent );
+      AddButtonImage( mBackgroundContent );
+      TransitionButtonImage( mSelectedBackgroundContent );
+      AddButtonImage( mUnselectedContent );
+      TransitionButtonImage( mSelectedContent );
+      ReAddLabel();
 
       TransitionOut( mUnselectedContent );
       TransitionOut( mDisabledContent );
 
       TransitionOut( mUnselectedContent );
       TransitionOut( mDisabledContent );
@@ -333,8 +348,10 @@ void Button::SetSelected( bool selected, bool emitSignal )
       //(2) mSelectedContent
       //(1) mBackgroundContent
 
       //(2) mSelectedContent
       //(1) mBackgroundContent
 
-      TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent );
-      TransitionInAtIndex( 0, mBackgroundContent );
+      AddButtonImage( mBackgroundContent );
+      AddButtonImage( mSelectedContent );
+      TransitionButtonImage( mUnselectedContent );
+      ReAddLabel();
 
       TransitionOut( mSelectedContent );
       TransitionOut( mSelectedBackgroundContent );
 
       TransitionOut( mSelectedContent );
       TransitionOut( mSelectedBackgroundContent );
@@ -954,9 +971,11 @@ void Button::Pressed()
     //(2) mSelectedBackgroundContent (Inserted)
     //(1) mBackgroundContent
 
     //(2) mSelectedBackgroundContent (Inserted)
     //(1) mBackgroundContent
 
-    TransitionInBetween( mUnselectedContent, mLabel, mSelectedContent );
-    TransitionInAbove( mBackgroundContent, mSelectedBackgroundContent );
-    TransitionInAtIndex( 0, mBackgroundContent );
+    AddButtonImage( mBackgroundContent );
+    TransitionButtonImage( mSelectedBackgroundContent );
+    AddButtonImage( mUnselectedContent );
+    TransitionButtonImage( mSelectedContent );
+    ReAddLabel();
 
     TransitionOut( mUnselectedContent );
     TransitionOut( mDisabledContent );
 
     TransitionOut( mUnselectedContent );
     TransitionOut( mDisabledContent );
@@ -983,8 +1002,10 @@ void Button::Released()
     //(2) mSelectedContent
     //(1) mBackgroundContent
 
     //(2) mSelectedContent
     //(1) mBackgroundContent
 
-    TransitionInBetween( mSelectedContent, mLabel, mUnselectedContent );
-    TransitionInAtIndex( 0, mBackgroundContent );
+    AddButtonImage( mBackgroundContent );
+    AddButtonImage( mSelectedContent );
+    TransitionButtonImage( mUnselectedContent );
+    ReAddLabel();
 
     TransitionOut( mSelectedContent );
     TransitionOut( mSelectedBackgroundContent );
 
     TransitionOut( mSelectedContent );
     TransitionOut( mSelectedBackgroundContent );
@@ -1008,16 +1029,44 @@ Button::PaintState Button::GetPaintState()
   return mPaintState;
 }
 
   return mPaintState;
 }
 
-bool Button::InsertButtonImage( unsigned int index, Actor& actor )
+void Button::PrepareAddButtonImage( Actor& actor )
 {
   if( actor )
   {
 {
   if( actor )
   {
-    Self().Insert( index, actor );
+    actor.Unparent();
+    Self().Add( actor );
     PrepareForTranstionOut( actor );
     PrepareForTranstionOut( actor );
-    return true;
   }
   }
+}
 
 
-  return false;
+void Button::TransitionButtonImage( Actor& actor )
+{
+  if( actor )
+  {
+    if( !actor.GetParent() )
+    {
+      Self().Add( actor );
+    }
+
+    OnTransitionIn( actor );
+  }
+}
+
+void Button::AddButtonImage( Actor& actor )
+{
+  if( actor )
+  {
+    Self().Add( actor );
+  }
+}
+
+void Button::ReAddLabel()
+{
+  if( mLabel )
+  {
+    mLabel.Unparent();
+    Self().Add( mLabel );
+  }
 }
 
 void Button::RemoveButtonImage( Actor& actor )
 }
 
 void Button::RemoveButtonImage( Actor& actor )
@@ -1049,31 +1098,6 @@ unsigned int Button::FindChildIndex( Actor& actor )
   return childrenNum;
 }
 
   return childrenNum;
 }
 
-void Button::TransitionInBetween(  Actor childLower, Actor childUpper, Actor actor )
-{
-  unsigned int index = childLower ? FindChildIndex( childLower ) + 1 : FindChildIndex( childUpper );
-  TransitionInAtIndex( index, actor );
-}
-
-void Button::TransitionInAbove( Actor child, Actor actor )
-{
-  unsigned int index = child ? FindChildIndex( child ) + 1 : 0;
-  TransitionInAtIndex( index, actor );
-}
-
-void Button::TransitionInAtIndex( unsigned int index, Actor actor )
-{
-  if( actor )
-  {
-    if( !actor.GetParent() )
-    {
-      Self().Insert( index, actor );
-    }
-
-    OnTransitionIn( actor );
-  }
-}
-
 void Button::TransitionOut( Actor actor )
 {
   OnTransitionOut( actor );
 void Button::TransitionOut( Actor actor )
 {
   OnTransitionOut( actor );
@@ -1081,9 +1105,8 @@ void Button::TransitionOut( Actor actor )
 
 void Button::ResetImageLayers()
 {
 
 void Button::ResetImageLayers()
 {
-  //ensure that all layers are in the correct order and state according to the paint state
+  // Ensure that all layers are in the correct order and state according to the paint state
 
 
-  int index = 0;
   switch( mPaintState )
   {
     case UnselectedState:
   switch( mPaintState )
   {
     case UnselectedState:
@@ -1098,14 +1121,8 @@ void Button::ResetImageLayers()
       RemoveButtonImage( mDisabledSelectedContent );
       RemoveButtonImage( mDisabledBackgroundContent );
 
       RemoveButtonImage( mDisabledSelectedContent );
       RemoveButtonImage( mDisabledBackgroundContent );
 
-      if( InsertButtonImage( index, mBackgroundContent ) )
-      {
-        ++index;
-      }
-      if( InsertButtonImage( index, mUnselectedContent ) )
-      {
-        ++index;
-      }
+      PrepareAddButtonImage( mBackgroundContent );
+      PrepareAddButtonImage( mUnselectedContent );
       break;
     }
     case SelectedState:
       break;
     }
     case SelectedState:
@@ -1120,18 +1137,10 @@ void Button::ResetImageLayers()
       RemoveButtonImage( mDisabledSelectedContent );
       RemoveButtonImage( mDisabledBackgroundContent );
 
       RemoveButtonImage( mDisabledSelectedContent );
       RemoveButtonImage( mDisabledBackgroundContent );
 
-      if( InsertButtonImage( index, mBackgroundContent ) )
-      {
-        ++index;
-      }
-      if( InsertButtonImage( index, mSelectedBackgroundContent ) )
-      {
-        ++index;
-      }
-      if( InsertButtonImage( index, mSelectedContent ) )
-      {
-        ++index;
-      }
+      PrepareAddButtonImage( mBackgroundContent );
+      PrepareAddButtonImage( mSelectedBackgroundContent );
+      PrepareAddButtonImage( mSelectedContent );
+      ReAddLabel();
       break;
     }
     case DisabledUnselectedState:
       break;
     }
     case DisabledUnselectedState:
@@ -1146,14 +1155,9 @@ void Button::ResetImageLayers()
       RemoveButtonImage( mDisabledSelectedContent );
       RemoveButtonImage( mSelectedBackgroundContent );
 
       RemoveButtonImage( mDisabledSelectedContent );
       RemoveButtonImage( mSelectedBackgroundContent );
 
-      if( InsertButtonImage( index, mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ) )
-      {
-        ++index;
-      }
-      if( InsertButtonImage( index, mDisabledContent ? mDisabledContent : mUnselectedContent ) )
-      {
-        ++index;
-      }
+      PrepareAddButtonImage( mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent );
+      PrepareAddButtonImage( mDisabledContent ? mDisabledContent : mUnselectedContent );
+      ReAddLabel();
       break;
     }
     case DisabledSelectedState:
       break;
     }
     case DisabledSelectedState:
@@ -1170,27 +1174,16 @@ void Button::ResetImageLayers()
 
       if( mDisabledBackgroundContent )
       {
 
       if( mDisabledBackgroundContent )
       {
-        if( InsertButtonImage( index, mDisabledBackgroundContent) )
-        {
-          ++index;
-        }
+        PrepareAddButtonImage( mDisabledBackgroundContent );
       }
       else
       {
       }
       else
       {
-        if( InsertButtonImage( index, mBackgroundContent ) )
-        {
-          ++index;
-        }
-        if( InsertButtonImage( index, mSelectedBackgroundContent ) )
-        {
-          ++index;
-        }
+        PrepareAddButtonImage( mBackgroundContent );
+        PrepareAddButtonImage( mSelectedBackgroundContent );
       }
 
       }
 
-      if( InsertButtonImage( index, mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent) )
-      {
-        ++index;
-      }
+      PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent );
+      ReAddLabel();
       break;
     }
   }
       break;
     }
   }
index 89f0591..a17d058 100644 (file)
@@ -578,45 +578,43 @@ private:
   void ResetImageLayers();
 
   /**
   void ResetImageLayers();
 
   /**
-   * Transitions in the actor, inserting the actor above childLower below the childUpper.
-   * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor)
+   * Transitions out the actor
    */
    */
-  void TransitionInBetween( Actor childLower, Actor childUpper, Actor actor );
+  void TransitionOut( Actor actor );
 
   /**
 
   /**
-   * Transitions in the actor, inserting the actor above the child if the child exists or at the bottom otherwise
-   * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor)
+   * Removes the actor from the button and prepares it to be transitioned out
    */
    */
-  void TransitionInAbove( Actor child, Actor actor );
+  void RemoveButtonImage( Actor& actor );
 
   /**
 
   /**
-   * Transitions in the actor, inserting the actor at the index
-   * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor)
+   * Finds the index of the actor.
+   * If the actor doesn't exist, return the last index + 1.
    */
    */
-  void TransitionInAtIndex( unsigned int index, Actor actor );
+  unsigned int FindChildIndex( Actor& actor );
 
   /**
 
   /**
-   * Transitions out the actor
+   * Adds an actor to the hierarchy and prepares it to be transitioned.
+   * @param[in] actor The actor to add
    */
    */
-  void TransitionOut( Actor actor );
+  void PrepareAddButtonImage( Actor& actor );
 
   /**
 
   /**
-   * Inserts the actor to the button and prepares it to be transitioned out
-   * @return true if the child was inserted, false otherwise
+   * Adds an actor to the hierarchy and marks it to be transitioned.
+   * @param[in] actor The actor to add
    */
    */
-  bool InsertButtonImage( unsigned int index, Actor& actor );
+  void TransitionButtonImage( Actor& actor );
 
   /**
 
   /**
-   * Removes the actor from the button and prepares it to be transitioned out
+   * Adds an actor to the hierarchy.
+   * @param[in] actor The actor to add
    */
    */
-  void RemoveButtonImage( Actor& actor );
+  void AddButtonImage( Actor& actor );
 
   /**
 
   /**
-   * Finds the index of the actor.
-   * If the actor doesn't exist, return the last index + 1.
+   * (Re)Adds the label (if exists) to the hierarchy (so it is always on top).
    */
    */
-  unsigned int FindChildIndex( Actor& actor );
-
+  void ReAddLabel();
 
   // Undefined
   Button( const Button& );
 
   // Undefined
   Button( const Button& );
index 1ee6b92..b6efdf8 100644 (file)
@@ -241,8 +241,11 @@ Vector3 PushButton::GetNaturalSize()
   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );
   if( label )
   {
   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );
   if( label )
   {
-    size.width  = std::max( size.width,  label.GetRelayoutSize( Dimension::WIDTH ) );
-    size.height = std::max( size.height, label.GetRelayoutSize( Dimension::HEIGHT ) );
+    Padding padding( 0.0f, 0.0f, 0.0f, 0.0f );
+    label.GetPadding( padding );
+    size = label.GetNaturalSize();
+    size.width += padding.x + padding.width;
+    size.height += padding.y + padding.height;
   }
   else
   {
   }
   else
   {
index 6434772..a346005 100644 (file)
@@ -584,8 +584,8 @@ void Control::SetBackgroundColor( const Vector4& color )
     Actor actor = CreateBackground(Self(), color );
     background.actor = actor;
     mImpl->mAddRemoveBackgroundChild = true;
     Actor actor = CreateBackground(Self(), color );
     background.actor = actor;
     mImpl->mAddRemoveBackgroundChild = true;
-    // use insert to guarantee its the first child (so that OVERLAY_2D mode works)
-    Self().Insert( 0, actor );
+    // The actor does not need to be inserted to guarantee order.
+    Self().Add( actor );
     mImpl->mAddRemoveBackgroundChild = false;
   }
 
     mImpl->mAddRemoveBackgroundChild = false;
   }
 
@@ -619,8 +619,8 @@ void Control::SetBackgroundImage( Image image )
    // Set the background actor before adding so that we do not inform derived classes
    background.actor = actor;
    mImpl->mAddRemoveBackgroundChild = true;
    // Set the background actor before adding so that we do not inform derived classes
    background.actor = actor;
    mImpl->mAddRemoveBackgroundChild = true;
-   // use insert to guarantee its the first child (so that OVERLAY_2D mode works)
-   Self().Insert( 0, actor );
+   // The actor does not need to be inserted to guarantee order.
+   Self().Add( actor );
    mImpl->mAddRemoveBackgroundChild = false;
 }
 
    mImpl->mAddRemoveBackgroundChild = false;
 }