X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fbutton-impl.cpp;h=79ac7dbaebff0afc2f8867c608642c7b54c68683;hp=661e3b28595843c8add5b38b60ca5f18e2a3e99f;hb=7f0a28e0f0da67178997e5a647bdc471e8dcb652;hpb=72ea28bfe5df526ce47369c36edf1390641fff5a diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index 661e3b2..79ac7db 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -348,11 +349,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 +369,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() ); @@ -547,13 +544,13 @@ void Button::ButtonDown() void Button::ButtonUp() { + bool emitSignalsForPressAndReleaseAction = false; + if( DEPRESSED == mButtonPressedState ) { - bool validButtonAction = false; - if( mTogglableButton ) // Button up will change state { - validButtonAction = OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour + emitSignalsForPressAndReleaseAction = OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour } else { @@ -562,16 +559,20 @@ void Button::ButtonUp() { mAutoRepeatingTimer.Reset(); } - validButtonAction = true; + emitSignalsForPressAndReleaseAction = true; } + } + else if ( TOGGLE_DEPRESSED == mButtonPressedState ) + { + emitSignalsForPressAndReleaseAction = true; // toggle released after being pressed, a click + } - if ( validButtonAction ) - { - // The clicked and released signals should be emitted regardless of toggle mode. - Toolkit::Button handle( GetOwner() ); - mReleasedSignal.Emit( handle ); - mClickedSignal.Emit( handle ); - } + if ( emitSignalsForPressAndReleaseAction ) + { + // The clicked and released signals should be emitted regardless of toggle mode. + Toolkit::Button handle( GetOwner() ); + mReleasedSignal.Emit( handle ); + mClickedSignal.Emit( handle ); } } @@ -776,34 +777,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 ) - Size largestForegroundVisual; + Size largestProvidedVisual; 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 ); - 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 - 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 - 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", - largestForegroundVisual.width, largestForegroundVisual.height ); + largestProvidedVisual.width, largestProvidedVisual.height ); // Get natural size of label if text has been set if ( mTextStringSetFlag ) @@ -956,12 +975,12 @@ void Button::OnRelayout( const Vector2& size, RelayoutContainer& container ) if ( currentBackGroundVisual ) { - DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual bakcground size to(%f,%f)\n", size.width, size.height); + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual background size to(%f,%f)\n", size.width, size.height); Property::Map visualTransform; visualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, size ) - .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 0.0f, 0.0f, 1.0f, 1.0f) ); // Use relative size + .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) ); currentBackGroundVisual.SetTransformAndSize( visualTransform, size ); } @@ -974,7 +993,8 @@ void Button::OnRelayout( const Vector2& size, RelayoutContainer& container ) visualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, visualSize ) .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, visualPosition ) - .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 1.0f, 1.0f, 1.0f, 1.0f) ) // Use absolute size + .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) ) + .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) ) .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN ) .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, visualAnchorPoint ); @@ -994,12 +1014,18 @@ void Button::OnRelayout( const Vector2& size, RelayoutContainer& container ) labelPosition.y = labelVisualPadding.height; } + Vector2 preSize = Vector2( static_cast< int >( remainingSpaceForText.x ), static_cast< int >( remainingSpaceForText.y )); + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout text Size(%f,%f) text Position(%f,%f) \n", remainingSpaceForText.width, remainingSpaceForText.height, labelPosition.x, labelPosition.y); + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout text Size -- (%f,%f) text Position(%f,%f) \n", preSize.width, preSize.height, labelPosition.x, labelPosition.y); + + Property::Map textVisualTransform; - textVisualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, remainingSpaceForText) + textVisualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, preSize ) .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, labelPosition ) - .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 1.0f, 1.0f, 1.0f,1.0f ) ) // Use absolute size + .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) ) + .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( DevelVisual::Transform::Policy::ABSOLUTE, DevelVisual::Transform::Policy::ABSOLUTE ) ) .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN ) .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, visualAnchorPoint ); @@ -1007,6 +1033,8 @@ void Button::OnRelayout( const Vector2& size, RelayoutContainer& container ) } } + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout selected (%s) \n", IsSelected()?"yes":"no" ); + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout << \n"); } @@ -1141,17 +1169,17 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope 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 { - 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 { - 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: @@ -1195,13 +1223,33 @@ 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 { - Property::Map textVisualProperties; - GetImplementation( button ).MergeLabelProperties( *setPropertyMap, textVisualProperties ); - GetImplementation( button ).CreateVisualsForComponent( index, textVisualProperties, DepthIndex::CONTENT ); + // Get a Property::Map from the property if possible. + Property::Map* setPropertyMap = value.GetMap(); + if( setPropertyMap ) + { + TextVisual::ConvertStringKeysToIndexKeys( *setPropertyMap ); + GetImplementation( button ).MergeWithExistingLabelProperties( *setPropertyMap, outTextVisualProperties ); + } + } + + if( !outTextVisualProperties.Empty() ) + { + GetImplementation( button ).CreateVisualsForComponent( index, outTextVisualProperties, DepthIndex::CONTENT ); GetImplementation( button ).RelayoutRequest(); } break; @@ -1285,19 +1333,19 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert 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: { - 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: { - value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL ); + value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL ); break; } @@ -1449,10 +1497,7 @@ void Button::SetLabel( Actor label ) 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 ) @@ -1461,14 +1506,15 @@ void Button::SetBackgroundImage( const std::string& filename ) { 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 ) { - if( !filename.empty() ) - { - CreateVisualsForComponent( Toolkit::DevelButton::Property::SELECTED_VISUAL, filename, DepthIndex::CONTENT ); - } + SetSelectedBackgroundImage( filename ); } void Button::SetSelectedBackgroundImage( const std::string& filename ) @@ -1477,6 +1523,10 @@ void Button::SetSelectedBackgroundImage( const std::string& filename ) { 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 ) @@ -1558,7 +1608,7 @@ void Button::SetSelectedImage( Image image ) 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; } @@ -1566,7 +1616,7 @@ Actor Button::GetButtonImage() const 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; }