Button Label properties can now be set via Property::Map 00/45400/13
authorTom Robinson <tom.robinson@samsung.com>
Wed, 5 Aug 2015 14:29:20 +0000 (15:29 +0100)
committerTom Robinson <tom.robinson@samsung.com>
Thu, 6 Aug 2015 13:39:44 +0000 (06:39 -0700)
Change-Id: I3f3388125c39eaa6d6279a4f084042e863fff439

dali-toolkit/internal/controls/buttons/button-impl.cpp
dali-toolkit/internal/controls/buttons/button-impl.h
dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp
dali-toolkit/public-api/controls/buttons/button.h
dali-toolkit/styles/480x800/dali-toolkit-default-theme.json
dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json

index ff395ae..a4c5101 100644 (file)
@@ -87,13 +87,18 @@ DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-image",         STR
 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-image",         STRING,  DISABLED_STATE_IMAGE         )
 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselected-color",             VECTOR4, UNSELECTED_COLOR             )
 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-color",               VECTOR4, SELECTED_COLOR               )
+DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label",                        MAP,     LABEL                        )
+
+// Deprecated properties:
 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-text",                   STRING,  LABEL_TEXT                   )
 
+// Signals:
 DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "pressed",                               SIGNAL_PRESSED               )
 DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "released",                              SIGNAL_RELEASED              )
 DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "clicked",                               SIGNAL_CLICKED               )
 DALI_SIGNAL_REGISTRATION(   Toolkit, Button, "state-changed",                         SIGNAL_STATE_CHANGED         )
 
+// Actions:
 DALI_ACTION_REGISTRATION(   Toolkit, Button, "button-click",                          ACTION_BUTTON_CLICK          )
 
 DALI_TYPE_REGISTRATION_END()
@@ -101,8 +106,6 @@ DALI_TYPE_REGISTRATION_END()
 const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
 const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
 
-const char* const STYLE_BUTTON_LABEL = "button.label";
-
 } // unnamed namespace
 
 Button::Button()
@@ -428,27 +431,9 @@ float Button::GetAnimationTime() const
 
 void Button::SetLabelText( const std::string& label )
 {
-  if( !mLabel || ( label != GetLabelText() ) )
-  {
-    // If we have a label, unparent and update it.
-    if( mLabel )
-    {
-      mLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, label );
-    }
-    else
-    {
-      // If we don't have a label, create one and set it up.
-      mLabel = Toolkit::TextLabel::New( label );
-      mLabel.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_LABEL );
-      mLabel.SetPosition( 0.f, 0.f );
-      // label should be the top of the button
-      Self().Add( mLabel );
-    }
-
-    OnLabelSet( false );
-
-    RelayoutRequest();
-  }
+  Property::Map labelProperty;
+  labelProperty.Insert( "text", label );
+  ModifyLabel( labelProperty );
 }
 
 std::string Button::GetLabelText() const
@@ -461,6 +446,40 @@ std::string Button::GetLabelText() const
   return std::string();
 }
 
+void Button::ModifyLabel( const Property::Map& properties )
+{
+  // If we don't have a label yet, create one.
+  if( !mLabel )
+  {
+    // If we don't have a label, create one and set it up.
+    // Note: The label text is set from the passed in property map after creation.
+    mLabel = Toolkit::TextLabel::New();
+    mLabel.SetPosition( 0.0f, 0.0f );
+    // label should be the top of the button
+    Self().Add( mLabel );
+  }
+
+  // Set any properties specified for the label by iterating through all property key-value pairs.
+  for( unsigned int i = 0, mapCount = properties.Count(); i < mapCount; ++i )
+  {
+    const StringValuePair& propertyPair( properties.GetPair( i ) );
+
+    // Convert the property string to a property index.
+    Property::Index setPropertyIndex = mLabel.GetPropertyIndex( propertyPair.first );
+    if( setPropertyIndex != Property::INVALID_INDEX )
+    {
+      // If the conversion worked, we have a valid property index,
+      // Set the property to the new value.
+      mLabel.SetProperty( setPropertyIndex, propertyPair.second );
+    }
+  }
+
+  // Notify derived button classes of the change.
+  OnLabelSet( false );
+
+  RelayoutRequest();
+}
+
 Actor& Button::GetLabelActor()
 {
   return mLabel;
@@ -1468,6 +1487,17 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope
         GetImplementation( button ).SetLabelText( value.Get< std::string >() );
         break;
       }
+
+      case Toolkit::Button::Property::LABEL:
+      {
+        // Get a Property::Map from the property if possible.
+        Property::Map setPropertyMap;
+        if( value.Get( setPropertyMap ) )
+        {
+          GetImplementation( button ).ModifyLabel( setPropertyMap );
+        }
+      }
+      break;
     }
   }
 }
@@ -1553,6 +1583,13 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert
         value = GetImplementation( button ).GetLabelText();
         break;
       }
+
+      case Toolkit::Button::Property::LABEL:
+      {
+        Property::Map emptyMap;
+        value = emptyMap;
+        break;
+      }
     }
   }
 
@@ -1571,8 +1608,7 @@ void Button::SetLabel( Actor label )
     }
 
     mLabel = label;
-    mLabel.SetProperty( Toolkit::Control::Property::STYLE_NAME, STYLE_BUTTON_LABEL );
-    mLabel.SetPosition( 0.f, 0.f );
+    mLabel.SetPosition( 0.0f, 0.0f );
 
     // label should be the top of the button
     Self().Add( mLabel );
index d9d4bd6..7adb67c 100644 (file)
@@ -58,72 +58,72 @@ protected:
 public:
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetDisabled( bool disabled )
+   * @copydoc Dali::Toolkit::Button::SetDisabled
    */
   void SetDisabled( bool disabled );
 
   /**
-   * @copydoc Dali::Toolkit::Button::IsDisabled() const
+   * @copydoc Dali::Toolkit::Button::IsDisabled
    */
   bool IsDisabled() const;
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetAutoRepeating( bool autoRepeating )
+   * @copydoc Dali::Toolkit::Button::SetAutoRepeating
    */
   void SetAutoRepeating( bool autoRepeating );
 
   /**
-   * @copydoc Dali::Toolkit::Button::IsAutoRepeating() const
+   * @copydoc Dali::Toolkit::Button::IsAutoRepeating
    */
   bool IsAutoRepeating() const;
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
+   * @copydoc Dali::Toolkit::Button::SetInitialAutoRepeatingDelay
    */
   void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
 
   /**
-   * @copydoc Dali::Toolkit::Button::GetInitialAutoRepeatingDelay() const
+   * @copydoc Dali::Toolkit::Button::GetInitialAutoRepeatingDelay
    */
   float GetInitialAutoRepeatingDelay() const;
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
+   * @copydoc Dali::Toolkit::Button::SetNextAutoRepeatingDelay
    */
   void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
 
   /**
-   * @copydoc Dali::Toolkit::Button::GetNextAutoRepeatingDelay() const
+   * @copydoc Dali::Toolkit::Button::GetNextAutoRepeatingDelay
    */
   float GetNextAutoRepeatingDelay() const;
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetTogglableButton( bool togglable )
+   * @copydoc Dali::Toolkit::Button::SetTogglableButton
    */
   void SetTogglableButton( bool togglable );
 
   /**
-   * @copydoc Dali::Toolkit::Button::IsTogglableButton() const
+   * @copydoc Dali::Toolkit::Button::IsTogglableButton
    */
   bool IsTogglableButton() const;
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetSelected( bool selected )
+   * @copydoc Dali::Toolkit::Button::SetSelected
    */
   void SetSelected( bool selected );
 
   /**
-   * @copydoc Dali::Toolkit::Button::IsSelected() const
+   * @copydoc Dali::Toolkit::Button::IsSelected
    */
   bool IsSelected() const;
 
   /**
-   * @copydoc Dali::Toolkit::Button::SetAnimationTime()
+   * @copydoc Dali::Toolkit::Button::SetAnimationTime
    */
   void SetAnimationTime( float animationTime );
 
   /**
-   * @copydoc Dali::Toolkit::Button::GetAnimationTime()
+   * @copydoc Dali::Toolkit::Button::GetAnimationTime
    */
   float GetAnimationTime() const;
 
@@ -208,6 +208,14 @@ public:
   std::string GetDisabledBackgroundImageFilename() const;
 
   /**
+   * @brief Sets the specified properties on the button label.
+   * If the label does not exist yet, it is created.
+   * The derived buttons are notified if any properties are changed.
+   * @param[in] properties A Property::Map of key-value pairs of properties to set.
+   */
+  void ModifyLabel( const Property::Map& properties );
+
+  /**
    * Performs actions as requested using the action name.
    * @param[in] object The object on which to perform the action.
    * @param[in] actionName The action to perform.
@@ -266,12 +274,12 @@ public: // Deprecated API
   void SetDisabledBackgroundImage( Actor image );
 
   /**
-   * @copydoc Dali::Toolkit::Button::GetButtonImage()
+   * @copydoc Dali::Toolkit::Button::GetButtonImage
    */
   Actor GetButtonImage() const;
 
   /**
-   * @copydoc Dali::Toolkit::Button::GetSelectedImage()
+   * @copydoc Dali::Toolkit::Button::GetSelectedImage
    */
   Actor GetSelectedImage() const;
 
index 0c47877..68a30c5 100644 (file)
@@ -30,6 +30,7 @@
 #include <dali/public-api/images/resource-image.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/vector4.h>
+#include <dali/public-api/object/property-map.h>
 #include <dali/devel-api/object/type-registry-helper.h>
 
 #include <libintl.h>
@@ -49,7 +50,7 @@ namespace
 // todo Move this to adaptor??
 #define GET_LOCALE_TEXT(string) dgettext("elementary", string)
 
-const std::string TEXT_SELECTION_POPUP_LABEL( "textselectionpopuplabel" );
+const std::string TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME( "textselectionpopupbutton" );
 const Dali::Vector4 DEFAULT_OPTION_PRESSED_COLOR( Dali::Vector4( 0.24f, 0.72f, 0.8f, 1.0f ) );
 
 #ifdef DGETTEXT_ENABLED
@@ -688,8 +689,13 @@ std::string TextSelectionPopup::GetPressedImage() const
    // 2. Set the options contents.
    if( showCaption )
    {
+     // PushButton layout properties.
      option.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 24.0f, 24.0f, 14.0f, 14.0f ) );
-     option.SetLabelText( button.caption );
+
+     // Label properties.
+     Property::Map buttonLabelProperties;
+     buttonLabelProperties.Insert( "text", button.caption );
+     option.SetProperty( Toolkit::Button::Property::LABEL, buttonLabelProperties );
    }
    if( showIcons )
    {
@@ -708,6 +714,7 @@ std::string TextSelectionPopup::GetPressedImage() const
    // The image can be blank, the color can be used regardless.
    option.SetSelectedImage( mPressedImage );
    option.SetProperty( Toolkit::Button::Property::SELECTED_COLOR, mPressedColor );
+   option.SetProperty( Toolkit::Control::Property::STYLE_NAME, TEXT_SELECTION_POPUP_BUTTON_STYLE_NAME );
 
    // 5 Add option to tool bar
    mToolbar.AddOption( option );
index 9ba5348..9c0eba0 100644 (file)
@@ -106,8 +106,11 @@ public:
       UNSELECTED_STATE_IMAGE,          ///< name "unselected-state-image",       @see SetUnselectedImage(),           type std::string
       SELECTED_STATE_IMAGE,            ///< name "selected-state-image",         @see SetSelectedImage(),             type std::string
       DISABLED_STATE_IMAGE,            ///< name "disabled-state-image",         @see SetDisabledImage(),             type std::string
-      UNSELECTED_COLOR,                ///< name "unselected-color",             @see SetUnselectedColor(),           type Vector4
-      SELECTED_COLOR,                  ///< name "selected-color",               @see SetSelectedColor(),             type Vector4
+      UNSELECTED_COLOR,                ///< name "unselected-color",                                                  type Vector4
+      SELECTED_COLOR,                  ///< name "selected-color",                                                    type Vector4
+      LABEL,                           ///< name "label",                                                             type Property::Map
+
+      // Deprecated properties:
       LABEL_TEXT,                      ///< name "label-text",                   @see SetLabelText(),                 type std::string
     };
   };
index b71bf26..cb7f5e1 100644 (file)
@@ -102,6 +102,13 @@ distributing this software or its derivatives.
       "popup-fade-in-duration":0.25,
       "popup-fade-out-duration":0.25
     },
+    "textselectionpopupbutton":
+    {
+      "label":
+      {
+        "point-size":8
+      }
+    },
     "scrollview":
     {
       "overshoot-effect-color":"B018"
index cd6b94a..ce53bbb 100644 (file)
@@ -102,6 +102,13 @@ distributing this software or its derivatives.
       "popup-fade-in-duration":0.25,
       "popup-fade-out-duration":0.25
     },
+    "textselectionpopupbutton":
+    {
+      "label":
+      {
+        "point-size":8
+      }
+    },
     "scrollview":
     {
       "overshoot-effect-color":"B018"