Control - Trigger the size negotiation when the background is updated.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control-impl.cpp
index a01cc5e..02bbf97 100644 (file)
 #include <dali-toolkit/public-api/styling/style-manager.h>
 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
-#include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
 #include <dali-toolkit/internal/styling/style-manager-impl.h>
 #include <dali-toolkit/internal/visuals/color/color-visual.h>
 #include <dali-toolkit/internal/visuals/transition-data-impl.h>
+#include <dali-toolkit/devel-api/align-enums.h>
 
 namespace Dali
 {
@@ -165,6 +166,16 @@ HandleIndex GetVisualProperty(
   return HandleIndex( handle, Property::INVALID_INDEX );
 }
 
+void SetDefaultTransform( Property::Map& propertyMap )
+{
+  propertyMap.Clear();
+  propertyMap
+    .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 );
+}
 
 /**
  * Creates control through type registry
@@ -531,11 +542,6 @@ Toolkit::Control Control::New()
   return handle;
 }
 
-Control::~Control()
-{
-  delete mImpl;
-}
-
 void Control::SetStyleName( const std::string& styleName )
 {
   if( styleName != mImpl->mStyleName )
@@ -560,7 +566,7 @@ void Control::SetBackgroundColor( const Vector4& color )
 {
   mImpl->mBackgroundColor = color;
   Property::Map map;
-  map[ Toolkit::VisualProperty::TYPE ] = Toolkit::Visual::COLOR;
+  map[ Toolkit::DevelVisual::Property::TYPE ] = Toolkit::Visual::COLOR;
   map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
 
   SetBackground( map );
@@ -578,6 +584,9 @@ void Control::SetBackground( const Property::Map& map )
   {
     RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual );
     visual.SetDepthIndex( DepthIndex::BACKGROUND );
+
+    // Trigger a size negotiation request that may be needed by the new visual to relayout its contents.
+    RelayoutRequest();
   }
 }
 
@@ -596,6 +605,9 @@ void Control::ClearBackground()
 {
    UnregisterVisual( Toolkit::Control::Property::BACKGROUND );
    mImpl->mBackgroundColor = Color::TRANSPARENT;
+
+   // Trigger a size negotiation request that may be needed when unregistering a visual.
+   RelayoutRequest();
 }
 
 void Control::EnableGestureDetection(Gesture::Type type)
@@ -747,22 +759,22 @@ void Control::RegisterVisual( Property::Index index, Toolkit::Visual::Base& visu
   bool visualReplaced ( false );
   Actor self = Self();
 
-  if ( !mImpl->mVisuals.Empty() )
+  if( !mImpl->mVisuals.Empty() )
   {
-      RegisteredVisualContainer::Iterator iter;
-      // Check if visual (index) is already registered.  Replace if so.
-      if ( FindVisual( index, mImpl->mVisuals, iter ) )
+    RegisteredVisualContainer::Iterator iter;
+    // Check if visual (index) is already registered.  Replace if so.
+    if ( FindVisual( index, mImpl->mVisuals, iter ) )
+    {
+      if( (*iter)->visual && self.OnStage() )
       {
-        if( (*iter)->visual && self.OnStage() )
-        {
-          Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
-        }
-        (*iter)->visual = visual;
-        visualReplaced = true;
+        Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
       }
+      (*iter)->visual = visual;
+      visualReplaced = true;
+    }
   }
 
-  if ( !visualReplaced ) // New registration entry
+  if( !visualReplaced ) // New registration entry
   {
     mImpl->mVisuals.PushBack( new RegisteredVisual( index, visual, enabled ) );
   }
@@ -803,6 +815,7 @@ void Control::EnableVisual( Property::Index index, bool enable )
   {
     if (  (*iter)->enabled == enable )
     {
+      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Visual Already enabled set (%s) \n", enable?"enabled":"disabled");
       return;
     }
 
@@ -812,11 +825,12 @@ void Control::EnableVisual( Property::Index index, bool enable )
     {
       if ( enable )
       {
-
+        DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting Visual(%d) on stage \n", index );
         Toolkit::GetImplementation((*iter)->visual).SetOnStage( parentActor );
       }
       else
       {
+        DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::EnableVisual Setting Visual(%d) off stage \n", index );
         Toolkit::GetImplementation((*iter)->visual).SetOffStage( parentActor );  // No need to call if control not staged.
       }
     }
@@ -981,6 +995,11 @@ Control::Control( ControlBehaviour behaviourFlags )
   mImpl->mFlags = behaviourFlags;
 }
 
+Control::~Control()
+{
+  delete mImpl;
+}
+
 void Control::Initialize()
 {
   // Call deriving classes so initialised before styling is applied to them.
@@ -1084,11 +1103,14 @@ void Control::EmitKeyInputFocusSignal( bool focusGained )
 
 void Control::OnStageConnection( int depth )
 {
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection number of registered visuals(%d)\n",  mImpl->mVisuals.Size() );
+
   for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++)
   {
     // Check whether the visual is empty and enabled
     if( (*iter)->visual && (*iter)->enabled )
     {
+      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageConnection Setting visual(%d) on stage\n", (*iter)->index );
       Actor self( Self() );
       Toolkit::GetImplementation((*iter)->visual).SetOnStage( self );
     }
@@ -1102,6 +1124,7 @@ void Control::OnStageDisconnection()
     // Check whether the visual is empty
     if( (*iter)->visual )
     {
+      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageDisconnection Setting visual(%d) off stage\n", (*iter)->index );
       Actor self( Self() );
       Toolkit::GetImplementation((*iter)->visual).SetOffStage( self );
     }
@@ -1136,7 +1159,9 @@ void Control::OnSizeSet(const Vector3& targetSize)
   if( visual )
   {
     Vector2 size( targetSize );
-    visual.SetSize( size );
+    Property::Map transformMap;
+    SetDefaultTransform( transformMap );
+    visual.SetTransformAndSize( transformMap, size );
   }
 }
 
@@ -1171,6 +1196,15 @@ void Control::OnRelayout( const Vector2& size, RelayoutContainer& container )
   {
     container.Add( Self().GetChildAt( i ), size );
   }
+
+  Toolkit::Visual::Base visual = GetVisual( Toolkit::Control::Property::BACKGROUND );
+  if( visual )
+  {
+    Vector2 controlSize( size );
+    Property::Map transformMap;
+    SetDefaultTransform( transformMap );
+    visual.SetTransformAndSize( transformMap, controlSize );
+  }
 }
 
 void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )