From 07d76537f714a144bf02191c96db2480a4b7a621 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Wed, 11 Jan 2017 15:02:55 +0000 Subject: [PATCH] Button needs a simple mechanism to set text label Label property can now take just a string instead of a property map to create text visual Change-Id: I027136406b852fc2de0c99c6a00b614c63bbe432 --- .../src/dali-toolkit/utc-Dali-Button.cpp | 89 +++++++++++++++++++--- .../internal/controls/buttons/button-impl.cpp | 39 +++++++--- .../internal/controls/buttons/button-impl.h | 6 +- dali-toolkit/public-api/controls/buttons/button.h | 2 +- 4 files changed, 109 insertions(+), 27 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp index a2bf49d..9452649 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp @@ -59,6 +59,23 @@ static bool ButtonCallback( Button button ) return false; } +static std::string GetButtonText( Button button ) +{ + Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL ); + + Property::Map *labelProperty = value.GetMap(); + + std::string textLabel; + + if ( labelProperty ) + { + Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT ); + value->Get( textLabel ); + } + + return textLabel; +} + struct CallbackFunctor { CallbackFunctor(bool* callbackFlag) @@ -472,7 +489,7 @@ int UtcDaliButtonSetAnimationTimeP(void) END_TEST; } -int UtcDaliButtonSetLabelStringP(void) +int UtcDaliButtonSetLabelStringWithPropertyMapP(void) { ToolkitTestApplication application; @@ -480,11 +497,28 @@ int UtcDaliButtonSetLabelStringP(void) button.SetProperty( Toolkit::Button::Property::LABEL, Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ) .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ) + .Add( Toolkit::TextVisual::Property::TEXT, "Button Label") ); - button.SetLabelText( "Button Label" ); + DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION ); + END_TEST; +} + +int UtcDaliButtonSetLabelWithStringP(void) +{ + ToolkitTestApplication application; + + Button button = PushButton::New(); + + // Set default point size for text visual as style sheet not available. + button.SetProperty( Toolkit::Button::Property::LABEL, + Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ) + .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ) + ); + + button.SetProperty( Toolkit::Button::Property::LABEL, "Button Label" ); - DALI_TEST_EQUALS( button.GetLabelText(), "Button Label", TEST_LOCATION ); + DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION ); END_TEST; } @@ -492,6 +526,9 @@ int UtcDaliButtonSetLabelPropertyP(void) { ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonSetLabelPropertyP Set text label and then set again with new text"); + + const std::string TEST_LABEL1 = "test label one"; const std::string TEST_LABEL2 = "test label two"; @@ -500,13 +537,10 @@ int UtcDaliButtonSetLabelPropertyP(void) button.SetProperty( Toolkit::Button::Property::LABEL, Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ) .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ) + .Add( Toolkit::TextVisual::Property::TEXT, TEST_LABEL1 ) ); - button.SetProperty( Button::Property::LABEL_TEXT, TEST_LABEL1 ); - - std::string labelText = button.GetProperty( Button::Property::LABEL_TEXT ); - - DALI_TEST_EQUALS( labelText, TEST_LABEL1, TEST_LOCATION ); + DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL1, TEST_LOCATION ); Property::Map propertyMap; propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ); @@ -515,9 +549,7 @@ int UtcDaliButtonSetLabelPropertyP(void) propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); button.SetProperty( Button::Property::LABEL, propertyMap ); - labelText = button.GetProperty( Button::Property::LABEL_TEXT ); - - DALI_TEST_EQUALS( labelText, TEST_LABEL2, TEST_LOCATION ); + DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL2, TEST_LOCATION ); END_TEST; } @@ -1238,3 +1270,38 @@ int UtcDaliButtonSetGetDepreciatedPropertiesWithURL(void) END_TEST; } + +int UtcDaliButtonSetLabelTextDeprecatedPropertyP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonSetLabelTextDeprecatedPropertyP"); + + const std::string TEST_LABEL1 = "test label one"; + const std::string TEST_LABEL2 = "test label two"; + + Button button = PushButton::New(); + + button.SetProperty( Toolkit::Button::Property::LABEL, + Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ) + .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ) + ); + + button.SetProperty( Button::Property::LABEL_TEXT, TEST_LABEL1 ); + + std::string labelText = button.GetProperty( Button::Property::LABEL_TEXT ); + + DALI_TEST_EQUALS( labelText, TEST_LABEL1, TEST_LOCATION ); + + Property::Map propertyMap; + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ); + propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, TEST_LABEL2 ); + propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE ); + propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f ); + button.SetProperty( Button::Property::LABEL, propertyMap ); + + labelText = button.GetProperty( Button::Property::LABEL_TEXT ); + + DALI_TEST_EQUALS( labelText, TEST_LABEL2, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index 0c7005b..ed9b2c8 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -348,11 +348,7 @@ bool Button::IsSelected() const void Button::SetLabelText( const std::string& label ) { - Property::Map labelProperty; - labelProperty.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT) - .Add( Toolkit::TextVisual::Property::TEXT, label ); - - Self().SetProperty( Toolkit::Button::Property::LABEL, labelProperty ); + Self().SetProperty( Toolkit::Button::Property::LABEL, label ); } std::string Button::GetLabelText() const @@ -372,7 +368,7 @@ std::string Button::GetLabelText() const return textLabel; } -void Button::MergeLabelProperties( const Property::Map& inMap, Property::Map& outMap ) +void Button::MergeWithExistingLabelProperties( const Property::Map& inMap, Property::Map& outMap ) { DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "MergeLabelProperties with %d properties\n", inMap.Count() ); @@ -1224,13 +1220,32 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope case Toolkit::Button::Property::LABEL: { - // Get a Property::Map from the property if possible. - Property::Map* setPropertyMap = value.GetMap(); - if( setPropertyMap ) + Property::Map outTextVisualProperties; + std::string textString; + + if ( value.Get( textString ) ) + { + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty Setting TextVisual with string[%s]\n", textString.c_str() ); + + Property::Map setPropertyMap; + setPropertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT) + .Add( Toolkit::TextVisual::Property::TEXT, textString ); + + GetImplementation( button ).MergeWithExistingLabelProperties( setPropertyMap, outTextVisualProperties ); + } + else + { + // Get a Property::Map from the property if possible. + Property::Map* setPropertyMap = value.GetMap(); + if( setPropertyMap ) + { + GetImplementation( button ).MergeWithExistingLabelProperties( *setPropertyMap, outTextVisualProperties ); + } + } + + if( !outTextVisualProperties.Empty() ) { - Property::Map textVisualProperties; - GetImplementation( button ).MergeLabelProperties( *setPropertyMap, textVisualProperties ); - GetImplementation( button ).CreateVisualsForComponent( index, textVisualProperties, DepthIndex::CONTENT ); + GetImplementation( button ).CreateVisualsForComponent( index, outTextVisualProperties, DepthIndex::CONTENT ); GetImplementation( button ).RelayoutRequest(); } break; diff --git a/dali-toolkit/internal/controls/buttons/button-impl.h b/dali-toolkit/internal/controls/buttons/button-impl.h index a079cd5..e0b7d50 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.h +++ b/dali-toolkit/internal/controls/buttons/button-impl.h @@ -149,13 +149,13 @@ public: std::string GetLabelText() const; /** - * @brief Produces a Property::Map of Text properties to create a Text Visual + * @brief Produces a Property::Map of Text properties to create a Text Visual, merging existing properties with supplied map * 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. - * @param[out] properties A Property::Map of text visual properties to set. + * @param[out] properties A Property::Map of text visual properties to set after merging inMap with existing maps */ - void MergeLabelProperties( const Property::Map& inMap, Property::Map& outMap ); + void MergeWithExistingLabelProperties( const Property::Map& inMap, Property::Map& outMap ); /** * Performs actions as requested using the action name. diff --git a/dali-toolkit/public-api/controls/buttons/button.h b/dali-toolkit/public-api/controls/buttons/button.h index 3ccf2d4..e447554 100644 --- a/dali-toolkit/public-api/controls/buttons/button.h +++ b/dali-toolkit/public-api/controls/buttons/button.h @@ -192,7 +192,7 @@ public: SELECTED_COLOR, /** - * @brief name "label", type Property::Map + * @brief name "label", type Property::Map or std::string * @SINCE_1_0.0 */ LABEL, -- 2.7.4