Keep legacy look of buttons with pre Visual API 45/103545/6
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Thu, 8 Dec 2016 14:25:43 +0000 (14:25 +0000)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Tue, 13 Dec 2016 13:22:23 +0000 (13:22 +0000)
Change-Id: Ief4e1bb2bb3efe0871d86d4aae7c503e1e2708b0

automated-tests/src/dali-toolkit/utc-Dali-Button.cpp
automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp
dali-toolkit/internal/controls/buttons/button-impl.cpp

index c0598cb..a2bf49d 100644 (file)
@@ -27,6 +27,7 @@
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali/integration-api/events/touch-event-integ.h>
 
+#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
 
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
 
@@ -271,8 +272,8 @@ int UtcDaliButtonPropertyGetLabelAlignment(void)
   tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n");
 
   Button button = PushButton::New();
   tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n");
 
   Button button = PushButton::New();
-  button.SetProperty( Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT, "END"  );
-  DALI_TEST_EQUALS( button.GetProperty<std::string>( Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT ), "END", TEST_LOCATION );
+  button.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "END"  );
+  DALI_TEST_EQUALS( button.GetProperty<std::string>( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT ), "END", TEST_LOCATION );
 
   END_TEST;
 }
 
   END_TEST;
 }
index 5ca3310..5ae6ee7 100644 (file)
@@ -26,6 +26,7 @@
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali-toolkit/dali-toolkit.h>
 
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali-toolkit/dali-toolkit.h>
 
+#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
 
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
 
@@ -1018,7 +1019,7 @@ int UtcDaliPushButtonSetUnSelectedVisual01P(void)
   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
   propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
 
   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
   propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
 
-  pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
+  pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
 
   tet_infoline(" UNSELECTED_VISUAL Added to button\n");
 
 
   tet_infoline(" UNSELECTED_VISUAL Added to button\n");
 
@@ -1044,7 +1045,7 @@ int UtcDaliPushButtonSetUnSelectedVisual01P(void)
   Property::Map propertyMap2;
   propertyMap2.Insert(Visual::Property::TYPE,  Visual::COLOR);
   propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
   Property::Map propertyMap2;
   propertyMap2.Insert(Visual::Property::TYPE,  Visual::COLOR);
   propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
-  pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap2 );
+  pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap2 );
 
   tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
 
 
   tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
 
@@ -1087,7 +1088,7 @@ int UtcDaliPushButtonSetSelectedVisualN(void)
   colorMap.Insert(Visual::Property::TYPE,  BROKEN_VISUAL_TYPE);
   colorMap.Insert(BorderVisual::Property::COLOR,  Color::BLUE);
   colorMap.Insert(BorderVisual::Property::SIZE,  5.f);
   colorMap.Insert(Visual::Property::TYPE,  BROKEN_VISUAL_TYPE);
   colorMap.Insert(BorderVisual::Property::COLOR,  Color::BLUE);
   colorMap.Insert(BorderVisual::Property::SIZE,  5.f);
-  pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, colorMap );
+  pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, colorMap );
 
   Stage::GetCurrent().Add( pushButton );
   application.SendNotification();
 
   Stage::GetCurrent().Add( pushButton );
   application.SendNotification();
index 661e3b2..aef2ddf 100644 (file)
@@ -776,34 +776,52 @@ Vector3 Button::GetNaturalSize()
   bool horizontalAlignment = mTextLabelAlignment == BEGIN || mTextLabelAlignment == END; // label and visual side by side
 
   // Get natural size of foreground ( largest of the possible visuals )
   bool horizontalAlignment = mTextLabelAlignment == BEGIN || mTextLabelAlignment == END; // label and visual side by side
 
   // Get natural size of foreground ( largest of the possible visuals )
-  Size largestForegroundVisual;
+  Size largestProvidedVisual;
   Size labelSize = Size::ZERO;
 
   Size labelSize = Size::ZERO;
 
-  for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++)
+  bool foreGroundVisualUsed = false;
+
+  for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++ )
   {
     Toolkit::Visual::Base visual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
     Size visualSize;
     if ( visual )
     {
       visual.GetNaturalSize( visualSize );
   {
     Toolkit::Visual::Base visual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
     Size visualSize;
     if ( visual )
     {
       visual.GetNaturalSize( visualSize );
-      largestForegroundVisual.width = std::max(largestForegroundVisual.width, visualSize.width );
-      largestForegroundVisual.height = std::max(largestForegroundVisual.height, visualSize.height );
+      largestProvidedVisual.width = std::max(largestProvidedVisual.width, visualSize.width );
+      largestProvidedVisual.height = std::max(largestProvidedVisual.height, visualSize.height );
+      foreGroundVisualUsed = true;
+    }
+  }
+
+  if ( !foreGroundVisualUsed ) // If foreground visual not supplied then use the background visual to calculate Natural size
+  {
+    for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++ )
+    {
+      Toolkit::Visual::Base visual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND] );
+      Size visualSize;
+      if ( visual )
+      {
+        visual.GetNaturalSize( visualSize );
+        largestProvidedVisual.width = std::max(largestProvidedVisual.width, visualSize.width );
+        largestProvidedVisual.height = std::max(largestProvidedVisual.height, visualSize.height );
+      }
     }
   }
 
   // Get horizontal padding total
     }
   }
 
   // Get horizontal padding total
-  if ( largestForegroundVisual.width > 0 )  // if visual exists
+  if ( largestProvidedVisual.width > 0 )  // if visual exists
   {
   {
-    size.width += largestForegroundVisual.width + mForegroundPadding.left + mForegroundPadding.right;
+    size.width += largestProvidedVisual.width + mForegroundPadding.left + mForegroundPadding.right;
   }
   // Get vertical padding total
   }
   // Get vertical padding total
-  if ( largestForegroundVisual.height > 0 )
+  if ( largestProvidedVisual.height > 0 )
   {
   {
-    size.height += largestForegroundVisual.height + mForegroundPadding.top + mForegroundPadding.bottom;
+    size.height += largestProvidedVisual.height + mForegroundPadding.top + mForegroundPadding.bottom;
   }
 
   DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize visual Size(%f,%f)\n",
   }
 
   DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize visual Size(%f,%f)\n",
-                 largestForegroundVisual.width, largestForegroundVisual.height );
+                 largestProvidedVisual.width, largestProvidedVisual.height );
 
   // Get natural size of label if text has been set
   if ( mTextStringSetFlag )
 
   // Get natural size of label if text has been set
   if ( mTextStringSetFlag )
@@ -1141,17 +1159,17 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope
 
       case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: // Legacy Tizen 3.0
       {
 
       case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: // Legacy Tizen 3.0
       {
-        GetImplementation( button ).CreateVisualsForComponent( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
+        GetImplementation( button ).CreateVisualsForComponent( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, value, DepthIndex::BACKGROUND );
         break;
       }
       case Toolkit::Button::Property::DISABLED_STATE_IMAGE:  // Legacy Tizen 3.0
       {
         break;
       }
       case Toolkit::Button::Property::DISABLED_STATE_IMAGE:  // Legacy Tizen 3.0
       {
-        GetImplementation( button ).CreateVisualsForComponent( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
+        GetImplementation( button ).CreateVisualsForComponent( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, value, DepthIndex::BACKGROUND );
         break;
       }
       case Toolkit::Button::Property::SELECTED_STATE_IMAGE:  // Legacy Tizen 3.0
       {
         break;
       }
       case Toolkit::Button::Property::SELECTED_STATE_IMAGE:  // Legacy Tizen 3.0
       {
-        GetImplementation( button ).CreateVisualsForComponent( Toolkit::DevelButton::Property::SELECTED_VISUAL, value, DepthIndex::CONTENT );
+        GetImplementation( button ).CreateVisualsForComponent( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, value, DepthIndex::BACKGROUND );
         break;
       }
       case Toolkit::DevelButton::Property::UNSELECTED_VISUAL:
         break;
       }
       case Toolkit::DevelButton::Property::UNSELECTED_VISUAL:
@@ -1285,19 +1303,19 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert
 
       case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
       {
 
       case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
       {
-        value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::UNSELECTED_VISUAL );
+        value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL );
         break;
       }
 
       case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
       {
         break;
       }
 
       case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
       {
-        value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::SELECTED_VISUAL );
+        value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL );
         break;
       }
 
       case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
       {
         break;
       }
 
       case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
       {
-        value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL );
+        value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL );
         break;
       }
 
         break;
       }
 
@@ -1449,10 +1467,7 @@ void Button::SetLabel( Actor label )
 
 void Button::SetUnselectedImage( const std::string& filename )
 {
 
 void Button::SetUnselectedImage( const std::string& filename )
 {
-  if( !filename.empty() )
-  {
-    CreateVisualsForComponent( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
-  }
+  SetBackgroundImage( filename );
 }
 
 void Button::SetBackgroundImage( const std::string& filename )
 }
 
 void Button::SetBackgroundImage( const std::string& filename )
@@ -1461,14 +1476,15 @@ void Button::SetBackgroundImage( const std::string& filename )
   {
     CreateVisualsForComponent( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
   }
   {
     CreateVisualsForComponent( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
   }
+  else
+  {
+    UnregisterVisual( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL );
+  }
 }
 
 void Button::SetSelectedImage( const std::string& filename )
 {
 }
 
 void Button::SetSelectedImage( const std::string& filename )
 {
-  if( !filename.empty() )
-  {
-    CreateVisualsForComponent( Toolkit::DevelButton::Property::SELECTED_VISUAL, filename, DepthIndex::CONTENT );
-  }
+    SetSelectedBackgroundImage( filename );
 }
 
 void Button::SetSelectedBackgroundImage( const std::string& filename )
 }
 
 void Button::SetSelectedBackgroundImage( const std::string& filename )
@@ -1477,6 +1493,10 @@ void Button::SetSelectedBackgroundImage( const std::string& filename )
   {
     CreateVisualsForComponent( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
   }
   {
     CreateVisualsForComponent( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
   }
+  else
+  {
+    UnregisterVisual( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL );
+  }
 }
 
 void Button::SetDisabledBackgroundImage( const std::string& filename )
 }
 
 void Button::SetDisabledBackgroundImage( const std::string& filename )
@@ -1558,7 +1578,7 @@ void Button::SetSelectedImage( Image image )
 Actor Button::GetButtonImage() const
 {
   DALI_LOG_WARNING("Button::GetButtonImage @DEPRECATED_1_0.50\n");
 Actor Button::GetButtonImage() const
 {
   DALI_LOG_WARNING("Button::GetButtonImage @DEPRECATED_1_0.50\n");
-  Actor imageView = Toolkit::ImageView::New( GetUrlForImageVisual( Toolkit::DevelButton::Property::UNSELECTED_VISUAL ) );
+  Actor imageView = Toolkit::ImageView::New( GetUrlForImageVisual( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL ) );
 
   return imageView;
 }
 
   return imageView;
 }
@@ -1566,7 +1586,7 @@ Actor Button::GetButtonImage() const
 Actor Button::GetSelectedImage() const
 {
   DALI_LOG_WARNING("Button::GetSelectedImage @DEPRECATED_1_0.50\n");
 Actor Button::GetSelectedImage() const
 {
   DALI_LOG_WARNING("Button::GetSelectedImage @DEPRECATED_1_0.50\n");
-  Actor imageView = Toolkit::ImageView::New( GetUrlForImageVisual( Toolkit::DevelButton::Property::SELECTED_VISUAL ) );
+  Actor imageView = Toolkit::ImageView::New( GetUrlForImageVisual( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL ) );
 
   return imageView;
 }
 
   return imageView;
 }