X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fpush-button-impl.cpp;h=1a5c3a435e5acc64ea2830b7509074c3d5376352;hp=bd26b232d346ecdbc7f412665d3fdc4b7b6c2744;hb=c38b9091faab34444644f626356abbdb875548d8;hpb=297b1b9a9b6ed72fe98d5afb018ff4d1c951ce7d diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index bd26b23..1a5c3a4 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -23,7 +23,7 @@ #include // INTERNAL INCLUDES -#include +#include namespace Dali { @@ -123,7 +123,7 @@ void PushButton::SetButtonImage( Actor image ) buttonImage = image; - FadeInImage( buttonImage ); + FadeInImage( buttonImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -131,7 +131,7 @@ void PushButton::SetButtonImage( Actor image ) else { buttonImage = image; - Self().Add( buttonImage ); + Self().Insert( 0, buttonImage ); } break; } @@ -148,7 +148,7 @@ void PushButton::SetButtonImage( Actor image ) // Replaces the button image. buttonImage = image; - Self().Add( buttonImage ); + Self().Insert( 0, buttonImage ); FadeOutImage( Foreground, buttonImage, opacity ); StartFadeOutAnimation(); @@ -162,7 +162,7 @@ void PushButton::SetButtonImage( Actor image ) buttonImage = image; - FadeInImage( buttonImage ); + FadeInImage( buttonImage, 0.0f, 0 ); StartFadeInAnimation(); break; } @@ -174,7 +174,8 @@ void PushButton::SetButtonImage( Actor image ) buttonImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); buttonImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); buttonImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH ); - buttonImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + buttonImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + buttonImage.SetName( "BUTTON_IMAGE" ); } void PushButton::SetSelectedImage( Actor image ) @@ -193,7 +194,7 @@ void PushButton::SetSelectedImage( Actor image ) selectedImage = image; - FadeInImage( selectedImage ); + FadeInImage( selectedImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -201,7 +202,7 @@ void PushButton::SetSelectedImage( Actor image ) else { selectedImage = image; - Self().Add( selectedImage ); + Self().Insert( 0, selectedImage ); } break; } @@ -218,7 +219,7 @@ void PushButton::SetSelectedImage( Actor image ) // Replaces the button image. selectedImage = image; - Self().Add( selectedImage ); + Self().Insert( 0, selectedImage ); FadeOutImage( Foreground, selectedImage, opacity ); StartFadeOutAnimation(); @@ -232,7 +233,7 @@ void PushButton::SetSelectedImage( Actor image ) selectedImage = image; - FadeInImage( selectedImage ); + FadeInImage( selectedImage, 0.0f, 0 ); StartFadeInAnimation(); break; } @@ -244,7 +245,7 @@ void PushButton::SetSelectedImage( Actor image ) selectedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); selectedImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); selectedImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH ); - selectedImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + selectedImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); } void PushButton::SetBackgroundImage( Actor image ) @@ -266,7 +267,7 @@ void PushButton::SetBackgroundImage( Actor image ) backgroundImage = image; - FadeInImage( backgroundImage ); + FadeInImage( backgroundImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -274,7 +275,7 @@ void PushButton::SetBackgroundImage( Actor image ) else { backgroundImage = image; - Self().Add( backgroundImage ); + Self().Insert( 0, backgroundImage ); } break; } @@ -291,7 +292,7 @@ void PushButton::SetBackgroundImage( Actor image ) // Replaces the button image. backgroundImage = image; - Self().Add( backgroundImage ); + Self().Insert( 0, backgroundImage ); FadeOutImage( Background, backgroundImage, opacity ); StartFadeOutAnimation(); @@ -305,7 +306,7 @@ void PushButton::SetBackgroundImage( Actor image ) backgroundImage = image; - FadeInImage( backgroundImage ); + FadeInImage( backgroundImage, 0.0f, 0 ); StartFadeInAnimation(); break; } @@ -317,7 +318,7 @@ void PushButton::SetBackgroundImage( Actor image ) backgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); backgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); backgroundImage.SetPosition( 0.f, 0.f, BACKGROUND_DEPTH ); - backgroundImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + backgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); } void PushButton::SetDisabledImage( Actor image ) @@ -337,7 +338,7 @@ void PushButton::SetDisabledImage( Actor image ) disabledImage = image; - FadeInImage( disabledImage ); + FadeInImage( disabledImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -357,7 +358,7 @@ void PushButton::SetDisabledImage( Actor image ) disabledImage = image; - FadeInImage( disabledImage ); + FadeInImage( disabledImage, 0.0f, 0 ); StartFadeInAnimation(); break; } @@ -388,7 +389,7 @@ void PushButton::SetDisabledImage( Actor image ) disabledImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); disabledImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); disabledImage.SetPosition( 0.f, 0.f, FOREGROUND_DEPTH ); - disabledImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + disabledImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); } void PushButton::SetDisabledBackgroundImage( Actor image ) @@ -408,7 +409,7 @@ void PushButton::SetDisabledBackgroundImage( Actor image ) disabledBackgroundImage = image; - FadeInImage( disabledBackgroundImage ); + FadeInImage( disabledBackgroundImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -428,7 +429,7 @@ void PushButton::SetDisabledBackgroundImage( Actor image ) disabledBackgroundImage = image; - FadeInImage( disabledBackgroundImage ); + FadeInImage( disabledBackgroundImage, 0.0f, 0 ); StartFadeInAnimation(); break; } @@ -459,7 +460,7 @@ void PushButton::SetDisabledBackgroundImage( Actor image ) disabledBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); disabledBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); disabledBackgroundImage.SetPosition( 0.f, 0.f, BACKGROUND_DEPTH ); - disabledBackgroundImage.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + disabledBackgroundImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); } void PushButton::OnButtonInitialize() @@ -467,6 +468,9 @@ void PushButton::OnButtonInitialize() // Push button requires the Leave event. Actor root = Self(); root.SetLeaveRequired( true ); + + // Set resize policy to natural size so that buttons will resize to background images + root.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS ); } void PushButton::OnLabelSet() @@ -496,7 +500,7 @@ void PushButton::OnSelected( bool selected ) { StopFadeOutAnimation(); FadeOutImage( Foreground, buttonImage ); - FadeInImage( selectedImage ); + FadeInImage( selectedImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -514,7 +518,7 @@ void PushButton::OnSelected( bool selected ) { StopFadeOutAnimation(); FadeOutImage( Foreground, selectedImage ); - FadeInImage( buttonImage ); + FadeInImage( buttonImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -539,7 +543,7 @@ void PushButton::OnSelected( bool selected ) StopFadeInAnimation(); FadeOutImage( Foreground, selectedImage, 1.f - opacity ); - FadeInImage( buttonImage, opacity ); + FadeInImage( buttonImage, opacity, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -565,7 +569,7 @@ void PushButton::OnSelected( bool selected ) StopFadeInAnimation(); FadeOutImage( Foreground, buttonImage, 1.f - opacity ); - FadeInImage( selectedImage, opacity ); + FadeInImage( selectedImage, opacity, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -605,8 +609,8 @@ void PushButton::OnDisabled( bool disabled ) StopFadeOutAnimation(); FadeOutImage( Background, backgroundImage ); FadeOutImage( Foreground, buttonImage ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledImage ); + FadeInImage( disabledBackgroundImage, 0.0f, 0 ); + FadeInImage( disabledImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -628,8 +632,8 @@ void PushButton::OnDisabled( bool disabled ) StopFadeOutAnimation(); FadeOutImage( Background, backgroundImage ); FadeOutImage( Foreground, selectedImage ); - FadeInImage( disabledBackgroundImage ); - FadeInImage( disabledImage ); + FadeInImage( disabledBackgroundImage, 0.0f, 0 ); + FadeInImage( disabledImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -651,8 +655,8 @@ void PushButton::OnDisabled( bool disabled ) StopFadeOutAnimation(); FadeOutImage( Background, disabledBackgroundImage ); FadeOutImage( Foreground, disabledImage ); - FadeInImage( backgroundImage ); - FadeInImage( buttonImage ); + FadeInImage( backgroundImage, 0.0f, 0 ); + FadeInImage( buttonImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -674,8 +678,8 @@ void PushButton::OnDisabled( bool disabled ) StopFadeOutAnimation(); FadeOutImage( Background, disabledBackgroundImage ); FadeOutImage( Foreground, disabledImage ); - FadeInImage( backgroundImage ); - FadeInImage( selectedImage ); + FadeInImage( backgroundImage, 0.0f, 0 ); + FadeInImage( selectedImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -705,8 +709,8 @@ void PushButton::OnDisabled( bool disabled ) FadeOutImage( Foreground, selectedImage, 1.f - opacity ); FadeOutImage( Background, backgroundImage ); - FadeInImage( disabledImage ); - FadeInImage( disabledBackgroundImage ); + FadeInImage( disabledImage, 0.0f, 0 ); + FadeInImage( disabledBackgroundImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -737,8 +741,8 @@ void PushButton::OnDisabled( bool disabled ) FadeOutImage( Foreground, buttonImage, 1.f - opacity ); FadeOutImage( Background, backgroundImage ); - FadeInImage( disabledImage ); - FadeInImage( disabledBackgroundImage ); + FadeInImage( disabledImage, 0.0f, 0); + FadeInImage( disabledBackgroundImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -768,8 +772,8 @@ void PushButton::OnDisabled( bool disabled ) FadeOutImage( Foreground, disabledImage, 1.f - opacity ); FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity ); - FadeInImage( buttonImage, opacity ); - FadeInImage( backgroundImage, opacity ); + FadeInImage( buttonImage, opacity, 0 ); + FadeInImage( backgroundImage, opacity, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -799,8 +803,8 @@ void PushButton::OnDisabled( bool disabled ) FadeOutImage( Foreground, buttonImage, 1.f - opacity ); FadeOutImage( Background, backgroundImage, 1.f - opacity ); - FadeInImage( disabledImage, opacity ); - FadeInImage( disabledBackgroundImage, opacity ); + FadeInImage( disabledImage, opacity, 0 ); + FadeInImage( disabledBackgroundImage, opacity, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -830,8 +834,8 @@ void PushButton::OnDisabled( bool disabled ) FadeOutImage( Foreground, disabledImage, 1.f - opacity ); FadeOutImage( Background, disabledBackgroundImage, 1.f - opacity ); - FadeInImage( selectedImage, opacity ); - FadeInImage( backgroundImage, opacity ); + FadeInImage( selectedImage, opacity, 0 ); + FadeInImage( backgroundImage, opacity, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -861,8 +865,8 @@ void PushButton::OnDisabled( bool disabled ) FadeOutImage( Foreground, selectedImage, 1.f - opacity ); FadeOutImage( Background, backgroundImage, 1.f - opacity ); - FadeInImage( disabledImage, opacity ); - FadeInImage( disabledBackgroundImage, opacity ); + FadeInImage( disabledImage, opacity, 0 ); + FadeInImage( disabledBackgroundImage, opacity, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -895,7 +899,7 @@ void PushButton::OnPressed() { StopFadeOutAnimation(); FadeOutImage( Foreground, buttonImage ); - FadeInImage( selectedImage ); + FadeInImage( selectedImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -928,7 +932,7 @@ void PushButton::OnPressed() StopFadeInAnimation(); FadeOutImage( Foreground, buttonImage, 1.f - opacity ); - FadeInImage( selectedImage, opacity ); + FadeInImage( selectedImage, opacity, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -960,7 +964,7 @@ void PushButton::OnReleased() { StopFadeOutAnimation(); FadeOutImage( Foreground, selectedImage ); - FadeInImage( buttonImage ); + FadeInImage( buttonImage, 0.0f, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -985,7 +989,7 @@ void PushButton::OnReleased() StopFadeInAnimation(); FadeOutImage( Foreground, selectedImage, 1.f - opacity ); - FadeInImage( buttonImage, opacity ); + FadeInImage( buttonImage, opacity, 0 ); StartFadeOutAnimation(); StartFadeInAnimation(); @@ -1040,7 +1044,7 @@ Vector3 PushButton::GetNaturalSize() ImageActor imageActor = FindImageActor( GetButtonImage() ); if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) { - Vector3 imageSize = RelayoutHelper::GetNaturalSize( imageActor ); + Vector3 imageSize = imageActor.GetNaturalSize(); if( widthIsZero ) { @@ -1056,7 +1060,7 @@ Vector3 PushButton::GetNaturalSize() ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() ); if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) { - Vector3 imageSize = RelayoutHelper::GetNaturalSize( backgroundImageActor ); + Vector3 imageSize = backgroundImageActor.GetNaturalSize(); if( widthIsZero ) { @@ -1068,6 +1072,23 @@ Vector3 PushButton::GetNaturalSize() size.height = std::max( size.height, imageSize.height ); } } + + // If label, test against it's size + Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( GetLabel() ); + if( textLabel ) + { + Vector3 textLabelSize = textLabel.GetNaturalSize(); + + if( widthIsZero ) + { + size.width = std::max( size.width, textLabelSize.width + TEXT_PADDING * 2.0f ); + } + + if( heightIsZero ) + { + size.height = std::max( size.height, textLabelSize.height + TEXT_PADDING * 2.0f ); + } + } } return size; @@ -1158,14 +1179,21 @@ void PushButton::StopFadeOutAnimation( bool remove ) } } -void PushButton::FadeInImage( Actor& image, float opacity ) +void PushButton::FadeInImage( Actor& image, float opacity, int priority ) { if( image ) { image.SetOpacity( opacity ); if( !image.GetParent() ) { - Self().Add( image ); + if( priority > -1 ) + { + Self().Insert( priority, image ); + } + else + { + Self().Add( image ); + } } AddToFadeInAnimation( image );