-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
-
#include "push-button-impl.h"
// EXTERNAL INCLUDES
-
-#include <algorithm>
+#include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/images/resource-image.h>
// INTERNAL INCLUDES
-
-#include "push-button-default-painter-impl.h"
-
-#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
namespace Dali
{
namespace Toolkit
{
-const Property::Index PushButton::PROPERTY_AUTO_REPEATING = Internal::Button::BUTTON_PROPERTY_END_INDEX + 1;
-const Property::Index PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_END_INDEX + 2;
-const Property::Index PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY = Internal::Button::BUTTON_PROPERTY_END_INDEX + 3;
-const Property::Index PushButton::PROPERTY_TOGGLABLE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 4;
-const Property::Index PushButton::PROPERTY_TOGGLE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 5;
-const Property::Index PushButton::PROPERTY_BUTTON_IMAGE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 6;
-const Property::Index PushButton::PROPERTY_PRESSED_IMAGE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 8;
-const Property::Index PushButton::PROPERTY_DIMMED_IMAGE = Internal::Button::BUTTON_PROPERTY_END_INDEX + 9;
-const Property::Index PushButton::PROPERTY_LABEL_TEXT = Internal::Button::BUTTON_PROPERTY_END_INDEX + 11;
-
namespace Internal
{
namespace
{
+const float TEXT_PADDING = 12.0f;
+const float ANIMATION_TIME( 0.2f );
+
BaseHandle Create()
{
return Toolkit::PushButton::New();
TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create );
-SignalConnectorType signalConnector1( typeRegistration, Toolkit::PushButton::SIGNAL_TOGGLED , &PushButton::DoConnectSignal );
-SignalConnectorType signalConnector2( typeRegistration, Toolkit::PushButton::SIGNAL_PRESSED , &PushButton::DoConnectSignal );
-SignalConnectorType signalConnector3( typeRegistration, Toolkit::PushButton::SIGNAL_RELEASED, &PushButton::DoConnectSignal );
-
-TypeAction action1( typeRegistration, Toolkit::PushButton::ACTION_PUSH_BUTTON_CLICK, &PushButton::DoAction );
-
-PropertyRegistration property1( typeRegistration, "auto-repeating", Toolkit::PushButton::PROPERTY_AUTO_REPEATING, Property::BOOLEAN, &PushButton::SetProperty, &PushButton::GetProperty );
-PropertyRegistration property2( typeRegistration, "initial-auto-repeating-delay", Toolkit::PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, Property::FLOAT, &PushButton::SetProperty, &PushButton::GetProperty );
-PropertyRegistration property3( typeRegistration, "next-auto-repeating-delay", Toolkit::PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY, Property::FLOAT, &PushButton::SetProperty, &PushButton::GetProperty );
-PropertyRegistration property4( typeRegistration, "togglable", Toolkit::PushButton::PROPERTY_TOGGLABLE, Property::BOOLEAN, &PushButton::SetProperty, &PushButton::GetProperty );
-PropertyRegistration property5( typeRegistration, "toggle", Toolkit::PushButton::PROPERTY_TOGGLE, Property::BOOLEAN, &PushButton::SetProperty, &PushButton::GetProperty );
-PropertyRegistration property6( typeRegistration, "button-image", Toolkit::PushButton::PROPERTY_BUTTON_IMAGE, Property::STRING, &PushButton::SetProperty, &PushButton::GetProperty );
-PropertyRegistration property7( typeRegistration, "pressed-image", Toolkit::PushButton::PROPERTY_PRESSED_IMAGE, Property::STRING, &PushButton::SetProperty, &PushButton::GetProperty );
-PropertyRegistration property8( typeRegistration, "dimmed-image", Toolkit::PushButton::PROPERTY_DIMMED_IMAGE, Property::STRING, &PushButton::SetProperty, &PushButton::GetProperty );
-PropertyRegistration property9( typeRegistration, "label-text", Toolkit::PushButton::PROPERTY_LABEL_TEXT, Property::STRING, &PushButton::SetProperty, &PushButton::GetProperty );
+const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-up.9.png";
+const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down.9.png";
+const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-disabled.9.png";
+const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "button-down-disabled.9.png";
} // unnamed namespace
namespace
{
-const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
-const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
-
-// Helper function used to cast a ButtonPainter to PushButtonDefaultPainter
-PushButtonDefaultPainterPtr GetPushButtonPainter( Dali::Toolkit::Internal::ButtonPainterPtr painter )
-{
- return static_cast<PushButtonDefaultPainter*>( painter.Get() );
-}
-
/**
- * Helper function to checks if the specified actor is an ImageActor and if it has an Image with a path.
- *
- * @param[in] actor Actor handle to check.
- * @param[out] path The image path will be applied to this parameter, if available.
- * If not available then this will be an empty string.
+ * Get size of Actor if larger than given size
+ * @param[in] root the actor to get the size of
+ * @param[out] size the greater of the given size or the size of the Actor
*/
-void GetImageActorFilename( Actor& actor, std::string& path )
+void SizeOfActorIfLarger( Actor root, Vector3& size )
{
- path = ""; // Just return an empty string if not using ImageActor with an image
-
- if ( actor )
+ if ( root )
{
- ImageActor imageActor = ImageActor::DownCast( actor );
- if ( imageActor )
- {
- Image image = imageActor.GetImage();
- if ( image )
- {
- path = image.GetFilename();
- }
- }
+ // RelayoutSize retreived for Actor to use any padding set to it.
+ size.width = std::max( root.GetRelayoutSize( Dimension::WIDTH ), size.width );
+ size.height = std::max( root.GetRelayoutSize( Dimension::HEIGHT ), size.height );
}
}
return pushButton;
}
-void PushButton::SetAutoRepeating( bool autoRepeating )
-{
- mAutoRepeating = autoRepeating;
-
- // An autorepeating button can't be a toggle button.
- if( autoRepeating )
- {
- mToggleButton = false;
- if( mToggled )
- {
- // Emit a signal is not wanted, only change the appearance.
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->Toggled( handle );
- mToggled = false;
- }
- }
-
- // Notifies the painter.
- GetPushButtonPainter( mPainter )->SetAutoRepeating( mAutoRepeating );
-}
-
-bool PushButton::IsAutoRepeating() const
-{
- return mAutoRepeating;
-}
-
-void PushButton::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
-{
- DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f );
- mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
-}
-
-float PushButton::GetInitialAutoRepeatingDelay() const
+PushButton::PushButton()
+: Button(),
+ mSize()
{
- return mInitialAutoRepeatingDelay;
+ SetAnimationTime( ANIMATION_TIME );
}
-void PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
+PushButton::~PushButton()
{
- DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
- mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
}
-float PushButton::GetNextAutoRepeatingDelay() const
+void PushButton::OnButtonInitialize()
{
- return mNextAutoRepeatingDelay;
-}
+ // Push button requires the Leave event.
+ Actor self = Self();
+ self.SetLeaveRequired( true );
-void PushButton::SetToggleButton( bool toggle )
-{
- mToggleButton = toggle;
+ // Set resize policy to natural size so that buttons will resize to background images
+ self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
- // A toggle button can't be an autorepeating button.
- if( toggle )
- {
- mAutoRepeating = false;
+ Image buttonImage = Dali::ResourceImage::New( UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
+ Image selectedImage = Dali::ResourceImage::New( SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
+ Image disabledImage = Dali::ResourceImage::New( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
+ Image disabledSelectedImage = Dali::ResourceImage::New( DISABLED_SELECTED_BUTTON_IMAGE_DIR, ResourceImage::ON_DEMAND, ResourceImage::NEVER );
- // Notifies the painter.
- GetPushButtonPainter( mPainter )->SetAutoRepeating( mAutoRepeating );
- }
+ SetButtonImage( ImageActor::New( buttonImage ) );
+ SetSelectedImage( ImageActor::New( selectedImage ) );
+ SetDisabledImage( ImageActor::New( disabledImage ) );
+ SetDisabledSelectedImage( ImageActor::New( disabledSelectedImage ) );
}
-bool PushButton::IsToggleButton() const
+void PushButton::OnLabelSet()
{
- return mToggleButton;
-}
+ Actor& label = GetLabel();
-void PushButton::SetToggled( bool toggle )
-{
- if( !mDimmed && mToggleButton && ( toggle != mToggled ) )
+ if( label )
{
- mToggled = toggle;
-
- Toolkit::PushButton handle( GetOwner() );
+ label.SetAnchorPoint( AnchorPoint::CENTER );
+ label.SetParentOrigin( ParentOrigin::CENTER );
- // Notifies the painter the button has been toggled.
- GetPushButtonPainter( mPainter )->Toggled( handle );
+ Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( label );
+ if( textLabel )
+ {
+ textLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+ textLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+ textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
+ }
- // Emit signal.
- mToggledSignalV2.Emit( handle, mToggled );
+ ConfigureSizeNegotiation();
}
}
-bool PushButton::IsToggled() const
+void PushButton::OnButtonImageSet()
{
- return mToggleButton && mToggled;
+ ConfigureSizeNegotiation();
+ RelayoutRequest();
}
-void PushButton::SetButtonImage( Image image )
+void PushButton::OnSelectedImageSet()
{
- SetButtonImage( ImageActor::New( image ) );
+ ConfigureSizeNegotiation();
+ RelayoutRequest();
}
-void PushButton::SetButtonImage( Actor image )
+void PushButton::OnBackgroundImageSet()
{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetButtonImage( handle, image );
+ ConfigureSizeNegotiation();
+ RelayoutRequest();
}
-Actor& PushButton::GetButtonImage()
+void PushButton::OnSelectedBackgroundImageSet()
{
- return mButtonImage;
+ ConfigureSizeNegotiation();
+ RelayoutRequest();
}
-Actor PushButton::GetButtonImage() const
+void PushButton::OnDisabledImageSet()
{
- return mButtonImage;
+ ConfigureSizeNegotiation();
+ RelayoutRequest();
}
-void PushButton::SetBackgroundImage( Image image )
+void PushButton::OnDisabledSelectedImageSet()
{
- SetBackgroundImage( ImageActor::New( image ) );
+ ConfigureSizeNegotiation();
+ RelayoutRequest();
}
-void PushButton::SetBackgroundImage( Actor image )
+void PushButton::OnDisabledBackgroundImageSet()
{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetBackgroundImage( handle, image );
+ ConfigureSizeNegotiation();
+ RelayoutRequest();
}
-Actor& PushButton::GetBackgroundImage()
+void PushButton::OnSizeSet( const Vector3& targetSize )
{
- return mBackgroundImage;
-}
-
-Actor PushButton::GetBackgroundImage() const
-{
- return mBackgroundImage;
-}
-
-void PushButton::SetPressedImage( Image image )
-{
- SetPressedImage( ImageActor::New( image ) );
-}
-
-void PushButton::SetPressedImage( Actor image )
-{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetPressedImage( handle, image );
-}
-
-Actor& PushButton::GetPressedImage()
-{
- return mPressedImage;
-}
-
-Actor PushButton::GetPressedImage() const
-{
- return mPressedImage;
-}
-
-void PushButton::SetDimmedBackgroundImage( Image image )
-{
- SetDimmedBackgroundImage( ImageActor::New( image ) );
-}
-
-void PushButton::SetDimmedBackgroundImage( Actor image )
-{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetDimmedBackgroundImage( handle, image );
-}
-
-Actor& PushButton::GetDimmedBackgroundImage()
-{
- return mDimmedBackgroundImage;
-}
-
-Actor PushButton::GetDimmedBackgroundImage() const
-{
- return mDimmedBackgroundImage;
-}
-
-void PushButton::SetDimmedImage( Image image )
-{
- SetDimmedImage( ImageActor::New( image ) );
-}
-
-void PushButton::SetDimmedImage( Actor image )
-{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetDimmedImage( handle, image );
-}
-
-Actor& PushButton::GetDimmedImage()
-{
- return mDimmedImage;
-}
-
-Actor PushButton::GetDimmedImage() const
-{
- return mDimmedImage;
-}
-
-void PushButton::SetLabelText( const std::string& text )
-{
- Toolkit::TextView textView ( Toolkit::TextView::New( text ) );
- textView.SetWidthExceedPolicy( Toolkit::TextView::ShrinkToFit ); // Make sure our text always fits inside the button
- SetLabelText( textView );
-}
+ if( targetSize != mSize )
+ {
+ mSize = targetSize;
-void PushButton::SetLabelText( Actor text )
-{
- Toolkit::PushButton handle( GetOwner() );
- GetPushButtonPainter( mPainter )->SetLabelText( handle, text );
-}
+ Actor& label = GetLabel();
-Actor& PushButton::GetLabel()
-{
- return mLabel;
+ if( label )
+ {
+ label.SetSize( mSize );
+ }
+ }
}
-Actor PushButton::GetLabelText() const
+void PushButton::PrepareForTranstionIn( Actor actor )
{
- return mLabel;
+ actor.SetOpacity( 0.0f );
}
-Actor& PushButton::GetFadeOutBackgroundImage()
+void PushButton::PrepareForTranstionOut( Actor actor )
{
- return mFadeOutBackgroundImage;
+ actor.SetOpacity( 1.0f );
}
-Actor& PushButton::GetFadeOutButtonImage()
+void PushButton::OnTransitionIn( Actor actor )
{
- return mFadeOutButtonImage;
+ FadeImageTo( actor, 1.f );
}
-Toolkit::PushButton::ToggledSignalV2& PushButton::ToggledSignal()
+void PushButton::OnTransitionOut( Actor actor )
{
- return mToggledSignalV2;
+ FadeImageTo( actor, 0.0f );
}
-Toolkit::PushButton::PressedSignalV2& PushButton::PressedSignal()
+void PushButton::FadeImageTo( Actor actor, float opacity )
{
- return mPressedSignalV2;
-}
+ if( actor )
+ {
+ Dali::Animation transitionAnimation = GetTransitionAnimation();
+ DALI_ASSERT_DEBUG( transitionAnimation );
-Toolkit::PushButton::ReleasedSignalV2& PushButton::ReleasedSignal()
-{
- return mReleasedSignalV2;
+ if( transitionAnimation )
+ {
+ transitionAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), opacity );
+ }
+ }
}
-bool PushButton::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
+Vector3 PushButton::GetNaturalSize()
{
- Dali::BaseHandle handle( object );
+ Vector3 size;
- bool connected( true );
- Toolkit::PushButton button = Toolkit::PushButton::DownCast(handle);
-
- if( Toolkit::PushButton::SIGNAL_TOGGLED == signalName )
+ // If label, test against it's size
+ Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );
+ if( label )
{
- button.ToggledSignal().Connect( tracker, functor );
- }
- else if( Toolkit::PushButton::SIGNAL_PRESSED == signalName )
- {
- button.PressedSignal().Connect( tracker, functor );
- }
- else if( Toolkit::PushButton::SIGNAL_RELEASED == signalName )
- {
- button.ReleasedSignal().Connect( tracker, functor );
+ size.width = std::max( size.width, label.GetRelayoutSize( Dimension::WIDTH ) );
+ size.height = std::max( size.height, label.GetRelayoutSize( Dimension::HEIGHT ) );
}
else
{
- // signalName does not match any signal
- connected = false;
+ // Check Image and Background image and use the largest size as the control's Natural size.
+ SizeOfActorIfLarger( GetButtonImage(), size );
+ SizeOfActorIfLarger( GetBackgroundImage(), size );
}
- return connected;
+ return size;
}
-void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
+void PushButton::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
{
- Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
-
- if ( pushButton )
- {
- PushButton& pushButtonImpl( GetImplementation( pushButton ) );
-
- switch ( propertyIndex )
- {
- case Toolkit::PushButton::PROPERTY_AUTO_REPEATING:
- {
- pushButtonImpl.SetAutoRepeating( value.Get< bool >() );
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY:
- {
- pushButtonImpl.SetInitialAutoRepeatingDelay( value.Get< float >() );
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY:
- {
- pushButtonImpl.SetNextAutoRepeatingDelay( value.Get< float >() );
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_TOGGLABLE:
- {
- pushButtonImpl.SetToggleButton( value.Get< bool >() );
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_TOGGLE:
- {
- pushButtonImpl.SetToggled( value.Get< bool >() );
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_BUTTON_IMAGE:
- {
- Image image = Image::New( value.Get<std::string>() );
- pushButtonImpl.SetButtonImage( image );
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_PRESSED_IMAGE:
- {
- Image image = Image::New( value.Get<std::string>() );
- pushButtonImpl.SetPressedImage( image );
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_DIMMED_IMAGE:
- {
- Image image = Image::New( value.Get<std::string>() );
- pushButtonImpl.SetDimmedImage( image );
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_LABEL_TEXT:
- {
- pushButtonImpl.SetLabelText( value.Get< std::string >() );
- break;
- }
- }
- }
+ ConfigureSizeNegotiation();
}
-Property::Value PushButton::GetProperty( BaseObject* object, Property::Index propertyIndex )
+void PushButton::ConfigureSizeNegotiation()
{
- Property::Value value;
-
- Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) );
-
- if ( pushButton )
- {
- PushButton& pushButtonImpl( GetImplementation( pushButton ) );
-
- switch ( propertyIndex )
- {
- case Toolkit::PushButton::PROPERTY_AUTO_REPEATING:
- {
- value = pushButtonImpl.mAutoRepeating;
- break;
- }
+ std::vector< Actor > images;
+ images.reserve( 7 );
- case Toolkit::PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY:
- {
- value = pushButtonImpl.mInitialAutoRepeatingDelay;
- break;
- }
+ images.push_back( GetButtonImage() );
+ images.push_back( GetSelectedImage() );
+ images.push_back( GetSelectedBackgroundImage() );
+ images.push_back( GetBackgroundImage() );
+ images.push_back( GetDisabledImage() );
+ images.push_back( GetDisabledSelectedImage() );
+ images.push_back( GetDisabledBackgroundImage() );
- case Toolkit::PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY:
- {
- value = pushButtonImpl.mNextAutoRepeatingDelay;
- break;
- }
+ Actor label = GetLabel();
- case Toolkit::PushButton::PROPERTY_TOGGLABLE:
- {
- value = pushButtonImpl.mToggleButton;
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_TOGGLE:
- {
- value = pushButtonImpl.mToggled;
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_BUTTON_IMAGE:
- {
- std::string path;
- GetImageActorFilename( pushButtonImpl.mButtonImage, path );
- value = path;
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_PRESSED_IMAGE:
- {
- std::string path;
- GetImageActorFilename( pushButtonImpl.mPressedImage, path );
- value = path;
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_DIMMED_IMAGE:
- {
- std::string path;
- GetImageActorFilename( pushButtonImpl.mDimmedImage, path );
- value = path;
- break;
- }
-
- case Toolkit::PushButton::PROPERTY_LABEL_TEXT:
- {
- value = ""; // Just return an empty string if not using a TextView
-
- if ( pushButtonImpl.mLabel )
- {
- Toolkit::TextView textView = Toolkit::TextView::DownCast( pushButtonImpl.mLabel );
- if ( textView )
- {
- value = textView.GetText();
- }
- }
- break;
- }
- }
+ for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+ {
+ ConfigureSizeNegotiationDimension( static_cast< Dimension::Type >( 1 << i ), images, label );
}
- return value;
-}
-
-void PushButton::OnButtonInitialize()
-{
- // Push button requires the Leave event.
- Actor root = Self();
- root.SetLeaveRequired( true );
-}
-
-void PushButton::OnButtonDown()
-{
- if( !mToggleButton )
+ if( label )
{
- Toolkit::PushButton handle( GetOwner() );
+ Padding padding;
- // Notifies the painter the button has been pressed.
- GetPushButtonPainter( mPainter )->Pressed( handle );
+ if( label.GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::USE_NATURAL_SIZE )
+ {
+ padding.left = TEXT_PADDING;
+ padding.right = TEXT_PADDING;
+ }
- if( mAutoRepeating )
+ if( label.GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::USE_NATURAL_SIZE )
{
- SetUpTimer( mInitialAutoRepeatingDelay );
+ padding.top = TEXT_PADDING;
+ padding.bottom = TEXT_PADDING;
}
- //Emit signal.
- mPressedSignalV2.Emit( handle );
+ label.SetPadding( padding );
}
}
-void PushButton::OnButtonUp()
+void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label )
{
- if( ButtonDown == mState )
+ ResizePolicy::Type imageResizePolicy = ResizePolicy::FILL_TO_PARENT;
+ ResizePolicy::Type labelResizePolicy = ResizePolicy::FILL_TO_PARENT;
+
+ switch( Self().GetResizePolicy( dimension ) )
{
- if( mToggleButton )
+ case ResizePolicy::FIT_TO_CHILDREN:
{
- mToggled = !mToggled;
-
- Toolkit::PushButton handle( GetOwner() );
-
- // Notifies the painter the button has been toggled.
- GetPushButtonPainter( mPainter )->Toggled( handle );
-
- //Emit signal.
- mToggledSignalV2.Emit( handle, mToggled );
+ imageResizePolicy = labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
+ break;
}
- else
+ case ResizePolicy::USE_NATURAL_SIZE:
{
- Toolkit::PushButton handle( GetOwner() );
-
- // Notifies the painter the button has been clicked.
- GetPushButtonPainter( mPainter )->Released( handle );
- GetPushButtonPainter( mPainter )->Clicked( handle );
-
- if( mAutoRepeating )
+ if( label )
{
- mAutoRepeatingTimer.Reset();
+ labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
}
-
- //Emit signal.
- mReleasedSignalV2.Emit( handle );
- mClickedSignalV2.Emit( handle );
- }
- }
-}
-
-void PushButton::OnTouchPointLeave()
-{
- if( ButtonDown == mState )
- {
- if( !mToggleButton )
- {
- Toolkit::PushButton handle( GetOwner() );
-
- // Notifies the painter the button has been released.
- GetPushButtonPainter( mPainter )->Released( handle );
-
- if( mAutoRepeating )
+ else
{
- mAutoRepeatingTimer.Reset();
+ imageResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
}
-
- //Emit signal.
- mReleasedSignalV2.Emit( handle );
+ break;
+ }
+ default:
+ {
+ break;
}
}
-}
-
-void PushButton::OnTouchPointInterrupted()
-{
- OnTouchPointLeave();
-}
-
-void PushButton::OnAnimationTimeSet( float animationTime )
-{
- GetPushButtonPainter( mPainter )->SetAnimationTime( animationTime );
-}
-
-float PushButton::OnAnimationTimeRequested() const
-{
- return GetPushButtonPainter( mPainter )->GetAnimationTime();
-}
-
-PushButton::PushButton()
-: Button(),
- mAutoRepeating( false ),
- mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ),
- mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
- mToggleButton( false ),
- mAutoRepeatingTimer(),
- mToggled( false ),
- mClickActionPerforming(false)
-{
- // Creates specific painter.
- mPainter = PushButtonDefaultPainterPtr( new PushButtonDefaultPainter() );
-}
-
-PushButton::~PushButton()
-{
- if( mAutoRepeatingTimer )
- {
- mAutoRepeatingTimer.Reset();
- }
-
- mPainter = NULL;
-}
-
-void PushButton::SetUpTimer( float delay )
-{
- mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
- mAutoRepeatingTimer.TickSignal().Connect( this, &PushButton::AutoRepeatingSlot );
- mAutoRepeatingTimer.Start();
-}
-bool PushButton::AutoRepeatingSlot()
-{
- bool consumed = false;
- if( !mDimmed )
+ if( label )
{
- // Restart the autorepeat timer.
- SetUpTimer( mNextAutoRepeatingDelay );
-
- Toolkit::PushButton handle( GetOwner() );
-
- // Notifies the painter the button has been pressed.
- GetPushButtonPainter( mPainter )->Pressed( handle );
-
- //Emit signal.
- consumed = mReleasedSignalV2.Emit( handle );
- consumed |= mClickedSignalV2.Emit( handle );
- consumed |= mPressedSignalV2.Emit( handle );
- }
-
- return consumed;
-}
-
-void PushButton::OnActivated()
-{
- // When the button is activated, it performs the click action
- std::vector<Property::Value> attributes;
- DoClickAction(attributes);
-}
-
-void PushButton::DoClickAction(const PropertyValueContainer& attributes)
-{
- // Prevents the button signals from doing a recursive loop by sending an action
- // and re-emitting the signals.
- if(!mClickActionPerforming)
- {
- mClickActionPerforming = true;
- OnButtonDown();
- mState = ButtonDown;
- OnButtonUp();
- mClickActionPerforming = false;
+ label.SetResizePolicy( labelResizePolicy, dimension );
}
-}
-bool PushButton::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
-{
- bool ret = false;
-
- Dali::BaseHandle handle(object);
-
- Toolkit::PushButton button = Toolkit::PushButton::DownCast(handle);
-
- DALI_ASSERT_ALWAYS(button);
-
- if(Toolkit::PushButton::ACTION_PUSH_BUTTON_CLICK == actionName)
+ for( std::vector< Actor >::const_iterator it = images.begin(), itEnd = images.end(); it != itEnd; ++it )
{
- GetImplementation(button).DoClickAction(attributes);
- ret = true;
+ Actor actor = *it;
+ if( actor )
+ {
+ actor.SetResizePolicy( imageResizePolicy, dimension );
+ }
}
-
- return ret;
}
} // namespace Internal