From e5dbcae1f8ee31b14d675793ab86161eeeefb029 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Wed, 25 May 2016 14:26:50 +0100 Subject: [PATCH] Buttons to use Visuals Button base case takes over more of the functionality of derived class. Visuals are now used istead of images. Dali error added to Builder to be shown if string from json not found Button Relayout optimised and aligns in 4 directions Text can be aligned against the foreground using BEGIN, END, TOP and BOTTOM Positioning of Text and Foreground visual optimised although text not centers if foreground visual present Button uses visuals instead of placement actors Tests for Button Visuals and Visual removal with empty map Allow StageDisconnection to handle visual removal debug header removed from button-impl.h and now in cpp files. Fixed map bug in which map was checked for being empty before value was stored in it Increasing coverage and Removing Internal Button Tests Internal Tests used a TetButton when it should just use a PushButton. The Internal tests did not offer any advantage over regular tests so removed. Tests added to increase coverage and replace Internal tests Added Wait function to test application Change-Id: Idb9bccc9ca12a372c3e466fbdb4d8d3d41fb5acf --- .../src/dali-toolkit-internal/CMakeLists.txt | 1 - .../dali-toolkit-internal/utc-Dali-PushButton.cpp | 718 --------- .../dali-toolkit-test-utils/test-application.cpp | 12 + .../dali-toolkit-test-utils/test-application.h | 3 + .../src/dali-toolkit/utc-Dali-Button.cpp | 240 ++- .../src/dali-toolkit/utc-Dali-PushButton.cpp | 417 ++--- dali-toolkit/internal/builder/builder-impl.cpp | 2 +- .../internal/controls/buttons/button-impl.cpp | 1591 +++++++++----------- .../internal/controls/buttons/button-impl.h | 485 +++--- .../controls/buttons/check-box-button-impl.cpp | 165 +- .../controls/buttons/check-box-button-impl.h | 27 +- .../internal/controls/buttons/push-button-impl.cpp | 431 +----- .../internal/controls/buttons/push-button-impl.h | 129 +- .../controls/buttons/radio-button-impl.cpp | 131 +- .../internal/controls/buttons/radio-button-impl.h | 12 +- .../public-api/controls/buttons/button.cpp | 29 +- dali-toolkit/public-api/controls/buttons/button.h | 238 ++- .../public-api/controls/buttons/push-button.cpp | 19 +- .../public-api/controls/buttons/push-button.h | 8 +- .../1920x1080/dali-toolkit-default-theme.json | 88 ++ .../styles/480x800/dali-toolkit-default-theme.json | 90 +- .../720x1280/dali-toolkit-default-theme.json | 82 + ...-diabled.png => checkbox-selected-disabled.png} | Bin 23 files changed, 2123 insertions(+), 2795 deletions(-) delete mode 100644 automated-tests/src/dali-toolkit-internal/utc-Dali-PushButton.cpp rename dali-toolkit/styles/images-common/{checkbox-selected-diabled.png => checkbox-selected-disabled.png} (100%) diff --git a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt index a4a8ae7..20d76c0 100644 --- a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt @@ -7,7 +7,6 @@ SET(CAPI_LIB "dali-toolkit-internal") # List of test case sources (Only these get parsed for test cases) SET(TC_SOURCES - utc-Dali-PushButton.cpp utc-Dali-Text-CharacterSetConversion.cpp utc-Dali-Text-Cursor.cpp utc-Dali-Text-Segmentation.cpp diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-PushButton.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-PushButton.cpp deleted file mode 100644 index edaf7fd..0000000 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-PushButton.cpp +++ /dev/null @@ -1,718 +0,0 @@ -/* - * 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. - * - */ - -#include - -#include -#include -#include -#include -#include - - -using namespace Dali; -using namespace Toolkit; - -namespace -{ - -static bool gPushButtonSelectedState = false; -bool PushButtonSelected( Button button, bool selected ) -{ - gPushButtonSelectedState = selected && ( selected == static_cast( button ).IsSelected() ); - return true; -} - - -Dali::Integration::Point GetPointDownInside() -{ - Dali::Integration::Point point; - point.SetState( PointState::DOWN ); - point.SetScreenPosition( Vector2( 240, 400 ) ); - return point; -} - -Dali::Integration::Point GetPointUpInside() -{ - Dali::Integration::Point point; - point.SetState( PointState::UP ); - point.SetScreenPosition( Vector2( 240, 400 ) ); - return point; -} - -Dali::Integration::Point GetPointMotionOut() -{ - Dali::Integration::Point point; - point.SetState( PointState::MOTION ); - point.SetScreenPosition( Vector2( 10, 10 ) ); - return point; -} - -Dali::Integration::Point GetPointUpOutside() -{ - Dali::Integration::Point point; - point.SetState( PointState::UP ); - point.SetScreenPosition( Vector2( 10, 10 ) ); - return point; -} - -} // namespace - - -////////////////////////////////////////////////////////// - -namespace -{ -static bool gOnTouchPointInterrupted = false; -} //namespace - -namespace Dali -{ - -namespace Toolkit -{ - -namespace Internal -{ -class TETButton; -} - -/** - * Creates a PushButton to test if interrupt events are handled correctly. - */ -class TETButton : public PushButton -{ -public: - // PushButton Pressed - typedef Signal< bool ( PushButton ) > ButtonSignalType; - - ButtonSignalType& PressedSignal(); - - /** - * Default constructor. - */ - TETButton(); - - /** - * Copy constructor. - */ - TETButton( const PushButton& button ); - - /** - * Assignment operator. - */ - TETButton& operator=( const TETButton& button ); - - /** - * Creates and initializes a new button. - */ - static TETButton New(); - - /** - * Down cast to TETButton. - */ - static TETButton DownCast( BaseHandle handle ); - - /** - * Creates a handle using the Toolkit::Internal implementation. - * @param[in] implementation The Control implementation. - */ - TETButton( Internal::TETButton& implementation ); - - /** - * Allows the creation of this Control from an Internal::CustomActor pointer. - * @param[in] internal A pointer to the internal CustomActor. - */ - TETButton( Dali::Internal::CustomActor* internal ); -}; - -namespace Internal -{ - -/** - * Internal implementation - */ -class TETButton : public PushButton -{ -public: - /** - * Construct a new Button. - */ - TETButton(); - - /** - * A reference counted object may only be deleted by calling Unreference() - */ - virtual ~TETButton(); - - /** - * Creates an internal button. - */ - static Toolkit::TETButton New(); - - /** - * @return the pressed signal. - */ - Toolkit::TETButton::ButtonSignalType& PressedSignal(); - - /** - * Callback called when an interrupt events is received. - */ - void OnTouchPointInterrupted(); - - /** - * Callback received when a down event is received. - */ - void OnButtonDown(); - - Toolkit::TETButton::ButtonSignalType mPressedSignal; ///< Signal emitted when the button is pressed. -}; - -} // namespace Internal - -TETButton::TETButton() -{ -} - -TETButton::TETButton( const PushButton& button ) -: PushButton( button ) -{ -} - -TETButton& TETButton::operator=( const TETButton& button ) -{ - if( &button != this ) - { - PushButton::operator=( button ); - } - return *this; -} - -TETButton TETButton::New() -{ - return Internal::TETButton::New(); -} - -TETButton TETButton::DownCast( BaseHandle handle ) -{ - return Control::DownCast(handle); -} - -TETButton::ButtonSignalType& TETButton::PressedSignal() -{ - TETButton button( *this ); - DALI_ASSERT_ALWAYS( button ); - - Dali::RefObject& handle = button.GetImplementation(); - - return static_cast( handle ).PressedSignal(); -} - -TETButton::TETButton( Internal::TETButton& implementation ) -: PushButton( implementation ) -{} - -TETButton::TETButton( Dali::Internal::CustomActor* internal ) -: PushButton( internal ) -{ - VerifyCustomActorPointer(internal); -} - -namespace Internal -{ - -TETButton::TETButton() -: PushButton(), - mPressedSignal() -{ -} - -TETButton::~TETButton() -{ -} - -Toolkit::TETButton TETButton::New() -{ - // Create the implementation, temporarily owned on stack - IntrusivePtr< TETButton > internalTETButton = new TETButton(); - - // Pass ownership to CustomActor - Dali::Toolkit::TETButton tetButton( *internalTETButton ); - - // Second-phase init of the implementation - // This can only be done after the CustomActor connection has been made... - internalTETButton->Initialize(); - - return tetButton; -} - -Toolkit::TETButton::ButtonSignalType& TETButton::PressedSignal() -{ - return mPressedSignal; -} - -void TETButton::OnButtonDown() -{ - Toolkit::TETButton handle( GetOwner() ); - - //Emit signal. - mPressedSignal.Emit( handle ); -} - -void TETButton::OnTouchPointInterrupted() -{ - gOnTouchPointInterrupted = true; -} - -} // namespace Internal - -} // namespace Toolkit - -} // namespace Dali - -namespace -{ - -class TETButtonPressed : public Dali::ConnectionTracker -{ -public: - enum Test - { - SENSITIVENESS, - VISIBILITY - }; - - TETButtonPressed( Actor actor, Test test ) - : mActor( actor ), - mTest( test ) - { - } - - bool Callback( PushButton button ) - { - switch( mTest ) - { - case SENSITIVENESS: - { - mActor.SetSensitive( false ); - break; - } - case VISIBILITY: - { - std::cout <<"VISIBILITY false" << std::endl; - mActor.SetVisible( false ); - break; - } - default: - { - break; - } - } - return true; - } - - Actor mActor; - Test mTest; -}; - -static bool TestCallback(Actor actor, const TouchData& event) -{ - return true; -} - -} // namespace - -////////////////////////////////////////////////////////// - -int UtcDaliPushButtonDownCast(void) -{ - ToolkitTestApplication application; - tet_infoline(" UtcDaliPushButtonDownCast"); - - TETButton tetButton= Toolkit::TETButton::New(); - - BaseHandle object(tetButton); - - TETButton tetButton2 = TETButton::DownCast( object ); - DALI_TEST_CHECK(tetButton2); - - TETButton tetButton3 = DownCast< TETButton >(object); - DALI_TEST_CHECK(tetButton3); - END_TEST; -} - -int UtcDaliPushButtonInterruptEventWhenInsensitive(void) -{ - ToolkitTestApplication application; - tet_infoline(" UtcDaliPushButtonInterruptEventWhenInsensitive"); - - // * Creates an actor which contains a button. - // * The size of the actor is bigger than the button. - // * The button's boundary is contained in the actor's one. - Actor actor = Actor::New(); - TETButton tetButton= Toolkit::TETButton::New(); - - actor.SetName( "Actor" ); - tetButton.SetName( "TETButton" ); - - actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - actor.SetParentOrigin( ParentOrigin::TOP_LEFT ); - actor.SetPosition( 0, 0 ); - actor.SetSize( 400, 800 ); - - tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); - tetButton.SetPosition( 240, 400 ); - tetButton.SetSize( 100, 100 ); - - actor.Add( tetButton ); - Stage::GetCurrent().Add( actor ); - - // * Actor's touch event is connected to a callback function - // and this callback function consumes the event. - actor.TouchSignal().Connect( &TestCallback ); - - // * Button's pressed signal is connected to a callback function - // which also consumes the event. - // * Changes the sensitiveness of the button to false. - TETButtonPressed tetButtonPressed( actor, TETButtonPressed::SENSITIVENESS ); - tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback ); - - // Initializes TET state. - gOnTouchPointInterrupted = false; - tetButton.SetSensitive( true ); - - Dali::Integration::TouchEvent event; - - // TET starts. - - // Test a down point inside the button which is also consumed by the actor, and an up point - // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an - // interrupt event. - - application.SendNotification(); - application.Render(); - - // A down event is sent inside the button's boundary. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointDownInside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - // An up event is sent outside the button's boundary but inside the actor's one. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointUpOutside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - DALI_TEST_CHECK( gOnTouchPointInterrupted ); - - // Test a down point inside the button which is also consumed by the actor, and a motion point - // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an - // interrupt event. - - // Initializes TET state. - gOnTouchPointInterrupted = false; - actor.SetSensitive( true ); - tetButton.SetSensitive( true ); - - application.SendNotification(); - application.Render(); - - // A down event is sent inside the button's boundary. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointDownInside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - // A motion event is sent outside the button's boundary but inside the actor's one. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointMotionOut() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - DALI_TEST_CHECK( gOnTouchPointInterrupted ); - - // Test a down point inside the button which is also consumed by the actor, and an up point - // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false. - - // Initializes TET state. - gOnTouchPointInterrupted = false; - actor.SetSensitive( true ); - tetButton.SetSensitive( true ); - - // A down event is sent inside the button's boundary. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointDownInside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - actor.SetSensitive( true ); - // An up event is sent inside the button's boundary. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointUpInside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - DALI_TEST_CHECK( !gOnTouchPointInterrupted ); - END_TEST; -} - -int UtcDaliPushButtonInterruptEventWhenNonVisible(void) -{ - ToolkitTestApplication application; - tet_infoline(" UtcDaliPushButtonInterruptEventWhenNonVisible"); - - // Does same test as above but changing the visibility instead the sensitiveness. - - // * Creates an actor which contains a button. - // * The size of the actor is bigger than the button. - // * The button's boundary is contained in the actor's one. - Actor actor = Actor::New(); - TETButton tetButton = Toolkit::TETButton::New(); - - actor.SetName( "Actor" ); - tetButton.SetName( "TETButton" ); - - actor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - actor.SetParentOrigin( ParentOrigin::TOP_LEFT ); - actor.SetPosition( 0, 0 ); - actor.SetSize( 400, 800 ); - - tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); - tetButton.SetPosition( 240, 400 ); - tetButton.SetSize( 100, 100 ); - - actor.Add( tetButton ); - Stage::GetCurrent().Add( actor ); - - // * Actor's touch event is connected to a callback function - // and this callback function consumes the event. - actor.TouchSignal().Connect( &TestCallback ); - - // * Button's pressed signal is connected to a callback function - // which also consumes the event. - // * Changes the visibility of the button to false. - TETButtonPressed tetButtonPressed( tetButton, TETButtonPressed::VISIBILITY ); - tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback ); - - // Initializes TET state. - gOnTouchPointInterrupted = false; - tetButton.SetVisible( true ); - - Dali::Integration::TouchEvent event; - - // TET starts. - - // Test a down point inside the button which is also consumed by the actor, and an up point - // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an - // interrupt event. - - application.SendNotification(); - application.Render(); - - // A down event is sent inside the button's boundary. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointDownInside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - // More renders are needed in order to allow the node of the actor to become invisible. - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - - // An up event is sent outside the button's boundary but inside the actor's one. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointUpOutside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - DALI_TEST_CHECK( gOnTouchPointInterrupted ); - - // Test a down point inside the button which is also consumed by the actor, and a motion point - // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an - // interrupt event. - - // Initializes TET state. - gOnTouchPointInterrupted = false; - tetButton.SetVisible( true ); - - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - - // A down event is sent inside the button's boundary. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointDownInside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - // More renders are needed in order to allow the node of the actor to become invisible. - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - - // A motion event is sent outside the button's boundary but inside the actor's one. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointMotionOut() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - DALI_TEST_CHECK( gOnTouchPointInterrupted ); - - // Test a down point inside the button which is also consumed by the actor, and an up point - // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false. - - // Initializes TET state. - gOnTouchPointInterrupted = false; - tetButton.SetVisible( true ); - - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - - // A down event is sent inside the button's boundary. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointDownInside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - tetButton.SetVisible( true ); - - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - application.SendNotification(); - application.Render(); - - // An up event is sent inside the button's boundary. - - event = Dali::Integration::TouchEvent(); - event.AddPoint( GetPointUpInside() ); - - // flush the queue and render once - application.SendNotification(); - application.Render(); - application.ProcessEvent( event ); - - DALI_TEST_CHECK( !gOnTouchPointInterrupted ); - END_TEST; -} - -int UtcDaliPushButtonProperties(void) -{ - ToolkitTestApplication application; - - PushButton button = PushButton::New(); - Stage::GetCurrent().Add( button ); - - // Button::PROPERTY_AUTO_REPEATING - button.SetAutoRepeating( false ); - DALI_TEST_CHECK( ! button.GetProperty< bool >( Button::Property::AUTO_REPEATING ) ); - button.SetProperty( Button::Property::AUTO_REPEATING, true ); - DALI_TEST_CHECK( button.IsAutoRepeating() ) ; - DALI_TEST_CHECK( button.GetProperty< bool >( Button::Property::AUTO_REPEATING ) ); - - // Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY - button.SetInitialAutoRepeatingDelay( 10.0f ); - DALI_TEST_EQUALS( 10.0f, button.GetProperty< float >( Button::Property::INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION ); - button.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, 25.0f ); - DALI_TEST_EQUALS( 25.0f, button.GetInitialAutoRepeatingDelay(), TEST_LOCATION ); - DALI_TEST_EQUALS( 25.0f, button.GetProperty< float >( Button::Property::INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION ); - - // Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY - button.SetNextAutoRepeatingDelay( 3.0f ); - DALI_TEST_EQUALS( 3.0f, button.GetProperty< float >( Button::Property::NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION ); - button.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, 4.0f ); - DALI_TEST_EQUALS( 4.0f, button.GetNextAutoRepeatingDelay(), TEST_LOCATION ); - DALI_TEST_EQUALS( 4.0f, button.GetProperty< float >( Button::Property::NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION ); - - // Button::PROPERTY_TOGGLABLE - button.SetTogglableButton( false ); - DALI_TEST_CHECK( ! button.GetProperty< bool >( Button::Property::TOGGLABLE ) ); - button.SetProperty( Button::Property::TOGGLABLE, true ); - DALI_TEST_CHECK( button.IsTogglableButton() ) ; - DALI_TEST_CHECK( button.GetProperty< bool >( Button::Property::TOGGLABLE ) ); - - // Button::PROPERTY_SELECTED - button.SetSelected( false ); - DALI_TEST_CHECK( ! button.GetProperty< bool >( Button::Property::SELECTED ) ); - button.SetProperty( Button::Property::SELECTED, true ); - DALI_TEST_CHECK( button.IsSelected() ) ; - DALI_TEST_CHECK( button.GetProperty< bool >( Button::Property::SELECTED ) ); - - END_TEST; -} diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.cpp index e8d9be4..d89d4d2 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.cpp @@ -221,5 +221,17 @@ void TestApplication::ResetContext() mCore->ContextCreated(); } +unsigned int TestApplication::Wait( unsigned int durationToWait ) +{ + int time = 0; + + for(unsigned int i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++) + { + SendNotification(); + Render(RENDER_FRAME_INTERVAL); + time += RENDER_FRAME_INTERVAL; + } + return time; +} } // Namespace dali diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.h index 49a7f51..c5ecc4f 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.h @@ -48,6 +48,8 @@ public: static const unsigned int DEFAULT_RENDER_INTERVAL = 1; + static const unsigned int RENDER_FRAME_INTERVAL = 16; + TestApplication( size_t surfaceWidth = DEFAULT_SURFACE_WIDTH, size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT, float horizontalDpi = DEFAULT_HORIZONTAL_DPI, @@ -80,6 +82,7 @@ public: bool RenderOnly( ); void ResetContext(); bool GetRenderNeedsUpdate(); + unsigned int Wait( unsigned int durationToWait ); private: void DoUpdate( unsigned int intervalMilliseconds, const char* location=NULL ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp index ead898d..60df0f4 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp @@ -21,6 +21,7 @@ // Need to override adaptor classes for toolkit test harness, so include // test harness headers before dali headers. #include +#include "dali-toolkit-test-utils/toolkit-timer.h" #include #include @@ -42,8 +43,12 @@ void utc_dali_toolkit_button_cleanup(void) namespace { +static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; + static bool gIsCalledButtonCallback = false; +const int RENDER_FRAME_INTERVAL = 16; + static bool ButtonCallback( Button button ) { gIsCalledButtonCallback = true; @@ -112,8 +117,8 @@ Dali::Integration::Point GetPointUpOutside() return point; } - static float ANIMATION_TIME( 0.5f ); + } // namespace int UtcDaliButtonConstructorP(void) @@ -205,6 +210,70 @@ int UtcDaliButtonSetDisabledP(void) END_TEST; } +int UtcDaliButtonSetDisabledWithDifferentStates01P(void) +{ + ToolkitTestApplication application; + + tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates01P\n"); + + Button button = PushButton::New(); + + bool SELECTED = true; + + button.SetProperty( Button::Property::TOGGLABLE, true); + button.SetProperty( Button::Property::SELECTED, SELECTED ); + + button.SetProperty( Button::Property::DISABLED, true); + + tet_infoline("Set button to SELECTED = false whilst disabled, should not change to false\n"); + button.SetProperty( Button::Property::SELECTED, !SELECTED ); + + bool isSelected = button.GetProperty( Button::Property::SELECTED ) ; + + DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliButtonSetDisabledWithDifferentStates02P(void) +{ + ToolkitTestApplication application; + + tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates02\n"); + + Button button = PushButton::New(); + + bool SELECTED = true; + + button.SetProperty( Button::Property::TOGGLABLE, true ); + button.SetProperty( Button::Property::SELECTED, SELECTED ); + button.SetProperty( Button::Property::DISABLED, true ); + + bool isSelected = button.GetProperty( Button::Property::SELECTED ); + DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION ); + tet_infoline("Set button to DISABLED = false whilst disabled and then set to unselected\n"); + + button.SetProperty( Button::Property::DISABLED, false ); + button.SetProperty( Button::Property::SELECTED, !SELECTED ); + + isSelected = button.GetProperty( Button::Property::SELECTED ); + DALI_TEST_EQUALS( isSelected, !SELECTED , TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliButtonPropertyGetLabelAlignment(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n"); + + Button button = PushButton::New(); + button.SetProperty( Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT, "END" ); + DALI_TEST_EQUALS( button.GetProperty( Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT ), "END", TEST_LOCATION ); + + END_TEST; +} + int UtcDaliButtonIsDisabledP(void) { ToolkitTestApplication application; @@ -261,6 +330,66 @@ int UtcDaliButtonIsAutoRepeatingP(void) END_TEST; } +int UtcDaliButtonAutoRepeatingP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonPressedSignalP Setup Autorepeating and check multiple clicked signals received\n"); + + const float AUTO_REPEATING_DELAY = 0.15f; + + Button button = PushButton::New(); + button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + button.SetParentOrigin( ParentOrigin::TOP_LEFT ); + button.SetPosition( 240, 400 ); + button.SetSize( 100, 100 ); + Stage::GetCurrent().Add( button ); + + application.SendNotification(); + application.Render(); + + button.SetProperty( Toolkit::Button::Property::AUTO_REPEATING, true ); + button.SetProperty( Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY, AUTO_REPEATING_DELAY ); + // connect to its touch signal + ConnectionTracker* testTracker = new ConnectionTracker(); + button.PressedSignal().Connect( &ButtonCallback ); + button.ClickedSignal().Connect( &ButtonCallback ); + bool clickedSignal = false; + bool pressedSignal = false; + button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) ); + button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) ); + + Dali::Integration::TouchEvent event; + + // Touch point down and up inside the button. + + gIsCalledButtonCallback = false; + event = Dali::Integration::TouchEvent(); + event.AddPoint( GetPointDownInside() ); + application.ProcessEvent( event ); + + DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION ); + DALI_TEST_EQUALS( pressedSignal, true, TEST_LOCATION ); + tet_infoline("Consume first clicked signal then wait\n"); + + gIsCalledButtonCallback = false; + Dali::Timer timer = Timer::New( AUTO_REPEATING_DELAY ); + timer.MockEmitSignal(); + application.Wait( AUTO_REPEATING_DELAY*2 ); + DALI_TEST_EQUALS( clickedSignal, true, TEST_LOCATION ); + tet_infoline("Check gIsCalledButtonCallback was called again after last consumption of it.\n"); + + DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION ); + + gIsCalledButtonCallback = false; + event = Dali::Integration::TouchEvent(); + event.AddPoint( GetPointUpInside() ); + application.ProcessEvent( event ); + + DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliButtonSetInitialAutoRepeatingDelayP(void) { ToolkitTestApplication application; @@ -287,7 +416,7 @@ int UtcDaliButtonSetNextAutoRepeatingDelayP(void) DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.5f, TEST_LOCATION ); - button.SetNextAutoRepeatingDelay( 0.2f ); + button.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, 0.2f ); DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.2f, TEST_LOCATION ); END_TEST; @@ -351,15 +480,30 @@ int UtcDaliButtonSetLabelStringP(void) END_TEST; } -int UtcDaliButtonSetLabelActorP(void) +int UtcDaliButtonSetLabelPropertyP(void) { ToolkitTestApplication application; + const std::string TEST_LABEL1 = "test label one"; + const std::string TEST_LABEL2 = "test label two"; + Button button = PushButton::New(); - button.SetLabelText( "Button Label" ); + 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::TextLabel::Property::TEXT, TEST_LABEL2 ); + propertyMap.Insert( Toolkit::TextLabel::Property::TEXT_COLOR, Color::BLUE); + button.SetProperty( Button::Property::LABEL, propertyMap ); + + labelText = button.GetProperty( Button::Property::LABEL_TEXT ); + + DALI_TEST_EQUALS( labelText, TEST_LABEL2, TEST_LOCATION ); - DALI_TEST_EQUALS( button.GetLabelText(), "Button Label", TEST_LOCATION ); END_TEST; } @@ -374,16 +518,12 @@ int UtcDaliButtonSetUnselectedImageP(void) application.SendNotification(); application.Render(); - pushButton.SetSize( Vector2( 20.0f, 20.0f ) ); pushButton.SetUnselectedImage( "Image.jpg" ); application.SendNotification(); application.Render(); - Vector3 size = pushButton.GetCurrentSize(); - - DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION ); - DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION ); + DALI_TEST_CHECK( pushButton ); END_TEST; } @@ -399,16 +539,12 @@ int UtcDaliButtonSetSelectedImageP(void) application.SendNotification(); application.Render(); - pushButton.SetSize( Vector2( 20.0f, 20.0f ) ); pushButton.SetSelectedImage( "Image.jpg" ); application.SendNotification(); application.Render(); - Vector3 size = pushButton.GetCurrentSize(); - - DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION ); - DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION ); + DALI_TEST_CHECK( pushButton ); END_TEST; } @@ -803,7 +939,7 @@ int UtcDaliButtonSetDisabledSelectedImageN(void) END_TEST; } -int UtcDaliButtonSetLabelP(void) +int UtcDaliButtonSetLabeActorlP(void) { ToolkitTestApplication application; @@ -851,8 +987,11 @@ int UtcDaliButtonSetButtonImageP(void) try { - button.SetButtonImage( CreateBufferImage( 10, 10, Color::WHITE ) ); - DALI_TEST_CHECK( ImageView::DownCast( button.GetButtonImage() ) ); + ResourceImage image1 = ResourceImage::New( "TestImage.jpg"); + button.SetButtonImage( image1 ); + + Property::Value value = button.GetProperty(Button::Property::UNSELECTED_STATE_IMAGE ); + DALI_TEST_CHECK( value.Get() == "TestImage.jpg" ); } catch(...) { @@ -870,7 +1009,9 @@ int UtcDaliButtonSetButtonImageN(void) try { - button.SetButtonImage( CreateBufferImage( 10, 10, Color::WHITE ) ); + ResourceImage image1 = ResourceImage::New( "TestImage.jpg"); + button.SetButtonImage( image1 ); + DALI_TEST_CHECK( false ); } catch(...) @@ -887,11 +1028,13 @@ int UtcDaliButtonSetSelectedImageWithImageP(void) PushButton button = PushButton::New(); Stage::GetCurrent().Add( button ); + ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE ); try { - button.SetSelectedImage( CreateBufferImage( 10, 10, Color::WHITE ) ); - DALI_TEST_CHECK( ImageView::DownCast( button.GetSelectedImage() ) ); + button.SetSelectedImage( image1 ); + Property::Value value = button.GetProperty(Button::Property::SELECTED_STATE_IMAGE ); + DALI_TEST_CHECK( value.Get() == TEST_IMAGE_ONE ); } catch(...) { @@ -1007,3 +1150,58 @@ int UtcDaliButtonResetSelectedColorP(void) END_TEST; } + +int UtcDaliButtonSetImagesWithDeprecatedProperties(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonSetImagesWithDeprecatedProperties"); + + PushButton pushButton = PushButton::New(); + Stage::GetCurrent().Add( pushButton ); + + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); + + DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION ); + + pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, propertyMap ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION ); + + tet_infoline(" Set state to selected and provide SELECTED visual"); + pushButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, propertyMap ); + pushButton.SetProperty( Toolkit::Button::Property::SELECTED, true ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION ); + + tet_infoline(" Set state to selected, disabled and provide DISABLED_STATE_IMAGE visual"); + pushButton.SetProperty( Toolkit::Button::Property::SELECTED, false ); + pushButton.SetProperty( Toolkit::Button::Property::DISABLED, true ); + pushButton.SetProperty( Toolkit::Button::Property::DISABLED_STATE_IMAGE, propertyMap ); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION ); + +END_TEST; +} + +int UtcDaliButtonSetGetDepreciatedPropertiesWithURL(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonSetGetDepreciatedPropertiesWithURL"); + + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); + + tet_infoline(" Set state to selected, disabled and provide DISABLED_STATE_IMAGE visual"); + button.SetProperty( Toolkit::Button::Property::DISABLED, true ); + button.SetProperty( Toolkit::Button::Property::DISABLED_STATE_IMAGE, TEST_IMAGE_ONE ); + + Property::Value value = button.GetProperty(Button::Property::DISABLED_STATE_IMAGE ); + DALI_TEST_EQUALS( value.Get(), TEST_IMAGE_ONE, TEST_LOCATION ); + +END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp b/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp index a191f43..235d8ab 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp @@ -41,6 +41,7 @@ void utc_dali_toolkit_pushbutton_cleanup(void) namespace { +static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; static bool gPushButtonSelectedState = false; bool PushButtonSelected( Button button ) @@ -211,6 +212,29 @@ int UtcDaliPushButtonSetGetAutoRepeating(void) END_TEST; } +int UtcDaliPushButtonSetAutoRepeating(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliPushButtonSetAutoRepeating\n"); + tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n"); + PushButton pushButton = PushButton::New(); + + const bool INITIAL_TOGGLE_VALUE = true; + const bool INITIAL_SELECTED_VALUE = true; + + pushButton.SetProperty( Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE); + pushButton.SetProperty( Button::Property::SELECTED, INITIAL_SELECTED_VALUE ); + + DALI_TEST_EQUALS( pushButton.GetProperty( Button::Property::TOGGLABLE ), INITIAL_TOGGLE_VALUE , TEST_LOCATION ); + DALI_TEST_EQUALS( pushButton.GetProperty( Button::Property::SELECTED ), INITIAL_SELECTED_VALUE , TEST_LOCATION ); + + pushButton.SetProperty( Button::Property::AUTO_REPEATING, true ); + + DALI_TEST_EQUALS( pushButton.GetProperty( Button::Property::TOGGLABLE ), !INITIAL_TOGGLE_VALUE , TEST_LOCATION ); + + END_TEST; +} + int UtcDaliPushButtonSetGetTogglableButton(void) { ToolkitTestApplication application; @@ -572,7 +596,7 @@ int UtcDaliPushButtonSelected(void) DALI_TEST_CHECK( !gPushButtonSelectedState ); // Test4. Touch point down inside and up outside the button. - + // State changes on Button down gPushButtonSelectedState = false; event = Dali::Integration::TouchEvent(); event.AddPoint( GetPointDownInside() ); @@ -586,9 +610,12 @@ int UtcDaliPushButtonSelected(void) event.AddPoint( GetPointUpOutside() ); application.ProcessEvent( event ); - DALI_TEST_CHECK( !gPushButtonSelectedState ); + DALI_TEST_CHECK( gPushButtonSelectedState ); // Test5. Touch point down outside and up inside the button. + // Start in unselected state + pushButton.SetProperty( Button::Property::SELECTED, false ); + DALI_TEST_CHECK( !pushButton.IsSelected()); gPushButtonSelectedState = false; event = Dali::Integration::TouchEvent(); @@ -661,8 +688,9 @@ int UtcDaliPushButtonPaddingLayout(void) // The icon and label are each enabled and disabled to confirm the correct padding is used. PushButton pushButton = PushButton::New(); - pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) ); - pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) ); + const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f ); + const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f ,10.0f ); + const Vector2 TEST_IMAGE_SIZE = Vector2( 5.0f, 5.0f); pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); @@ -679,29 +707,40 @@ int UtcDaliPushButtonPaddingLayout(void) Vector2 size( Vector2::ZERO ); size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height ); DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - // Check label only padding. + // Check label only padding pushButton.SetLabelText( "Label" ); application.SendNotification(); application.Render(); - size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); - size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO ); + sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); + sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + + tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height ); + + // Add label padding to label + pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING ); + application.SendNotification(); + application.Render(); + + Vector2 sizeLabelAndPadding( Vector2::ZERO ); + sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); + sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height ); - // We should not test against the exact label size, we just make sure it is larger than our label padding so we know the padding has been applied. - DALI_TEST_GREATER( size.width, 20.0f, TEST_LOCATION ); - DALI_TEST_GREATER( size.height, 20.0f, TEST_LOCATION ); + // If control size has increased beyond size of just label then padding has been applied + DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION ); + DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION ); // Re-initialise the button so we can setup icon-only padding. pushButton.Unparent(); pushButton = PushButton::New(); - pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) ); - pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) ); - pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); pushButton.SetPosition( 0.0f, 0.0f ); @@ -709,32 +748,53 @@ int UtcDaliPushButtonPaddingLayout(void) Stage::GetCurrent().Add( pushButton ); - const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg"; + TestPlatformAbstraction& platform = application.GetPlatform(); + platform.SetClosestImageSize( TEST_IMAGE_SIZE ); + pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" ); - pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME ); - pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME ); + pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE ); + pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE ); application.SendNotification(); application.Render(); + // Size of button with just icon size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height ); - DALI_TEST_EQUALS( size, Vector2( 40.0f, 40.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING ); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); + size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height ); + const Vector2 expectedIconAndPaddingSize( TEST_ICON_PADDING.x+TEST_ICON_PADDING.y+TEST_IMAGE_SIZE.width, TEST_ICON_PADDING.w+TEST_ICON_PADDING.z +TEST_IMAGE_SIZE.height ); + DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); // Now test padding for both label and icon simultaneously. pushButton.SetLabelText( "Label" ); + application.SendNotification(); + application.Render(); + + size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); + size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height ); + + pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING ); application.SendNotification(); application.Render(); size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height ); - // We should not test against the exact label size, we just make sure it is larger than our label padding so we know the padding has been applied. - // Note we only test the width as we are horizontally aligned and the label my be less high than the icon. - // Full directional alignment tests are done in UtcDaliPushButtonAlignmentLayout. - DALI_TEST_GREATER( size.width, 60.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION ); + DALI_TEST_GREATER( size.height, expectedIconAndPaddingSize.width, TEST_LOCATION ); // Test height of control is greater than icon and padding. As Text set to larger values. END_TEST; } @@ -769,10 +829,12 @@ int UtcDaliPushButtonAlignmentLayout(void) * | | v +------------+ - * +---------+ - */ - PushButton pushButton = PushButton::New(); - pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 30.0f, 30.0f, 30.0f, 30.0f ) ); - pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 75.0f, 75.0f, 75.0f, 75.0f ) ); + const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f ); + const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f ); + const Vector2 TEST_IMAGE_SIZE = Vector2( 10.0f, 10.0f); + + PushButton pushButton = PushButton::New(); pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); @@ -781,23 +843,43 @@ int UtcDaliPushButtonAlignmentLayout(void) Stage::GetCurrent().Add( pushButton ); - const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg"; - pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" ); - pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME ); - pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME ); + // Add a label and get size of control + pushButton.SetLabelText( "Label" ); + application.SendNotification(); + application.Render(); + // First get the size of control with just label + Vector2 justLabelSize( Vector2::ZERO ); + justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); + justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height ); + + pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING ); application.SendNotification(); application.Render(); - // First get the base size (without label). - Vector2 baseSize( Vector2::ZERO ); - baseSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); - baseSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + // Size of Label and Padding + Vector2 expectedLabelAndPaddingSize( Vector2::ZERO ); + expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y; + expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z; - DALI_TEST_EQUALS( baseSize, Vector2( 150.0f, 150.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + Vector2 labelAndPaddingSize( Vector2::ZERO ); + labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); + labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); - // Add a label to cause size to be modified in the direction of alignment. - pushButton.SetLabelText( "Label" ); + DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + + const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ), + ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) ); + + TestPlatformAbstraction& platform = application.GetPlatform(); + platform.SetClosestImageSize( TEST_IMAGE_SIZE ); + + // Add Icon and set its alignment + pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" ); + pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE ); + pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE ); + pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING ); application.SendNotification(); application.Render(); @@ -806,7 +888,6 @@ int UtcDaliPushButtonAlignmentLayout(void) size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); - /* * Test Icon right alignment. * Height grows to largest of Icon or Label (+ padding). @@ -820,8 +901,8 @@ int UtcDaliPushButtonAlignmentLayout(void) * |............+ | * +------------+---------+ */ - DALI_TEST_GREATER( size.width, 150.0f + 60.0f, TEST_LOCATION ); - DALI_TEST_EQUALS( size.height, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION ); + DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION ); // Now test left alignment matches right for size. pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" ); @@ -829,9 +910,8 @@ int UtcDaliPushButtonAlignmentLayout(void) application.SendNotification(); application.Render(); - Vector2 compareSize( Vector2::ZERO ); - compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); - compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); + size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); /* * Test Icon left alignment. @@ -846,20 +926,11 @@ int UtcDaliPushButtonAlignmentLayout(void) * | +............| * +---------+------------+ */ - DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - - // Test top alignment. - pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" ); - - application.SendNotification(); - application.Render(); - - compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); - compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION ); + DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)"); /* - * Test Icon top alignment. - * Width grows to largest of Icon or Label (+ padding). * * +---------+ * | | @@ -873,13 +944,10 @@ int UtcDaliPushButtonAlignmentLayout(void) * | | * +---------+ * - * Note: We subtract a small number as we want to do a >= test. */ - DALI_TEST_GREATER( size.width, 150.0f - Math::MACHINE_EPSILON_1000, TEST_LOCATION ); - DALI_TEST_GREATER( compareSize.height, 150.0f + 60.0f, TEST_LOCATION ); - // Test bottom alignment. - pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" ); + tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button"); + pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" ); application.SendNotification(); application.Render(); @@ -887,6 +955,16 @@ int UtcDaliPushButtonAlignmentLayout(void) size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width); + tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height); + + tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height ); + tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height ); + + DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION ); + + DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION ); + /* * Test Icon bottom alignment. * Width grows to largest of Icon or Label (+ padding). @@ -903,90 +981,119 @@ int UtcDaliPushButtonAlignmentLayout(void) * | | * +---------+ */ - DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)"); + pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" ); + + application.SendNotification(); + application.Render(); + + size.width = pushButton.GetRelayoutSize( Dimension::WIDTH ); + size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT ); + + DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION ); + DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION ); END_TEST; } -int UtcDaliPushButtonSetButtonImageP(void) +int UtcDaliPushButtonSetUnSelectedVisual01P(void) { + tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n"); ToolkitTestApplication application; - PushButton button = PushButton::New(); - Stage::GetCurrent().Add( button ); + PushButton pushButton = PushButton::New(); + pushButton.SetSize(100.0f, 100.0f); - try - { - button.SetButtonImage( ImageView::New() ); - DALI_TEST_CHECK( true ); - } - catch(...) - { - DALI_TEST_CHECK( false ); - } + Stage::GetCurrent().Add( pushButton ); - END_TEST; -} + Property::Map propertyMap; + propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE); -int UtcDaliPushButtonSetButtonImageN(void) -{ - ToolkitTestApplication application; + pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap ); - PushButton button; + tet_infoline(" UNSELECTED_VISUAL Added to button\n"); - try - { - button.SetSelectedImage( ImageView::New() ); - DALI_TEST_CHECK( false ); - } - catch(...) - { - DALI_TEST_CHECK( true ); - } + application.SendNotification(); + application.Render(0); - END_TEST; -} + unsigned int rendererCount = pushButton.GetRendererCount(); + tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount ); -int UtcDaliPushButtonSetBackgroundImageP(void) -{ - ToolkitTestApplication application; + DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION ); - PushButton button = PushButton::New(); - Stage::GetCurrent().Add( button ); + tet_printf("Remove button from stage\n" ); - try - { - button.SetBackgroundImage( ImageView::New() ); - DALI_TEST_CHECK( true ); - } - catch(...) - { - DALI_TEST_CHECK( false ); - } + Stage::GetCurrent().Remove( pushButton ); + + rendererCount = pushButton.GetRendererCount(); + tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount ); + + DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION ); + + tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount ); + + Property::Map propertyMap2; + propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR); + propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED); + pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap2 ); + + tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n"); + + Stage::GetCurrent().Add( pushButton ); + + tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() ); + + DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION ); END_TEST; } -int UtcDaliPushButtonSetBackgroundImageN(void) +int UtcDaliPushButtonSetSelectedVisualN(void) { + tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property"); + ToolkitTestApplication application; - PushButton button; + PushButton pushButton = PushButton::New(); - try - { - button.SetBackgroundImage( ImageView::New() ); - DALI_TEST_CHECK( false ); - } - catch(...) - { - DALI_TEST_CHECK( true ); - } + pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); + pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + + Stage::GetCurrent().Add( pushButton ); + application.SendNotification(); + application.Render(0); + + unsigned int preRendererCount = pushButton.GetRendererCount(); + tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount); + DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION ); + + Stage::GetCurrent().Remove( pushButton ); + application.SendNotification(); + application.Render(0); + + Property::Map colorMap; + const int BROKEN_VISUAL_TYPE = 999999999; + + colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE); + //colorMap.Insert(Visual::Property::TYPE, Visual::COLOR); + colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE); + colorMap.Insert(BorderVisual::Property::SIZE, 5.f); + pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, colorMap ); + + Stage::GetCurrent().Add( pushButton ); + application.SendNotification(); + application.Render(0); + + unsigned int postRendererCount = pushButton.GetRendererCount(); + tet_printf("RendererCount post broken visual (%d)\n", postRendererCount); + DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION ); END_TEST; } -int UtcDaliPushButtonSetSelectedImageP(void) +int UtcDaliPushButtonSetButtonImageP(void) { ToolkitTestApplication application; @@ -995,7 +1102,7 @@ int UtcDaliPushButtonSetSelectedImageP(void) try { - button.SetSelectedImage( ImageView::New() ); + button.SetButtonImage( ImageView::New() ); DALI_TEST_CHECK( true ); } catch(...) @@ -1006,26 +1113,27 @@ int UtcDaliPushButtonSetSelectedImageP(void) END_TEST; } -int UtcDaliPushButtonSetSelectedImageN(void) +int UtcDaliPushButtonSetBackgroundImageP(void) { ToolkitTestApplication application; - PushButton button; + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); try { - button.SetSelectedImage( ImageView::New() ); - DALI_TEST_CHECK( false ); + button.SetBackgroundImage( ImageView::New() ); + DALI_TEST_CHECK( true ); } catch(...) { - DALI_TEST_CHECK( true ); + DALI_TEST_CHECK( false ); } END_TEST; } -int UtcDaliPushButtonSetSelectedBackgroundImageP(void) +int UtcDaliPushButtonSetSelectedImageP(void) { ToolkitTestApplication application; @@ -1034,7 +1142,7 @@ int UtcDaliPushButtonSetSelectedBackgroundImageP(void) try { - button.SetSelectedBackgroundImage( ImageView::New() ); + button.SetSelectedImage( ImageView::New() ); DALI_TEST_CHECK( true ); } catch(...) @@ -1045,20 +1153,21 @@ int UtcDaliPushButtonSetSelectedBackgroundImageP(void) END_TEST; } -int UtcDaliPushButtonSetSelectedBackgroundImageN(void) +int UtcDaliPushButtonSetSelectedBackgroundImageP(void) { ToolkitTestApplication application; - PushButton button; + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); try { button.SetSelectedBackgroundImage( ImageView::New() ); - DALI_TEST_CHECK( false ); + DALI_TEST_CHECK( true ); } catch(...) { - DALI_TEST_CHECK( true ); + DALI_TEST_CHECK( false ); } END_TEST; @@ -1084,24 +1193,6 @@ int UtcDaliPushButtonSetDisabledBackgroundImageP(void) END_TEST; } -int UtcDaliPushButtonSetDisabledBackgroundImageN(void) -{ - ToolkitTestApplication application; - - PushButton button; - - try - { - button.SetDisabledBackgroundImage( ImageView::New() ); - DALI_TEST_CHECK( false ); - } - catch(...) - { - DALI_TEST_CHECK( true ); - } - - END_TEST; -} int UtcDaliPushButtonSetDisabledImageP(void) { @@ -1123,25 +1214,6 @@ int UtcDaliPushButtonSetDisabledImageP(void) END_TEST; } -int UtcDaliPushButtonSetDisabledImageN(void) -{ - ToolkitTestApplication application; - - PushButton button; - - try - { - button.SetDisabledImage( ImageView::New() ); - DALI_TEST_CHECK( false ); - } - catch(...) - { - DALI_TEST_CHECK( true ); - } - - END_TEST; -} - int UtcDaliPushButtonSetDisabledSelectedImageP(void) { ToolkitTestApplication application; @@ -1161,22 +1233,3 @@ int UtcDaliPushButtonSetDisabledSelectedImageP(void) END_TEST; } - -int UtcDaliPushButtonSetDisabledSelectedImageN(void) -{ - ToolkitTestApplication application; - - PushButton button; - - try - { - button.SetDisabledSelectedImage( ImageView::New() ); - DALI_TEST_CHECK( false ); - } - catch(...) - { - DALI_TEST_CHECK( true ); - } - - END_TEST; -} diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index de3fbe1..a7fabdf 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -193,7 +193,7 @@ void Builder::SetProperties( const TreeNode& node, Handle& handle, const Replace } else { - DALI_SCRIPT_VERBOSE("SetProperty INVALID '%s' Index=:%d\n", key.c_str(), index); + DALI_LOG_ERROR("Key '%s' not found.\n", key.c_str()); } // Add custom properties diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index 925daf1..53f89ca 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -20,10 +20,13 @@ // EXTERNAL INCLUDES #include // for strcmp +#include +#include #include #include #include #include +#include #include // INTERNAL INCLUDES @@ -31,32 +34,16 @@ #include #include #include +#include +#include +#include +#include #include -/** - * Button states and contents - * (3) mSelectedContent - * (2) mUnselectedContent (2) mSelectedBackgroundContent - * (1) mBackgroundContent (1) mBackgroundContent - * < unselected > ----------------------- < selected > - * | OnSelect() | - * | OnDisabled() | OnDisabled() - * | | - * < disabled > < disabled-selected > - * (2) mDisabledContent (2) mDisabledSelectedContent - * (1) mDisabledBackgroundContent (1) mDisabledBackgroundContent - * - * The drawing order of child actors is as follows. - * - * Top mLabel - * | mUnselectedContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent - * | mSelectedBackgroundContent - * Bottom mBackgroundContent / mDisabledBackgroundContent - * - * Some of contents may be missed. - * And 2 images - fade-in image and fade-out image - in the same layer can be shown during the transition animation. Fade-in image should be above fade-out image. - */ +#if defined(DEBUG_ENABLED) + Debug::Filter* gLogButtonFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_BUTTON_CONTROL"); +#endif namespace Dali { @@ -77,23 +64,31 @@ BaseHandle Create() } // Setup properties, signals and actions using the type-registry. -DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create ); - -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "autoRepeating", BOOLEAN, AUTO_REPEATING ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initialAutoRepeatingDelay", FLOAT, INITIAL_AUTO_REPEATING_DELAY ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "nextAutoRepeatingDelay", FLOAT, NEXT_AUTO_REPEATING_DELAY ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedStateImage", STRING, UNSELECTED_STATE_IMAGE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedStateImage", STRING, SELECTED_STATE_IMAGE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledStateImage", STRING, DISABLED_STATE_IMAGE ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedColor", VECTOR4, UNSELECTED_COLOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedColor", VECTOR4, SELECTED_COLOR ) -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label", MAP, LABEL ) - -// Deprecated properties: -DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelText", STRING, LABEL_TEXT ) +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create ) + +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "autoRepeating", BOOLEAN, AUTO_REPEATING ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initialAutoRepeatingDelay", FLOAT, INITIAL_AUTO_REPEATING_DELAY ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "nextAutoRepeatingDelay", FLOAT, NEXT_AUTO_REPEATING_DELAY ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedStateImage", MAP, UNSELECTED_STATE_IMAGE ) // Deprecated property +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedStateImage", MAP, SELECTED_STATE_IMAGE ) // Deprecated property +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledStateImage", MAP, DISABLED_STATE_IMAGE ) // Deprecated property +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedColor", VECTOR4, UNSELECTED_COLOR ) // Deprecated property +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedColor", VECTOR4, SELECTED_COLOR ) // Deprecated property +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label", MAP, LABEL ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelText", STRING, LABEL_TEXT ) // Deprecated property +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedVisual", MAP, UNSELECTED_VISUAL ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedVisual", MAP, SELECTED_VISUAL ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledSelectedVisual", MAP, DISABLED_SELECTED_VISUAL ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledUnselectedVisual", MAP, DISABLED_UNSELECTED_VISUAL ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedBackgroundVisual", MAP, UNSELECTED_BACKGROUND_VISUAL ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedBackgroundVisual", MAP, SELECTED_BACKGROUND_VISUAL ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledUnselectedBackgroundVisual", MAP, DISABLED_UNSELECTED_BACKGROUND_VISUAL ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledSelectedBackgroundVisual", MAP, DISABLED_SELECTED_BACKGROUND_VISUAL ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelStrutLength", INTEGER, LABEL_STRUT_LENGTH ) +DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelRelativeAlignment", STRING, LABEL_RELATIVE_ALIGNMENT ) // Signals: DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED ) @@ -106,26 +101,47 @@ DALI_ACTION_REGISTRATION( Toolkit, Button, "buttonClick", DALI_TYPE_REGISTRATION_END() -const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f ); -const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f ); +DALI_ENUM_TO_STRING_TABLE_BEGIN( ALIGNMENT ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, BEGIN ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, END ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, TOP ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, BOTTOM ) +DALI_ENUM_TO_STRING_TABLE_END( ALIGNMENT ) + +const Scripting::StringEnum ALIGNMENT_STRING_TABLE[] = +{ + { "BEGIN", Button::BEGIN }, + { "END", Button::END }, + { "TOP", Button::TOP }, + { "BOTTOM", Button::BOTTOM }, +}; + +const unsigned int ALIGNMENT_STRING_TABLE_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0] ); + +const Property::Index GET_VISUAL_INDEX_FOR_STATE[][Button::STATE_COUNT] = +{ + { Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::UNSELECTED_VISUAL }, + { Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::SELECTED_VISUAL }, + { Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL }, + { Toolkit::Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::DISABLED_SELECTED_VISUAL } +}; } // unnamed namespace Button::Button() : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), mAutoRepeatingTimer(), - mUnselectedColor( Color::WHITE ), // The natural colors of the specified images will be used by default. - mSelectedColor( Color::WHITE ), - mDisabled( false ), + mForeGroundToLabelStrutLength( 0.0f ), + mTextLabelAlignment( END ), mAutoRepeating( false ), mTogglableButton( false ), - mSelected( false ), - mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ), - mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ), + mInitialAutoRepeatingDelay( 0.0f ), + mNextAutoRepeatingDelay( 0.0f ), mAnimationTime( 0.0f ), - mClickActionPerforming( false ), - mState( ButtonUp ), - mPaintState( UnselectedState ) + mButtonPressedState( UNPRESSED ), + mButtonState( UNSELECTED_STATE ), + mPreviousButtonState( mButtonState ), + mClickActionPerforming( false ) { } @@ -133,139 +149,6 @@ Button::~Button() { } -void Button::SetDisabled( bool disabled ) -{ - if( disabled == mDisabled ) - { - return; - } - - StopTransitionAnimation(); - - mDisabled = disabled; - - // Notifies the derived class the button has been disabled. - OnDisabled(); - - switch( mPaintState ) - { - case UnselectedState: - { - //Layer Order - //(3) mDisabledContent (Inserted) - //(4) mUnselectedContent - //(2) mDisabledBackgroundContent (Inserted) - //(1) mBackgroundContent - - AddButtonImage( mBackgroundContent ); - TransitionButtonImage( mDisabledBackgroundContent ); - AddButtonImage( mUnselectedContent ); - TransitionButtonImage( mDisabledContent ); - - AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - ReAddLabel(); - - TransitionOut( mDecoration[ SELECTED_DECORATION ] ); - TransitionOut( mUnselectedContent ); - TransitionOut( mSelectedContent ); - TransitionOut( mBackgroundContent ); - TransitionOut( mSelectedBackgroundContent ); - TransitionOut( mDisabledSelectedContent ); - - mPaintState = DisabledUnselectedState; - break; - } - case SelectedState: - { - //Layer Order - //(5) mDisabledSelectedContent (Inserted) - //(4) mSelectedContent - //(3) mDisabledBackgroundContent (Inserted) - //(2) mSelectedBackgroundContent - //(1) mBackgroundContent - - AddButtonImage( mBackgroundContent ); - AddButtonImage( mSelectedBackgroundContent ); - TransitionButtonImage( mDisabledBackgroundContent ); - AddButtonImage( mSelectedContent ); - TransitionButtonImage( mDisabledSelectedContent ); - - AddButtonImage( mDecoration[ SELECTED_DECORATION ] ); - ReAddLabel(); - - TransitionOut( mDecoration[ UNSELECTED_DECORATION ] ); - TransitionOut( mUnselectedContent ); - TransitionOut( mSelectedContent ); - TransitionOut( mBackgroundContent ); - TransitionOut( mSelectedBackgroundContent ); - TransitionOut( mDisabledContent ); - - mPaintState = DisabledSelectedState; - break; - } - case DisabledUnselectedState: - { - //Layer Order - //(3) mUnselectedContent (Inserted) - //(4) mDisabledContent - //(2) mBackgroundContent (Inserted) - //(1) mDisabledBackgroundContent - - AddButtonImage( mDisabledBackgroundContent ); - TransitionButtonImage( mBackgroundContent ); - AddButtonImage( mDisabledContent ); - TransitionButtonImage( mUnselectedContent ); - - AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - ReAddLabel(); - - TransitionOut( mDecoration[ SELECTED_DECORATION ] ); - TransitionOut( mSelectedContent ); - TransitionOut( mSelectedBackgroundContent ); - TransitionOut( mDisabledContent ); - TransitionOut( mDisabledSelectedContent ); - TransitionOut( mDisabledBackgroundContent ); - - mPaintState = UnselectedState; - break; - } - case DisabledSelectedState: - { - //Layer Order - //(4) mSelectedContent (Inserted) - //(5) mDisabledSelectedContent - //(3) mSelectedBackgroundContent (Inserted) - //(2) mBackgroundContent (Inserted) - //(1) mDisabledBackgroundContent - - AddButtonImage( mDisabledBackgroundContent ); - TransitionButtonImage( mBackgroundContent ); - TransitionButtonImage( mSelectedBackgroundContent ); - AddButtonImage( mDisabledSelectedContent ); - TransitionButtonImage( mSelectedContent ); - - AddButtonImage( mDecoration[ SELECTED_DECORATION ] ); - ReAddLabel(); - - TransitionOut( mDecoration[ UNSELECTED_DECORATION ] ); - TransitionOut( mUnselectedContent ); - TransitionOut( mDisabledContent ); - TransitionOut( mDisabledSelectedContent ); - TransitionOut( mDisabledBackgroundContent ); - - mPaintState = SelectedState; - break; - } - } - - StartTransitionAnimation(); -} - -bool Button::IsDisabled() const -{ - return mDisabled; -} - void Button::SetAutoRepeating( bool autoRepeating ) { mAutoRepeating = autoRepeating; @@ -275,10 +158,9 @@ void Button::SetAutoRepeating( bool autoRepeating ) { mTogglableButton = false; - if( mSelected ) + if( IsSelected() ) { - // Emit a signal is not wanted, only change the appearance. - SetSelected( false, false ); + SetSelected( false ); } } } @@ -290,7 +172,7 @@ bool Button::IsAutoRepeating() const void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay ) { - DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f ); + DALI_ASSERT_DEBUG( initialAutoRepeatingDelay > 0.f ); mInitialAutoRepeatingDelay = initialAutoRepeatingDelay; } @@ -301,7 +183,7 @@ float Button::GetInitialAutoRepeatingDelay() const void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay ) { - DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f ); + DALI_ASSERT_DEBUG( nextAutoRepeatingDelay > 0.f ); mNextAutoRepeatingDelay = nextAutoRepeatingDelay; } @@ -314,7 +196,7 @@ void Button::SetTogglableButton( bool togglable ) { mTogglableButton = togglable; - // A togglable button can't be an autorepeating button. + // A toggle button can't be an autorepeating button. if( togglable ) { mAutoRepeating = false; @@ -328,98 +210,121 @@ bool Button::IsTogglableButton() const void Button::SetSelected( bool selected ) { - if( !mDisabled && mTogglableButton && ( selected != mSelected ) ) + if( mTogglableButton ) { - SetSelected( selected, true ); + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetSelected (%s)\n", (selected?"true":"false") ); + + if ( selected && ( mButtonState != SELECTED_STATE ) ) + { + ChangeState( SELECTED_STATE ); + } + else if ( !selected && ( mButtonState != UNSELECTED_STATE ) ) + { + ChangeState( UNSELECTED_STATE ); + } } } -void Button::SetSelected( bool selected, bool emitSignal ) +void Button::SetDisabled( bool disabled ) { - StopTransitionAnimation(); - - mSelected = selected; + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetDisabled(%s) state(%d)\n", (disabled)?"disabled":"active", mButtonState ); - // Notifies the derived class the button has been selected. - OnSelected(); - - switch( mPaintState ) + if ( disabled ) { - case UnselectedState: + if ( mButtonState == SELECTED_STATE ) { - //Layer Order - //(3) mSelectedContent (Inserted) - //(4) mUnselectedContent - //(2) mSelectedBackgroundContent (Inserted) - //(1) mBackgroundContent - - AddButtonImage( mBackgroundContent ); - TransitionButtonImage( mSelectedBackgroundContent ); - AddButtonImage( mUnselectedContent ); - TransitionButtonImage( mSelectedContent ); - - AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - TransitionButtonImage( mDecoration[ SELECTED_DECORATION ] ); - ReAddLabel(); - - TransitionOut( mDecoration[ UNSELECTED_DECORATION ] ); - TransitionOut( mUnselectedContent ); - TransitionOut( mDisabledContent ); - TransitionOut( mDisabledSelectedContent ); - TransitionOut( mDisabledBackgroundContent ); - - mPaintState = SelectedState; - break; + ChangeState( DISABLED_SELECTED_STATE ); } - case SelectedState: + else if ( mButtonState == UNSELECTED_STATE ) { - //Layer Order - //(3) mUnselectedContent (Inserted) - //(2) mSelectedContent - //(1) mBackgroundContent - - AddButtonImage( mBackgroundContent ); - AddButtonImage( mSelectedContent ); - TransitionButtonImage( mUnselectedContent ); - - AddButtonImage( mDecoration[ SELECTED_DECORATION ] ); - TransitionButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - ReAddLabel(); - - TransitionOut( mDecoration[ SELECTED_DECORATION ] ); - TransitionOut( mSelectedContent ); - TransitionOut( mSelectedBackgroundContent ); - TransitionOut( mDisabledContent ); - TransitionOut( mDisabledSelectedContent ); - TransitionOut( mDisabledBackgroundContent ); - - mPaintState = UnselectedState; - break; + ChangeState( DISABLED_UNSELECTED_STATE ); + } + } + else + { + if ( mButtonState == DISABLED_SELECTED_STATE ) + { + ChangeState( SELECTED_STATE ); } - case DisabledUnselectedState: - case DisabledSelectedState: + else if ( mButtonState == DISABLED_UNSELECTED_STATE ) { - DALI_ASSERT_DEBUG( 0 && "Shouldn't be able to change paint state if the button is disabled." ); - break; + ChangeState( UNSELECTED_STATE ); } } +} + +bool Button::IsDisabled() const +{ + return ( mButtonState == DISABLED_SELECTED_STATE || mButtonState == DISABLED_UNSELECTED_STATE ) ; +} + +bool Button::ValidateState( State requestedState ) +{ + /* Below tables shows allowed state transitions + * Match rows in first column to following columns, if true then transition allowed. + * eg UNSELECTED_STATE to DISABLED_UNSELECTED_STATE is true so state transition allowed. + * + to| UNSELECTED_STATE | SELECTED_STATE | DISABLED_UNSELECTED_STATE | DISABLED_SELECTED_STATE |*/ + /* from*/ + bool transitionTable[4][4] = { /* UNSELECTED_STATE*/ { false, true, true, false }, + /* SELECTED_STATE*/ { true, false, false, true }, + /* DISABLED_UNSELECTED_STATE*/{ true, true, false, false }, + /* DISABLED_SELECTED_STATE*/ { false, true, false, false } + }; + + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ValidateState ReuestedState:%d, CurrentState:%d, result:%s\n", + requestedState, mButtonState, (transitionTable[mButtonState][requestedState])?"change-accepted":"change-denied"); + + return transitionTable[mButtonState][requestedState]; +} + +void Button::PerformFunctionOnVisualsInState( void(Button::*functionPtr)( Property::Index visualIndex), State state ) +{ + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState BACKROUND visual(%d) for state (%d)\n", GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND], state ); + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState FOREGROUND visuals(%d) for state (%d)\n", GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND], state ); + + (this->*functionPtr)( GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND] ); + (this->*functionPtr)( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] ); - StartTransitionAnimation(); + RelayoutRequest(); +} + +void Button::ChangeState( State requestedState ) +{ + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ChangeState ReuestedState(%d)\n", requestedState ); - if( emitSignal ) + // Validate State before changing + if ( !ValidateState( requestedState )) { - Toolkit::Button handle( GetOwner() ); + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ChangeState ReuestedState(%d) not validated\n", requestedState ); + return; + } + + // If not on stage the button could have still been set to selected so update state/ + mPreviousButtonState = mButtonState; // Store previous state for visual removal (used when animations ended) + mButtonState = requestedState; // Update current state - // Emit signal. - mStateChangedSignal.Emit( handle ); + if ( Self().OnStage() ) + { + // Clear existing animation and remove visual being transitioned out before starting a new transition of visuals. ClearTransitionAnimation(); + OnStateChange( mButtonState ); // Notify derived buttons + //// When animations enabled PerformFunctionOnVisualsInState( &Button::TransitionButtonVisualOut, mPreviousButtonState ); + PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState ); + // When animations enabled then call PerformFunctionOnVisualsInState( &Button::TransitionButtonVisualIn, mButtonState ); + // then StartTransitionAnimation(); + // and ClearTransitionAnimation(); + PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval } - RelayoutRequest(); + Toolkit::Button handle( GetOwner() ); + // Emit signal. + mStateChangedSignal.Emit( handle ); } bool Button::IsSelected() const { - return mTogglableButton && mSelected; + bool selected = ( mButtonState == SELECTED_STATE ) || ( mButtonState == DISABLED_SELECTED_STATE ); + return mTogglableButton && selected; } void Button::SetAnimationTime( float animationTime ) @@ -436,7 +341,7 @@ void Button::SetLabelText( const std::string& label ) { Property::Map labelProperty; labelProperty.Insert( "text", label ); - ModifyLabel( labelProperty ); + SetupLabel( labelProperty ); } std::string Button::GetLabelText() const @@ -449,16 +354,37 @@ std::string Button::GetLabelText() const return std::string(); } -void Button::ModifyLabel( const Property::Map& properties ) +void Button::SetupLabel( const Property::Map& properties ) { + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "SetupLabel\n"); + // 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 + mLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); + mLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" ); + mLabel.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + + // todo DEBUG + mLabel.SetProperty( Toolkit::Control::Property::BACKGROUND, Dali::Property::Map() + .Add( Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::COLOR ) + .Add( Toolkit::ColorVisual::Property::MIX_COLOR, Color::RED ) + ); + + ResizePolicy::Type policy = Self().GetResizePolicy( Dimension::ALL_DIMENSIONS ); + if ( policy == ResizePolicy::USE_NATURAL_SIZE || policy == ResizePolicy::FIT_TO_CHILDREN ) + { + mLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); + } + else + { + // todo Can't set Text Label to USE_ASSIGNED_SIZE as causes a relayout in it whilst doing a relayout = error + //mLabel.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS ); + } Self().Add( mLabel ); } @@ -483,270 +409,94 @@ void Button::ModifyLabel( const Property::Map& properties ) RelayoutRequest(); } -Actor& Button::GetLabelActor() +void Button::SetLabelStrutLength( unsigned int length ) { - return mLabel; + mForeGroundToLabelStrutLength = length; } -void Button::SetDecoration( DecorationState state, Actor actor ) +void Button::SetLabelAlignment( Button::Align labelAlignment) { - if( mDecoration[ state ] && mDecoration[ state ].GetParent() ) - { - mDecoration[ state ].Unparent(); - } - - mDecoration[ state ] = actor; - mDecoration[ state ].SetColorMode( USE_OWN_COLOR ); - - ResetImageLayers(); + mTextLabelAlignment = labelAlignment; RelayoutRequest(); } -Actor& Button::GetDecoration( DecorationState state ) -{ - return mDecoration[ state ]; -} - -void Button::SetupContent( Actor& actorToModify, Actor newActor ) +float Button::GetLabelStrutLength() { - if( newActor ) - { - StopTransitionAnimation(); - - if( actorToModify && actorToModify.GetParent() ) - { - actorToModify.Unparent(); - } - - actorToModify = newActor; - - if( actorToModify ) - { - actorToModify.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - actorToModify.SetParentOrigin( ParentOrigin::TOP_LEFT ); - actorToModify.SetPosition( 0.f, 0.f ); - } - - ResetImageLayers(); - } + return mForeGroundToLabelStrutLength; } -const Vector4 Button::GetUnselectedColor() const +Button::Align Button::GetLabelAlignment() { - return mUnselectedColor; + return mTextLabelAlignment; } -void Button::SetColor( const Vector4& color, Button::PaintState selectedState ) +void Button::CreateVisualsForComponent( Property::Index index, const Property::Value& value, const float visualDepth ) { - Actor* contentActor = NULL; // Using a pointer as SetupContent assigns the new Actor to this. - bool imageFileExists = false; - Property::Index visualIndex = Toolkit::Button::Property::SELECTED_STATE_IMAGE; - - if ( selectedState == SelectedState || selectedState == DisabledSelectedState ) - { - mSelectedColor = color; - contentActor = &mSelectedContent; - imageFileExists = !GetSelectedImageFilename().empty(); - } - else - { - mUnselectedColor = color; - contentActor = &mUnselectedContent; - imageFileExists = !GetUnselectedImageFilename().empty(); - visualIndex = Toolkit::Button::Property::UNSELECTED_STATE_IMAGE; - } + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent index(%d)\n", index ); + Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); + Toolkit::Visual::Base buttonVisual; - if ( contentActor ) + std::string imageUrl; + if( value.Get( imageUrl ) ) { - if( imageFileExists ) + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using image URL(%d)\n", index ); + if ( !imageUrl.empty() ) { - // If there is existing unselected content, change the color on it directly. - contentActor->SetColor( color ); + buttonVisual = visualFactory.CreateVisual( imageUrl, ImageDimensions() ); } - else - { - // If there is no existing content, create a new actor to use for flat color. - Actor placementActor = Actor::New(); - Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get(); - Toolkit::Visual::Base visual; - - Property::Map map; - map[ Toolkit::DevelVisual::Property::TYPE ] = Toolkit::Visual::COLOR; - map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; - - visual = visualFactory.CreateVisual( map ); - - RegisterVisual( visualIndex, visual ); - - SetupContent( *contentActor, placementActor ); // - contentActor->SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); - } - } -} - -const Vector4 Button::GetSelectedColor() const -{ - return mSelectedColor; -} - -void Button::SetUnselectedImage( const std::string& filename ) -{ - Toolkit::ImageView newContent; - if( !filename.empty() ) - { - newContent = Toolkit::ImageView::New( filename ); } else { - newContent = Toolkit::ImageView::New(); - } - - if( newContent ) - { - SetupContent( mUnselectedContent, newContent ); - - mUnselectedContent.SetColor( mUnselectedColor ); - - OnUnselectedImageSet(); - RelayoutRequest(); + // if its not a string then get a Property::Map from the property if possible. + Property::Map *map = value.GetMap(); + if( map && !map->Empty() ) // Empty map results in current visual removal. + { + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using Map(%d)\n", index ); + buttonVisual = visualFactory.CreateVisual( *map ); + } } -} - -Actor& Button::GetUnselectedImage() -{ - return mUnselectedContent; -} -void Button::SetSelectedImage( const std::string& filename ) -{ - Toolkit::ImageView newContent; - if( !filename.empty() ) + if ( buttonVisual ) { - newContent = Toolkit::ImageView::New( filename ); + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "RegisterVisual index(%d)\n", index ); + buttonVisual.SetDepthIndex( visualDepth ); + // Background Visuals take full size of control + RegisterVisual( index, buttonVisual, false ); } else { - newContent = Toolkit::ImageView::New(); - } - - if( newContent ) - { - SetupContent( mSelectedContent, newContent ); - - mSelectedContent.SetColor( mSelectedColor ); - - OnSelectedImageSet(); - RelayoutRequest(); + UnregisterVisual( index ); + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "Button visual not created or empty map provided (clearing visual).(%d)\n", index); } } -Actor& Button::GetSelectedImage() -{ - return mSelectedContent; -} - -void Button::SetBackgroundImage( const std::string& filename ) -{ - SetupContent( mBackgroundContent, Toolkit::ImageView::New( filename ) ); - - OnBackgroundImageSet(); - RelayoutRequest(); -} - -Actor& Button::GetBackgroundImage() -{ - return mBackgroundContent; -} - -void Button::SetSelectedBackgroundImage( const std::string& filename ) -{ - SetupContent( mSelectedBackgroundContent, Toolkit::ImageView::New( filename ) ); - - OnSelectedBackgroundImageSet(); - RelayoutRequest(); -} - -Actor& Button::GetSelectedBackgroundImage() -{ - return mSelectedBackgroundContent; -} - -void Button::SetDisabledImage( const std::string& filename ) -{ - SetupContent( mDisabledContent, Toolkit::ImageView::New( filename ) ); - - OnDisabledImageSet(); - RelayoutRequest(); -} - -Actor& Button::GetDisabledImage() -{ - return mDisabledContent; -} - -void Button::SetDisabledSelectedImage( const std::string& filename ) -{ - SetupContent( mDisabledSelectedContent, Toolkit::ImageView::New( filename ) ); - - OnDisabledSelectedImageSet(); - RelayoutRequest(); -} - -Actor& Button::GetDisabledSelectedImage() -{ - return mDisabledSelectedContent; -} - -void Button::SetDisabledBackgroundImage( const std::string& filename ) +const Vector4 Button::GetUnselectedColor() const { - SetupContent( mDisabledBackgroundContent, Toolkit::ImageView::New( filename ) ); - - OnDisabledBackgroundImageSet(); - RelayoutRequest(); + return mUnselectedColor; } -Actor& Button::GetDisabledBackgroundImage() +const Vector4 Button::GetSelectedColor() const { - return mDisabledBackgroundContent; + return mSelectedColor; } -std::string Button::GetUnselectedImageFilename() const +// Legacy code whilst Color can be set by direct Property setting ( deprecated ) instead of setting a Visual +void Button::SetColor( const Vector4& color, Property::Index visualIndex ) { - if( mUnselectedContent ) + if ( visualIndex == Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL ) { - ResourceImage image = ResourceImage::DownCast( mUnselectedContent ); - if( image ) - { - return image.GetUrl(); - } + mSelectedColor = color; } - return std::string(); -} - -std::string Button::GetSelectedImageFilename() const -{ - if( mSelectedContent ) + else { - ResourceImage image = ResourceImage::DownCast( mSelectedContent ); - if( image ) - { - return image.GetUrl(); - } + mUnselectedColor = color; } - return std::string(); -} -std::string Button::GetDisabledImageFilename() const -{ - if( mDisabledContent ) - { - ResourceImage image = ResourceImage::DownCast( mDisabledContent ); - if( image ) - { - return image.GetUrl(); - } - } - return std::string(); + Property::Map map; + map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR; + map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; + + CreateVisualsForComponent( visualIndex, map, DepthIndex::BACKGROUND ); } bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ) @@ -757,7 +507,7 @@ bool Button::DoAction( BaseObject* object, const std::string& actionName, const Toolkit::Button button = Toolkit::Button::DownCast( handle ); - DALI_ASSERT_ALWAYS( button ); + DALI_ASSERT_DEBUG( button ); if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) ) { @@ -775,7 +525,10 @@ bool Button::DoClickAction( const Property::Map& attributes ) { mClickActionPerforming = true; OnButtonDown(); - mState = ButtonDown; + if ( !mTogglableButton ) + { + mButtonPressedState = DEPRESSED; + } OnButtonUp(); mClickActionPerforming = false; @@ -787,13 +540,25 @@ bool Button::DoClickAction( const Property::Map& attributes ) void Button::OnButtonDown() { - if( !mTogglableButton ) + if( mTogglableButton ) + { + if ( mButtonState != SELECTED_STATE ) + { + SetSelected( true ); + mButtonPressedState = TOGGLE_DEPRESSED; + } + else + { + mButtonPressedState = DEPRESSED; + } + } + else { Pressed(); - + mButtonPressedState = DEPRESSED; if( mAutoRepeating ) { - SetUpTimer( mInitialAutoRepeatingDelay ); + SetUpTimer( mInitialAutoRepeatingDelay ); } } @@ -804,16 +569,19 @@ void Button::OnButtonDown() void Button::OnButtonUp() { - if( ButtonDown == mState ) + if( DEPRESSED == mButtonPressedState ) { if( mTogglableButton ) { - SetSelected( !mSelected ); + if ( TOGGLE_DEPRESSED != mButtonPressedState ) + { + SetSelected( !IsSelected() ); + mButtonPressedState = UNPRESSED; + } } else { Released(); - if( mAutoRepeating ) { mAutoRepeatingTimer.Reset(); @@ -829,7 +597,7 @@ void Button::OnButtonUp() void Button::OnTouchPointLeave() { - if( ButtonDown == mState ) + if( DEPRESSED == mButtonPressedState ) { if( !mTogglableButton ) { @@ -841,6 +609,8 @@ void Button::OnTouchPointLeave() } } + mButtonPressedState = UNPRESSED; + // The released signal should be emitted regardless of toggle mode. Toolkit::Button handle( GetOwner() ); mReleasedSignal.Emit( handle ); @@ -906,6 +676,8 @@ bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tr void Button::OnInitialize() { + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnInitialize\n" ); + Actor self = Self(); mTapDetector = TapGestureDetector::New(); @@ -922,73 +694,34 @@ bool Button::OnAccessibilityActivated() return OnKeyboardEnter(); } -bool Button::OnKeyboardEnter() +bool Button::OnTouch( Actor actor, const TouchData& touch ) { - // When the enter key is pressed, or button is activated, the click action is performed. - Property::Map attributes; - bool ret = DoClickAction( attributes ); - return ret; -} + // Only events are processed when the button is not disabled and the touch event has only + // one touch point. -void Button::OnStageDisconnection() -{ - if( ButtonDown == mState ) + if( !IsDisabled() && ( 1 == touch.GetPointCount() ) ) { - if( !mTogglableButton ) + switch( touch.GetState( 0 ) ) { - Released(); - - if( mAutoRepeating ) + case PointState::DOWN: { - mAutoRepeatingTimer.Reset(); - } - } - } - - mState = ButtonUp; - - Control::OnStageDisconnection(); -} - -bool Button::OnTouch( Actor actor, const TouchData& touch ) -{ - // Only events are processed when the button is not disabled and the touch event has only - // one touch point. - if( ( !mDisabled ) && ( 1 == touch.GetPointCount() ) ) - { - switch( touch.GetState( 0 ) ) - { - case PointState::DOWN: - { - OnButtonDown(); // Notification for derived classes. - - // Sets the button state to ButtonDown. - mState = ButtonDown; - break; + OnButtonDown(); + break; } case PointState::UP: { - OnButtonUp(); // Notification for derived classes. - - // Sets the button state to ButtonUp. - mState = ButtonUp; + OnButtonUp(); break; } case PointState::INTERRUPTED: { - OnTouchPointInterrupted(); // Notification for derived classes. - - // Sets the button state to the default (ButtonUp). - mState = ButtonUp; + OnTouchPointInterrupted(); break; } case PointState::LEAVE: { - OnTouchPointLeave(); // Notification for derived classes. - - // Sets the button state to the default (ButtonUp). - mState = ButtonUp; + OnTouchPointLeave(); break; } case PointState::MOTION: @@ -1003,317 +736,411 @@ bool Button::OnTouch( Actor actor, const TouchData& touch ) { OnTouchPointLeave(); // Notification for derived classes. - // Sets the button state to the default (ButtonUp). - mState = ButtonUp; + // Sets the button state to the default + mButtonPressedState = UNPRESSED; } return false; } -void Button::OnTap(Actor actor, const TapGesture& tap) +bool Button::OnKeyboardEnter() { - // Do nothing. -} + // When the enter key is pressed, or button is activated, the click action is performed. + Property::Map attributes; + bool ret = DoClickAction( attributes ); -void Button::SetUpTimer( float delay ) -{ - mAutoRepeatingTimer = Dali::Timer::New( static_cast( 1000.f * delay ) ); - mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot ); - mAutoRepeatingTimer.Start(); + return ret; } -bool Button::AutoRepeatingSlot() +void Button::OnStageDisconnection() { - bool consumed = false; - if( !mDisabled ) + if( DEPRESSED == mButtonPressedState ) { - // Restart the autorepeat timer. - SetUpTimer( mNextAutoRepeatingDelay ); + if( !mTogglableButton ) + { + Released(); - Pressed(); + if( mAutoRepeating ) + { + mAutoRepeatingTimer.Reset(); + } + } + } - Toolkit::Button handle( GetOwner() ); + mButtonPressedState = UNPRESSED; - //Emit signal. - consumed = mReleasedSignal.Emit( handle ); - consumed |= mClickedSignal.Emit( handle ); - consumed |= mPressedSignal.Emit( handle ); - } + Control::OnStageDisconnection(); // Visuals will be set off stage +} + +void Button::OnStageConnection( int depth ) +{ + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnStageConnection ptr(%p) \n", this ); + PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState ); + Control::OnStageConnection( depth ); // Enabled visuals will be put on stage - return consumed; } -void Button::Pressed() +Vector3 Button::GetNaturalSize() { - if( mPaintState == UnselectedState ) + Vector3 size = Vector3::ZERO; + + 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 labelSize; + + for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++) { - StopTransitionAnimation(); + 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 ); + } + } - // Notifies the derived class the button has been pressed. - OnPressed(); + // Get horizontal padding total + if ( largestForegroundVisual.width > 0 ) // if visual exists + { + size.width += largestForegroundVisual.width + mForegroundPadding.left + mForegroundPadding.right; + } + // Get vertical padding total + if ( largestForegroundVisual.height > 0 ) + { + size.height += largestForegroundVisual.height + mForegroundPadding.top + mForegroundPadding.bottom; + } - //Layer Order - //(4) mSelectedContent (Inserted) - //(3) mUnselectedContent - //(2) mSelectedBackgroundContent (Inserted) - //(1) mBackgroundContent + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize visual Size(%f,%f)\n", + largestForegroundVisual.width, largestForegroundVisual.height ); - AddButtonImage( mBackgroundContent ); - TransitionButtonImage( mSelectedBackgroundContent ); - AddButtonImage( mUnselectedContent ); - TransitionButtonImage( mSelectedContent ); + // Get natural size of label + if ( mLabel ) + { + labelSize = Vector2( mLabel.GetNaturalSize()); - AddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - TransitionButtonImage( mDecoration[ SELECTED_DECORATION ] ); - ReAddLabel(); + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize labelSize(%f,%f) padding(%f,%f)\n", + labelSize.width, labelSize.height, mLabelPadding.left + mLabelPadding.right, mLabelPadding.top + mLabelPadding.bottom); - TransitionOut( mDecoration[ UNSELECTED_DECORATION ] ); - TransitionOut( mUnselectedContent ); - TransitionOut( mDisabledContent ); - TransitionOut( mDisabledSelectedContent ); - TransitionOut( mDisabledBackgroundContent ); + labelSize.width += mLabelPadding.left + mLabelPadding.right; + labelSize.height += mLabelPadding.top + mLabelPadding.bottom; - mPaintState = SelectedState; + // Add label size to height or width depending on alignment position + if ( horizontalAlignment ) + { + size.width += labelSize.width; + size.height = std::max(size.height, labelSize.height ); + } + else + { + size.height += labelSize.height; + size.width = std::max(size.width, labelSize.width ); + } + } - StartTransitionAnimation(); + if( size.width < 1 && size.height < 1 ) + { + // if no image or label then use Control's natural size + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize Using control natural size\n"); + size = Control::GetNaturalSize(); } + + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "Button GetNaturalSize (%f,%f)\n", size.width, size.height ); + + return size; } -void Button::Released() +void Button::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) { - if( mPaintState == SelectedState ) + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnSetResizePolicy\n"); + + if ( policy != ResizePolicy::USE_NATURAL_SIZE || policy != ResizePolicy::FIT_TO_CHILDREN ) { - StopTransitionAnimation(); + if ( mLabel ) + { + // todo Can't set Text Label to USE_ASSIGNED_SIZE as causes a relayout in it whilst doing a relayout = error + //mLabel.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS ); + } + } + + RelayoutRequest(); +} - // Notifies the derived class the button has been released. - OnReleased(); +void Button::OnRelayout( const Vector2& size, RelayoutContainer& container ) +{ + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout targetSize(%f,%f) ptr(%p) state[%d]\n", size.width, size.height, this, mButtonState ); + + PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState ); - //Layer Order - //(3) mUnselectedContent (Inserted) - //(2) mSelectedContent - //(1) mBackgroundContent + ResizePolicy::Type widthResizePolicy = Self().GetResizePolicy( Dimension::WIDTH ); + ResizePolicy::Type heightResizePolicy = Self().GetResizePolicy( Dimension::HEIGHT ); - AddButtonImage( mBackgroundContent ); - AddButtonImage( mSelectedContent ); - TransitionButtonImage( mUnselectedContent ); + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout resize policy: width:%d height:%d\n", heightResizePolicy, widthResizePolicy); - AddButtonImage( mDecoration[ SELECTED_DECORATION ] ); - TransitionButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - ReAddLabel(); + Toolkit::Visual::Base currentVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND] ); - TransitionOut( mDecoration[ SELECTED_DECORATION ] ); - TransitionOut( mSelectedContent ); - TransitionOut( mSelectedBackgroundContent ); - TransitionOut( mDisabledContent ); - TransitionOut( mDisabledSelectedContent ); - TransitionOut( mDisabledBackgroundContent ); + Toolkit::Visual::Base currentBackGroundVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND] ); - mPaintState = UnselectedState; + // Sizes and padding set to zero, if not present then values will no effect calculations. + Vector2 visualPosition = Vector2::ZERO; + Vector2 labelPosition = Vector2::ZERO; + Size visualSize = Size::ZERO; + Padding foregroundVisualPadding = Padding(0.0f, 0.0f, 0.0f, 0.0f ); + Padding labelVisualPadding = Padding(0.0f, 0.0f, 0.0f, 0.0f ); - StartTransitionAnimation(); + if ( mLabel ) + { + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Label padding setting padding:%f,%f,%f,%f\n", mLabelPadding.y, mLabelPadding.x, mLabelPadding.width,mLabelPadding.height ); + labelVisualPadding = mLabelPadding; } + + if ( currentVisual ) + { + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Foreground Visual setting padding:%f,%f,%f,%f\n", mForegroundPadding.y, mForegroundPadding.x, mForegroundPadding.width,mForegroundPadding.height ); + currentVisual.GetNaturalSize( visualSize ); + foregroundVisualPadding = mForegroundPadding; + } + + Toolkit::Align::Type visualAnchorPoint = Toolkit::Align::TOP_BEGIN; + + Vector2 visualAndPaddingSize = Vector2( ( foregroundVisualPadding.x + visualSize.width + foregroundVisualPadding.y ), + ( foregroundVisualPadding.width + visualSize.height + foregroundVisualPadding.height )); + + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout visualAndPaddingSize(%f,%f)\n", visualAndPaddingSize.width, visualAndPaddingSize.height); + + switch ( mTextLabelAlignment ) + { + case BEGIN : + { + visualAnchorPoint = Toolkit::Align::TOP_END; + visualPosition.x = foregroundVisualPadding.right; + visualPosition.y = foregroundVisualPadding.top; + + labelPosition.x = labelVisualPadding.x; + labelPosition.y = labelVisualPadding.top; + break; + } + case END : + { + visualAnchorPoint = Toolkit::Align::TOP_BEGIN; + visualPosition.x = foregroundVisualPadding.left; + visualPosition.y = foregroundVisualPadding.top; + + labelPosition.x = visualAndPaddingSize.width + labelVisualPadding.x; + labelPosition.y = labelVisualPadding.top; + break; + } + case TOP : + { + visualAnchorPoint = Toolkit::Align::BOTTOM_END; + visualPosition.x = foregroundVisualPadding.left; + visualPosition.y = foregroundVisualPadding.bottom; + + labelPosition.x = labelVisualPadding.left; + labelPosition.y = labelVisualPadding.top; + break; + } + case BOTTOM : + { + visualAnchorPoint = Toolkit::Align::TOP_END; + visualPosition.x = foregroundVisualPadding.left; + visualPosition.y = foregroundVisualPadding.top; + + labelPosition.x = labelVisualPadding.left; + labelPosition.y = visualAndPaddingSize.height + labelVisualPadding.top; + break; + } + } + + if ( currentBackGroundVisual ) + { + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual bakcground 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 + + currentBackGroundVisual.SetTransformAndSize( visualTransform, size ); + } + + if ( currentVisual ) + { + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual size to(%f,%f)\n", visualSize.width, visualSize.height); + + currentVisual.SetProperty( Toolkit::Visual::DevelProperty::TRANSFORM, + Dali::Property::Map() + .Add( Toolkit::Visual::DevelProperty::Transform::Property::SIZE, visualSize ) + .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET, visualPosition ) + .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4(1.0f, 1.0f, 1.0f,1.0f) ) + .Add( Toolkit::Visual::DevelProperty::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN ) + .Add( Toolkit::Visual::DevelProperty::Transform::Property::ANCHOR_POINT, visualAnchorPoint ) + ); + } + + if ( mLabel ) + { + // When Text visual size can be set, determine the size here. + // Text Visual should take all space available after foreground visual size and all padding is considered. + // Remaining Space priority, Foreground padding, foreground visual, Text padding then Text visual. + + Size remainingSpaceForText = Size::ZERO; + remainingSpaceForText.width = size.width - visualAndPaddingSize.width - labelVisualPadding.x - labelVisualPadding.y; + remainingSpaceForText.height = size.height - visualAndPaddingSize.height - labelVisualPadding.width - labelVisualPadding.height; + + if ( !currentVisual ) + { + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Only Text\n"); + + // Center Text if no foreground visual + Size labelNaturalSize = Vector2( mLabel.GetNaturalSize() ); + + // A Text visual will take up all the remainingSpaceForText, for now TextLabel natural size needed for positioning. + labelPosition.x = labelVisualPadding.left + remainingSpaceForText.width*0.5 - labelNaturalSize.width *0.5; + labelPosition.y = labelVisualPadding.height + remainingSpaceForText.height*0.5 - labelNaturalSize.height *0.5; + } + + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout text Size(%f,%f) text Position(%f,%f) \n", remainingSpaceForText.width, remainingSpaceForText.height, labelPosition.x, labelPosition.y); + + mLabel.SetPosition( labelPosition.x, labelPosition.y ); + container.Add( mLabel, remainingSpaceForText ); // Currently a TextLabel is used and size can not be set here. + } + + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout << \n"); } -Button::ButtonState Button::GetState() +void Button::OnTap(Actor actor, const TapGesture& tap) { - return mState; + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnTap\n" ); } -Button::PaintState Button::GetPaintState() +void Button::SetUpTimer( float delay ) { - return mPaintState; + mAutoRepeatingTimer = Dali::Timer::New( static_cast( 1000.f * delay ) ); + mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot ); + mAutoRepeatingTimer.Start(); } -void Button::PrepareAddButtonImage( Actor& actor ) +bool Button::AutoRepeatingSlot() { - if( actor ) + bool consumed = false; + if( !IsDisabled() ) { - Self().Add( actor ); - PrepareForTranstionOut( actor ); - } + // Restart the autorepeat timer. + SetUpTimer( mNextAutoRepeatingDelay ); + + Pressed(); + + Toolkit::Button handle( GetOwner() ); + + //Emit signal. + consumed = mReleasedSignal.Emit( handle ); + consumed = mClickedSignal.Emit( handle ); + consumed |= mPressedSignal.Emit( handle ); + } + + return consumed; } -void Button::TransitionButtonImage( Actor& actor ) +void Button::Pressed() { - if( actor ) - { - if( !actor.GetParent() ) - { - Self().Add( actor ); - } + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Pressed\n" ); - OnTransitionIn( actor ); + if( mButtonState == UNSELECTED_STATE ) + { + ClearTransitionAnimation(); + ChangeState( SELECTED_STATE ); + OnPressed(); // Notifies the derived class the button has been pressed. } } -void Button::AddButtonImage( Actor& actor ) +void Button::Released() { - if( actor ) + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Released\n" ); + + if( mButtonState == SELECTED_STATE && !mTogglableButton ) { - Self().Add( actor ); + ClearTransitionAnimation(); + ChangeState( UNSELECTED_STATE ); + OnReleased(); // // Notifies the derived class the button has been released. } + mButtonPressedState = UNPRESSED; } -void Button::ReAddLabel() +Button::PressState Button::GetPressedState() { - if( mLabel ) - { - mLabel.Unparent(); - Self().Add( mLabel ); - } + return mButtonPressedState; } -void Button::RemoveButtonImage( Actor& actor ) +Button::State Button::GetButtonState() { - if( actor ) - { - if( actor.GetParent() ) - { - Self().Remove( actor ); - } - PrepareForTranstionIn( actor ); - } + return mButtonState; } -unsigned int Button::FindChildIndex( Actor& actor ) +void Button::SelectRequiredVisual( Property::Index visualIndex ) { - Actor self = Self(); - unsigned int childrenNum = self.GetChildCount(); + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SelectRequiredVisual index(%d) state(%d)\n", visualIndex, mButtonState ); - for( unsigned int i = 0; i < childrenNum; i++ ) - { - Actor child = self.GetChildAt( i ); - if( child == actor ) - { - return i; - } - } + EnableVisual( visualIndex, true ); +} + +void Button::TransitionButtonVisualOut( Property::Index visualIndex ) +{ + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::TransitionButtonVisualOut index(%d)\n", visualIndex); - return childrenNum; + // PrepareForTranstionOut and OnTransitionOut needs to be called on visual instead of Actor once animating is possible } -void Button::TransitionOut( Actor actor ) +void Button::TransitionButtonVisualIn( Property::Index visualIndex ) { - OnTransitionOut( actor ); + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::TransitionButtonVisualIn index(%d)\n", visualIndex ); } -void Button::ResetImageLayers() +void Button::OnTransitionIn( Actor actor ) { - // Ensure that all layers are in the correct order and state according to the paint state + PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval +} - switch( mPaintState ) - { - case UnselectedState: - { - //Layer Order - //(2) mUnselectedContent - //(1) mBackgroundContent - - RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] ); - RemoveButtonImage( mSelectedContent ); - RemoveButtonImage( mSelectedBackgroundContent ); - RemoveButtonImage( mDisabledContent ); - RemoveButtonImage( mDisabledSelectedContent ); - RemoveButtonImage( mDisabledBackgroundContent ); - - PrepareAddButtonImage( mBackgroundContent ); - PrepareAddButtonImage( mUnselectedContent ); - - PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - ReAddLabel(); - break; - } - case SelectedState: - { - //Layer Order - //(3) mSelectedContent - //(2) mSelectedBackgroundContent - //(1) mBackgroundContent - - RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - RemoveButtonImage( mUnselectedContent ); - RemoveButtonImage( mDisabledContent ); - RemoveButtonImage( mDisabledSelectedContent ); - RemoveButtonImage( mDisabledBackgroundContent ); - - PrepareAddButtonImage( mBackgroundContent ); - PrepareAddButtonImage( mSelectedBackgroundContent ); - PrepareAddButtonImage( mSelectedContent ); - - PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] ); - ReAddLabel(); - break; - } - case DisabledUnselectedState: - { - //Layer Order - //(2) mDisabledContent - //(1) mDisabledBackgroundContent - - RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - RemoveButtonImage( mUnselectedContent ); - RemoveButtonImage( mBackgroundContent ); - RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] ); - RemoveButtonImage( mSelectedContent ); - RemoveButtonImage( mDisabledSelectedContent ); - RemoveButtonImage( mSelectedBackgroundContent ); - - PrepareAddButtonImage( mDisabledBackgroundContent ? mDisabledBackgroundContent : mBackgroundContent ); - PrepareAddButtonImage( mDisabledContent ? mDisabledContent : mUnselectedContent ); - - PrepareAddButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - ReAddLabel(); - break; - } - case DisabledSelectedState: - { - //Layer Order - // (2) mDisabledSelectedContent - // (1) mDisabledBackgroundContent - - RemoveButtonImage( mDecoration[ UNSELECTED_DECORATION ] ); - RemoveButtonImage( mUnselectedContent ); - RemoveButtonImage( mDecoration[ SELECTED_DECORATION ] ); - RemoveButtonImage( mSelectedContent ); - RemoveButtonImage( mBackgroundContent ); - RemoveButtonImage( mSelectedBackgroundContent ); - RemoveButtonImage( mDisabledContent ); - - if( mDisabledBackgroundContent ) - { - PrepareAddButtonImage( mDisabledBackgroundContent ); - } - else - { - PrepareAddButtonImage( mBackgroundContent ); - PrepareAddButtonImage( mSelectedBackgroundContent ); - } +void Button::RemoveVisual( Property::Index visualIndex ) +{ + // Use OnButtonVisualRemoval if want button developer to have the option to override removal. + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::RemoveVisual index(%d) state(%d)\n", visualIndex, mButtonState ); - PrepareAddButtonImage( mDisabledSelectedContent ? mDisabledSelectedContent : mSelectedContent ); + Toolkit::Visual::Base visual = GetVisual( visualIndex ); - PrepareAddButtonImage( mDecoration[ SELECTED_DECORATION ] ); - ReAddLabel(); - break; - } + if( visual ) + { + EnableVisual( visualIndex, false ); } } +void Button::OnButtonVisualRemoval( Property::Index visualIndex ) +{ + // Derived Buttons can over ride this to prevent default removal. + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnButtonVisualRemoval index(%d)\n", visualIndex ); + RemoveVisual( visualIndex ); +} + void Button::StartTransitionAnimation() { if( mTransitionAnimation ) { + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::StartTransitionAnimation progress(%f) duration(%f) state(%d) \n", + mTransitionAnimation.GetCurrentProgress(), mTransitionAnimation.GetDuration(), + mTransitionAnimation.GetState()); mTransitionAnimation.Play(); } - else - { - ResetImageLayers(); - } } -void Button::StopTransitionAnimation() +void Button::ClearTransitionAnimation() { if( mTransitionAnimation ) { + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ClearTransitionAnimation progress(%f) duration(%f) state(%d) \n", + mTransitionAnimation.GetCurrentProgress(), mTransitionAnimation.GetDuration(), + mTransitionAnimation.GetState()); mTransitionAnimation.Clear(); mTransitionAnimation.Reset(); } @@ -1332,14 +1159,17 @@ Dali::Animation Button::GetTransitionAnimation() void Button::TransitionAnimationFinished( Dali::Animation& source ) { - StopTransitionAnimation(); - ResetImageLayers(); + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::TransitionAnimationFinished\n" ); + ClearTransitionAnimation(); + PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval } void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) { Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) ); + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty index[%d]\n", index ); + if ( button ) { switch ( index ) @@ -1380,39 +1210,59 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope break; } - case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: + case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: // Legacy Tizen 3.0 { - GetImplementation( button ).SetUnselectedImage( value.Get< std::string >() ); + GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, value, DepthIndex::CONTENT ); break; } - - case Toolkit::Button::Property::SELECTED_STATE_IMAGE: + case Toolkit::Button::Property::DISABLED_STATE_IMAGE: // Legacy Tizen 3.0 + { + GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, value, DepthIndex::CONTENT ); + break; + } + case Toolkit::Button::Property::SELECTED_STATE_IMAGE: // Legacy Tizen 3.0 { - GetImplementation( button ).SetSelectedImage( value.Get< std::string >() ); + GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, value, DepthIndex::CONTENT ); + break; + } + case Toolkit::Button::Property::UNSELECTED_VISUAL: + case Toolkit::Button::Property::SELECTED_VISUAL: + case Toolkit::Button::Property::DISABLED_SELECTED_VISUAL: + case Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL: + { + GetImplementation( button ).CreateVisualsForComponent( index, value, DepthIndex::CONTENT ); break; } - case Toolkit::Button::Property::DISABLED_STATE_IMAGE: + case Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL: + case Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL: + case Toolkit::Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL: + case Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL: { - GetImplementation( button ).SetDisabledImage( value.Get< std::string >() ); + GetImplementation( button ).CreateVisualsForComponent( index , value, DepthIndex::BACKGROUND); break; } case Toolkit::Button::Property::UNSELECTED_COLOR: { - GetImplementation( button ).SetColor( value.Get< Vector4 >(), UnselectedState ); + DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::UNSELECTED_COLOR instead use Button::Property::UNSELECTED_BACKGROUND_VISUAL\n", __FUNCTION__); + GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL ); break; } case Toolkit::Button::Property::SELECTED_COLOR: { - GetImplementation( button ).SetColor( value.Get< Vector4 >(), SelectedState ); + DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::SELECTED_COLOR instead use Button::Property::SELECTED_BACKGROUND_VISUAL\n", __FUNCTION__); + GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL ); break; } case Toolkit::Button::Property::LABEL_TEXT: { - GetImplementation( button ).SetLabelText( value.Get< std::string >() ); + DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::LABEL_TEXT instead use Button::Property::LABEL\n", __FUNCTION__); + Property::Map labelTextProperty; + labelTextProperty.Insert( "text", value.Get< std::string >() ); + GetImplementation( button ).SetupLabel( labelTextProperty ); break; } @@ -1422,10 +1272,27 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope Property::Map setPropertyMap; if( value.Get( setPropertyMap ) ) { - GetImplementation( button ).ModifyLabel( setPropertyMap ); + GetImplementation( button ).SetupLabel( setPropertyMap ); } + break; + } + + case Toolkit::Button::Property::LABEL_STRUT_LENGTH: + { + GetImplementation( button ).SetLabelStrutLength( value.Get< int >() ); + break; + } + + case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT: + { + Button::Align labelAlignment(END); + Scripting::GetEnumeration< Button::Align> ( value.Get< std::string >().c_str(), + ALIGNMENT_TABLE, ALIGNMENT_TABLE_COUNT, + labelAlignment ); + + GetImplementation( button ).SetLabelAlignment( labelAlignment ); + break; } - break; } } } @@ -1442,7 +1309,7 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert { case Toolkit::Button::Property::DISABLED: { - value = GetImplementation( button ).mDisabled; + value = GetImplementation( button ).IsDisabled(); break; } @@ -1472,25 +1339,25 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert case Toolkit::Button::Property::SELECTED: { - value = GetImplementation( button ).mSelected; + value = GetImplementation( button ).IsSelected(); break; } case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: { - value = GetImplementation( button ).GetUnselectedImageFilename(); + value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::UNSELECTED_VISUAL ); break; } case Toolkit::Button::Property::SELECTED_STATE_IMAGE: { - value = GetImplementation( button ).GetSelectedImageFilename(); + value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::SELECTED_VISUAL ); break; } case Toolkit::Button::Property::DISABLED_STATE_IMAGE: { - value = GetImplementation( button ).GetDisabledImageFilename(); + value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL ); break; } @@ -1518,138 +1385,158 @@ Property::Value Button::GetProperty( BaseObject* object, Property::Index propert value = emptyMap; break; } + + case Toolkit::Button::Property::LABEL_STRUT_LENGTH: + { + value = GetImplementation( button ).GetLabelStrutLength(); + break; + } + + case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT: + { + const char* alignment = Scripting::GetEnumerationName< Button::Align >( GetImplementation( button ).GetLabelAlignment(), + ALIGNMENT_STRING_TABLE, + ALIGNMENT_STRING_TABLE_COUNT ); + if( alignment ) + { + value = std::string( alignment ); + } + + break; + } } } return value; } -// Deprecated API +void Button::SetLabelPadding( const Padding& padding) +{ + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetLabelPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.bottom, padding.top ); + mLabelPadding = Padding( padding.left, padding.right, padding.bottom, padding.top ); + RelayoutRequest(); +} -void Button::SetLabel( Actor label ) +Padding Button::GetLabelPadding() { - if( mLabel != label ) - { - if( mLabel && mLabel.GetParent() ) - { - mLabel.GetParent().Remove( mLabel ); - } + return mLabelPadding; +} + +void Button::SetForegroundPadding( const Padding& padding) +{ + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetForegroundPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.bottom, padding.top ); + mForegroundPadding = Padding( padding.left, padding.right, padding.bottom, padding.top ); + RelayoutRequest(); +} - mLabel = label; - mLabel.SetPosition( 0.0f, 0.0f ); +Padding Button::GetForegroundPadding() +{ + return mForegroundPadding; +} - // label should be the top of the button - Self().Add( mLabel ); +//////////////////////////////////////////////////////////////////////// +// Legacy functions from Tizen 2.4 and 3.0 - ResetImageLayers(); - OnLabelSet( true ); +void Button::SetLabel( Actor label ) +{ + if ( label ) + { + Property::Value value =""; + value = label.GetProperty(Toolkit::TextLabel::Property::TEXT); - RelayoutRequest(); + SetLabelText( value.Get() ); } } -void Button::SetButtonImage( Actor image ) +void Button::SetUnselectedImage( const std::string& filename ) { - if( image ) + if( !filename.empty() ) { - StopTransitionAnimation(); - - SetupContent( mUnselectedContent, image ); - - OnUnselectedImageSet(); - RelayoutRequest(); + CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, filename, DepthIndex::CONTENT ); } } -void Button::SetSelectedImage( Actor image ) +void Button::SetBackgroundImage( const std::string& filename ) { - if( image ) + if( !filename.empty() ) { - StopTransitionAnimation(); - - SetupContent( mSelectedContent, image ); - - OnSelectedImageSet(); - RelayoutRequest(); + CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND ); } } -void Button::SetBackgroundImage( Actor image ) +void Button::SetSelectedImage( const std::string& filename ) { - if( image ) + if( !filename.empty() ) { - StopTransitionAnimation(); - - SetupContent( mBackgroundContent, image ); - - OnBackgroundImageSet(); - RelayoutRequest(); + CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, filename, DepthIndex::CONTENT ); } } -void Button::SetSelectedBackgroundImage( Actor image ) +void Button::SetSelectedBackgroundImage( const std::string& filename ) { - if( image ) + if( !filename.empty() ) { - StopTransitionAnimation(); - - SetupContent( mSelectedBackgroundContent, image ); - - OnSelectedBackgroundImageSet(); - RelayoutRequest(); + CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND ); } } -void Button::SetDisabledImage( Actor image ) +void Button::SetDisabledBackgroundImage( const std::string& filename ) { - if( image ) + if( !filename.empty() ) { - StopTransitionAnimation(); - - SetupContent( mDisabledContent, image ); - - OnDisabledImageSet(); - RelayoutRequest(); + CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND ); } } -void Button::SetDisabledSelectedImage( Actor image ) +void Button::SetDisabledImage( const std::string& filename ) { - if( image ) + if( !filename.empty() ) { - StopTransitionAnimation(); - - SetupContent( mDisabledSelectedContent, image ); - - OnDisabledSelectedImageSet(); - RelayoutRequest(); + CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, filename, DepthIndex::CONTENT ); } } -void Button::SetDisabledBackgroundImage( Actor image ) +void Button::SetDisabledSelectedImage( const std::string& filename ) { - if( image ) + if( !filename.empty() ) { - StopTransitionAnimation(); + CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_SELECTED_VISUAL, filename, DepthIndex::CONTENT ); + } +} - SetupContent( mDisabledBackgroundContent, image ); +std::string Button::GetUrlForImageVisual( Property::Index index ) +{ + Toolkit::Visual::Base visual = GetVisual( index ); + std::string result; - OnDisabledBackgroundImageSet(); - RelayoutRequest(); + if ( visual ) + { + Dali::Property::Map retreivedMap; + visual.CreatePropertyMap( retreivedMap ); + Property::Value* value = retreivedMap.Find( Toolkit::ImageVisual::Property::URL, Property::STRING ); + if ( value ) + { + result = value->Get(); + } } + + return result; } +// Below functions DEPRECATED_1_0.50 - Return empty Actors + Actor Button::GetButtonImage() const { - return mUnselectedContent; + DALI_LOG_WARNING("Button::GetButtonImage @DEPRECATED_1_0.50 Returning empty Actor \n"); + return Actor();; } Actor Button::GetSelectedImage() const { - return mSelectedContent; + DALI_LOG_WARNING("Button::GetSelectedImage @DEPRECATED_1_0.50 Returning empty Actor \n"); + return Actor(); } - } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/buttons/button-impl.h b/dali-toolkit/internal/controls/buttons/button-impl.h index da2557f..96787dc 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.h +++ b/dali-toolkit/internal/controls/buttons/button-impl.h @@ -1,5 +1,5 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_BUTTON_H__ -#define __DALI_TOOLKIT_INTERNAL_BUTTON_H__ +#ifndef DALI_TOOLKIT_INTERNAL_BUTTON_H +#define DALI_TOOLKIT_INTERNAL_BUTTON_H /* * Copyright (c) 2014 Samsung Electronics Co., Ltd. @@ -23,9 +23,14 @@ #include // INTERNAL INCLUDES +#include #include #include +//#if defined(DEBUG_ENABLED) +// Debug::Filter* gLogButtonFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_BUTTON_CONTROL"); +//#endif + namespace Dali { @@ -38,7 +43,16 @@ namespace Internal { /** + * @copydoc Toolkit::Button + * * Button is the base class implementation for all buttons. + * + * @note + * + * All Foreground/Icon visuals expected to be the same size. + * Background visuals will take the size of the control. + * Padding and struts take size precedence over visuals when available space is limited. + * Icon/Foreground visuals take size precedence over Labels when available space is limited. */ class Button : public Control { @@ -46,6 +60,19 @@ class Button : public Control public: /** + * Enum describing the position the text label can be in relation to the control (and foreground/icon) + */ + enum Align + { + BEGIN, // At the start of the control before the foreground/icon + END, // At the end of the control after the foreground/icon + TOP, // At the top of the control above the foreground/icon + BOTTOM // At the bottom of the control below the foreground/icon + }; + +public: + + /** * @copydoc Dali::Toolkit::Button::SetDisabled */ void SetDisabled( bool disabled ); @@ -126,104 +153,76 @@ public: std::string GetLabelText() const; /** - * @copydoc Dali::Toolkit::PushButton::SetUnselectedImage - */ - void SetUnselectedImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetSelectedImage - */ - void SetSelectedImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage - */ - void SetBackgroundImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetSelectedBackgroundImage - */ - void SetSelectedBackgroundImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledImage - */ - void SetDisabledImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage - */ - void SetDisabledSelectedImage( const std::string& filename ); - - /** - * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage + * @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 SetDisabledBackgroundImage( const std::string& filename ); + void SetupLabel( const Property::Map& properties ); /** - * @return The filename used for the button image. + * 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. + * @param[in] attributes The attributes with which to perfrom this action. + * @return true if action has been accepted by this control */ - std::string GetUnselectedImageFilename() const; + static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ); - /** - * @return The filename used for the selected image. - */ - std::string GetSelectedImageFilename() const; +public: // Deprecated API /** - * @return The filename used for the background image. + * @copydoc Dali::Toolkit::Button::SetLabel( Actor label ) */ - std::string GetBackgroundImageFilename() const; + void SetLabel( Actor label ); /** - * @return The filename used for the selected background image. + * @deprecated Sets the unselected image with an url. + * @param[in] image The Actor to use. */ - std::string GetSelectedBackgroundImageFilename() const; + void SetUnselectedImage( const std::string& filename ); /** - * @return The filename used for the disabled button image. + * @deprecated Sets the selected image with an url. + * @param[in] filename The url of the image to use to use. */ - std::string GetDisabledImageFilename() const; + void SetSelectedImage( const std::string& filename ); /** - * @return The filename used for the disabled selected image. + * @deprecated Sets the selected background image with an url. + * @param[in] filename The url of the image to use to use. */ - std::string GetDisabledSelectedImageFilename() const; + void SetSelectedBackgroundImage( const std::string& filename ); /** - * @return The filename used for the disabled background image. + * @deprecated Sets the background image with an url. + * @param[in] filename The url of the image to use to use. */ - std::string GetDisabledBackgroundImageFilename() const; + void SetBackgroundImage( const std::string& filename ); /** - * @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. + * @deprecated Sets the disabled unselected background image with an url. + * @param[in] filename The url of the image to use to use. */ - void ModifyLabel( const Property::Map& properties ); + void SetDisabledBackgroundImage( const std::string& filename ); /** - * 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. - * @param[in] attributes The attributes with which to perfrom this action. - * @return true if action has been accepted by this control + * @deprecated Sets the disabled unselected image with an url. + * @param[in] filename The url of the image to use to use. */ - static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ); - -public: // Deprecated API + void SetDisabledImage( const std::string& filename ); /** - * @copydoc Dali::Toolkit::Button::SetLabel( Actor label ) + * @deprecated Sets the disabled selected image with an url. + * @param[in] filename The url of the image to use to use. */ - void SetLabel( Actor label ); + void SetDisabledSelectedImage( const std::string& filename ); /** * @deprecated Sets the unselected image with an Actor. * @param[in] image The Actor to use. */ - void SetButtonImage( Actor image ); + void SetUnselectedImage( Actor image ); /** * @deprecated Sets the selected image with an Actor. @@ -232,12 +231,6 @@ public: // Deprecated API void SetSelectedImage( Actor image ); /** - * @deprecated Sets the background image with an Actor. - * @param[in] image The Actor to use. - */ - void SetBackgroundImage( Actor image ); - - /** * @deprecated Sets the selected background image with an Actor. * @param[in] image The Actor to use. */ @@ -262,6 +255,14 @@ public: // Deprecated API void SetDisabledBackgroundImage( Actor image ); /** + * @Gets url of a image visual, used by GetProperty but for deprecated Properties + * @param[in] index Visual index of url required + * @return filename for the corresponding visual + */ + std::string GetUrlForImageVisual( Property::Index index ); + + + /** * @copydoc Dali::Toolkit::Button::GetButtonImage */ Actor GetButtonImage() const; @@ -271,33 +272,58 @@ public: // Deprecated API */ Actor GetSelectedImage() const; -protected: +public: - enum ButtonState + /** + * Button's state + */ + enum State { - ButtonUp, ///< The button is up. - ButtonDown, ///< The button is down. + UNSELECTED_STATE, ///< The button is unselected. + SELECTED_STATE, ///< The button is selected. + DISABLED_UNSELECTED_STATE, ///< The button is disabled and unselected. + DISABLED_SELECTED_STATE, ///< The button is disabled and selected. + STATE_COUNT, ///< Number of States }; /** - * Button paint states. + * Enum to distinguish the different style-able components of the button */ - enum PaintState + enum Visuals { - UnselectedState, ///< The button is unselected. - SelectedState, ///< The button is selected. - DisabledUnselectedState, ///< The button is disabled and unselected. - DisabledSelectedState, ///< The button is disabled and selected. + UNSELECTED_FOREGROUND = 0, + SELECTED_FOREGROUND, + DISABLED_SELECTED_FOREGROUND, + DISABLED_UNSELECTED_FOREGROUND, + UNSELECTED_BACKGROUND, + SELECTED_BACKGROUND, + DISABLED_UNSELECTED_BACKGROUND, + DISABLED_SELECTED_BACKGROUND, + VISUALS_COUNT }; /** - * Enum to specify which decoration when getting and setting decorations. + * Enum to list types of visual a state can have. + */ + enum VisualState + { + BACKGROUND = 0, + FOREGROUND, + VISUAL_STATE_COUNT + }; + +protected: + + /** + * Button press state which is not the same as the actual button's state. + * A button can be DEPRESSED but the until released the button state may have not changed, + * For example DEPRESSING a toggle button that is already in the SELECTED state will not change the button state untill released. */ - enum DecorationState + enum PressState { - UNSELECTED_DECORATION = 0, - SELECTED_DECORATION, - DECORATION_STATES + DEPRESSED, ///< The button is up. + UNPRESSED, ///< The button is down. + TOGGLE_DEPRESSED, ///< The button has been pressed down and will stay depressed when released. }; /** @@ -317,37 +343,12 @@ protected: /** * @return A reference to the unselected button image. */ - Actor& GetUnselectedImage(); + Actor GetUnselectedImage(); /** * @return A reference to the selected image. */ - Actor& GetSelectedImage(); - - /** - * @return A reference to the background image. - */ - Actor& GetBackgroundImage(); - - /** - * @return A reference to the selected background image. - */ - Actor& GetSelectedBackgroundImage(); - - /** - * @return A reference to the disabled button image. - */ - Actor& GetDisabledImage(); - - /** - * @return A reference to the disabled selected image. - */ - Actor& GetDisabledSelectedImage(); - - /** - * @return A reference to the disabled background image. - */ - Actor& GetDisabledBackgroundImage(); + Actor GetSelectedImage(); private: @@ -426,7 +427,7 @@ private: /** * This method is called when the \e selected property is changed. */ - virtual void OnSelected() {} + virtual void OnStateChange( State newState ){} /** * This method is called when the \e disabled property is changed. @@ -516,8 +517,27 @@ protected: // From Control * @copydoc Toolkit::Control::OnStageDisconnection() * @note If overridden by deriving button classes, then an up-call to Button::OnStageDisconnection MUST be made at the end. */ - void OnStageDisconnection(); + virtual void OnStageDisconnection(); + + /** + * @copydoc Toolkit::Control::OnStageConnnection() + */ + virtual void OnStageConnection( int depth ); + + /** + * @copydoc Toolkit::Control::GetNaturalSize + */ + virtual Vector3 GetNaturalSize(); + + /** + * @copydoc Toolkit::Control::OnSetResizePolicy + */ + virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ); + /** + * @copydoc Toolkit::Control::OnRelayout + */ + virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ); private: @@ -546,80 +566,154 @@ private: void SetUpTimer( float delay ); /** + * Button has been pressed + */ + void Pressed(); + + /** * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer. */ bool AutoRepeatingSlot(); /** - * Sets the button as selected or unselected. - * @param[in] selected \e selected property value. - * @param[in] emitSignal Emit a signal if this value is \e true. + * Check the requested state is an allowed transition. + * Some states can not be transitioned to from certain states. + * @param[in] requestedState check if can transition to this state + * @return bool true if state change valid */ - void SetSelected( bool selected, bool emitSignal ); + bool ValidateState( State requestedState ); /** - * This method is called when the button is pressed. + * Perform the given function on the visuals in the given state. Can be used to add and remove visuals. + * @param[in] functionPtr pointer to the function to perform an action on a visual + * @param[in] state Visuals in this state will be the target */ - void Pressed(); + void PerformFunctionOnVisualsInState( void(Button::*functionPtr)( Property::Index visualIndex), State state ); /** - * This method is called when the button is released. + * Transition the visual in or out using the set animation + * @param[in] state State to transition in or out */ - void Released(); + void SetVisualsForTransition( State state ); /** - * Used to perform common setup applied to images within button. - * This will replace the current image with the specifed one. - * @param[in] actorToModify The image to replace. - * @param[out] newActor The new image to use. + * Changes the button state when an action occurs on it + * @param[in] requestedState the state to change to */ - void SetupContent( Actor& actorToModify, Actor newActor ); + void ChangeState( State requestedState ); /** - * Gets the unselected content color. - * @return The currently used unselected color. + * @brief Get unselected button color + * @return color as vector4 */ const Vector4 GetUnselectedColor() const; /** + * @brief Get selected button color + * @return color as vector4 + */ + const Vector4 GetSelectedColor() const; + + /** * Sets the color of button in selected or unselected state, if image also supplied this color will be appplied to it. * If no visual exists, it is created. * @param[in] color The color to use. - * @param[in] selectedState The state to apply the color to, SelectedState or DisabledUnselectedState. + * @param[in] visualIndex The Visual to apply the color */ - void SetColor( const Vector4& color, PaintState selectedState ); + void SetColor( const Vector4& color, Property::Index visualIndex ); /** - * Gets the selected content color. - * @return The currently used selected color. + * This method is called when the button is released. */ - const Vector4 GetSelectedColor() const; + void Released(); protected: - ButtonState GetState(); - PaintState GetPaintState(); - void SetDecoration( DecorationState state, Actor actor ); - Actor& GetDecoration( DecorationState state ); + /** + * Set Text Label Padding + * @param[in] padding BEGIN END BOTTOM TOP + */ + void SetLabelPadding( const Padding& padding ); + /** + * Get Text Label padding + * @return Padding + */ + Padding GetLabelPadding(); /** - * Returns the animation to be used for transitioning creating the animation if needed. + * Set Foreground/icon Padding + * @param[in] padding BEGIN END BOTTOM TOP + */ + void SetForegroundPadding( const Padding& padding); + + /** + * Get Foreground padding + * @ return Padding + */ + Padding GetForegroundPadding(); + + /** + * @brief Get the pressed state of the button + * @return ButtonPressedState the state the button is in + */ + PressState GetPressedState(); + + /** + * @brief Get the state of the button + * @return PaintState the state the button is in + */ + State GetButtonState(); + + /** + * @brief Setup the button components for example foregrounds and background + * @param[in] index the index of the visual to set + * @param[in] value the value to set on the component + * @param[in] visualDepth the depth of the visual if overlapping another + */ + void CreateVisualsForComponent( Property::Index index ,const Property::Value& value, const float visualDepth ); + + /** + * Returns the animation to be used for transition, creating the animation if needed. * @return The initialised transition animation. */ Dali::Animation GetTransitionAnimation(); /** + * @brief Set distance between label and foreground/icon, if both present + * @param[in] length length of strut + */ + void SetLabelStrutLength( unsigned int length ); + + /** + * @brief Set the position of the label relative to foreground/icon, if both present + * @param[in] labelAlignment given alignment setting + */ + void SetLabelAlignment( Align labelAlignment); + + /** + * @brief Get set distance between label and foreground/icon visual + * @return length of strut + */ + float GetLabelStrutLength(); + + /** + * @brief Get set alignment of label in relation to foreground/icon + * @return Set alignment value + */ + Align GetLabelAlignment(); + + /** * Prepares the actor to be transitioned in. * @param[in] actor The actor that will be transitioned in. */ - virtual void PrepareForTranstionIn( Actor actor ) {} + virtual void PrepareForTransitionIn( Actor actor ) {} /** * Prepares the actor to be transitioned in. * @param[in] actor The actor that will be transitioned out. */ - virtual void PrepareForTranstionOut( Actor actor ) {} + virtual void PrepareForTransitionOut( Actor actor ) {} /** * Transitions the actor in, allowing derived classes to configure @@ -627,7 +721,7 @@ protected: * Button is in charge of calling Dali::Animation::Play and so derived classes * only need to add the animation. */ - virtual void OnTransitionIn( Actor actor ) {} + virtual void OnTransitionIn( Actor actor ); /** * Transitions the actor out, allowing derived classes to configure @@ -637,6 +731,15 @@ protected: */ virtual void OnTransitionOut( Actor actor ) {} + /** + * Removes the visual from the button (un-staged) + * If the derived button does not want the visual removed then use this virtual function to + * define the required behaviour. + * Can decide to only remove specified visuals via index + */ + virtual void OnButtonVisualRemoval( Property::Index visualIndex ); + + private: /** @@ -646,9 +749,9 @@ private: void StartTransitionAnimation(); /** - * This method stops all transition animations + * This method stops and clears animations */ - void StopTransitionAnimation(); + void ClearTransitionAnimation(); /** * Called when the transition animation finishes. @@ -656,50 +759,26 @@ private: void TransitionAnimationFinished( Dali::Animation& source ); /** - * Resets the Button to the base state for the current paint state. - * Any additionally inserted images needed for transitions that are - * no longer needed and the removed. - */ - void ResetImageLayers(); - - /** - * Transitions out the actor - */ - void TransitionOut( Actor actor ); - - /** - * Removes the actor from the button and prepares it to be transitioned out - */ - void RemoveButtonImage( Actor& actor ); - - /** - * Finds the index of the actor. - * If the actor doesn't exist, return the last index + 1. + * Transition button visual using an animation before removal from Stage */ - unsigned int FindChildIndex( Actor& actor ); + void TransitionButtonVisualOut( Property::Index visualIndex ); /** - * Adds an actor to the hierarchy and prepares it to be transitioned. - * @param[in] actor The actor to add + * Transition button visual using an animation before adding to Stage */ - void PrepareAddButtonImage( Actor& actor ); + void TransitionButtonVisualIn( Property::Index visualIndex ); /** - * Adds an actor to the hierarchy and marks it to be transitioned. - * @param[in] actor The actor to add + * Removes the visual from the button and prepares it to be transitioned out + * @param[in] visualIndex the visual to remove */ - void TransitionButtonImage( Actor& actor ); + void RemoveVisual( Property::Index visualIndex ); /** - * Adds an actor to the hierarchy. - * @param[in] actor The actor to add + * Adds the required visual to the button. + * @param[in] visualIndex The Property index of the visual required */ - void AddButtonImage( Actor& actor ); - - /** - * (Re)Adds the label (if exists) to the hierarchy (so it is always on top). - */ - void ReAddLabel(); + void SelectRequiredVisual( Property::Index visualIndex ); // Undefined Button( const Button& ); @@ -715,41 +794,35 @@ private: Toolkit::Button::ButtonSignalType mClickedSignal; ///< Signal emitted when the button is clicked. Toolkit::Button::ButtonSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed. - Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property. - - Actor mLabel; ///< Stores the button label. + Timer mAutoRepeatingTimer; - Actor mDecoration[ DECORATION_STATES ]; ///< Stores the decorations for both selected and unselected states. + Actor mLabel; ///< Stores the button text label. + Padding mLabelPadding; ///< The padding around the label (if present). + Padding mForegroundPadding; ///< The padding around the foreground/icon visual (if present). - Actor mUnselectedContent; ///< Stores the unselected content. - Actor mSelectedContent; ///< Stores the selected content. - Actor mBackgroundContent; ///< Stores the background content. - Actor mSelectedBackgroundContent; ///< Stores the selected background content. - Actor mDisabledContent; ///< Stores the disabled content. - Actor mDisabledSelectedContent; ///< Stores the disabled selected content. - Actor mDisabledBackgroundContent; ///< Stores the disabled background content. + unsigned int mForeGroundToLabelStrutLength; ///< Distance between foreground/icon and label. + Align mTextLabelAlignment; ///< Position of text label in relation to foreground/icon when both are present. - Animation mTransitionAnimation; ///< Animation used in the state transitions. + Animation mTransitionAnimation; ///< Used in the state transitions. TapGestureDetector mTapDetector; - Vector4 mUnselectedColor; ///< Color to use for unselected content. - Vector4 mSelectedColor; ///< Color to use for selected content. + Vector4 mUnselectedColor; + Vector4 mSelectedColor; - bool mDisabled; ///< Stores the disabled property. - bool mAutoRepeating; ///< Stores the autorepeating property. - bool mTogglableButton; ///< Stores the togglable property. - bool mSelected; ///< Stores the selected state. - float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds. - float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds. + bool mAutoRepeating; ///< Stores the autorepeating property. + bool mTogglableButton; ///< Stores the togglable property as a flag. + float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds. + float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds. - float mAnimationTime; ///< The animation time. + float mAnimationTime; - // Actions - bool mClickActionPerforming; + PressState mButtonPressedState; ///< In relation to the button being pressed/released + State mButtonState; + State mPreviousButtonState; ///< During a transition between two states, this stores the previous state so Visuals can be removed. - ButtonState mState; ///< Stores the button state. - PaintState mPaintState; ///< Stores the paint state. + // Actions + bool mClickActionPerforming; ///< Used to manage signal emissions during action }; } // namespace Internal @@ -778,4 +851,4 @@ inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button } // namespace Dali -#endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__ +#endif // DALI_TOOLKIT_INTERNAL_BUTTON_H diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp index 5bf5344..b8907f0 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp @@ -19,6 +19,7 @@ #include "check-box-button-impl.h" // EXTERNAL INCLUDES +#include #include #include @@ -28,6 +29,10 @@ #include #include +#if defined(DEBUG_ENABLED) + extern Debug::Filter* gLogButtonFilter; +#endif + namespace Dali { @@ -40,8 +45,7 @@ namespace Internal namespace { -const float DISTANCE_BETWEEN_IMAGE_AND_LABEL( 5.0f ); -const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time +const float ANIMATION_TIME( 0.26f ); // EFL checkbox tick time - Will be replaced by stylable tranisitions BaseHandle Create() { @@ -50,10 +54,8 @@ BaseHandle Create() TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create ); -const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-unselected.png"; -const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-selected.png"; -const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-unselected-disabled.png"; -const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "checkbox-selected-diabled.png"; + + } Dali::Toolkit::CheckBoxButton CheckBoxButton::New() @@ -83,159 +85,46 @@ CheckBoxButton::~CheckBoxButton() { } -void CheckBoxButton::SetTickUVEffect() +void CheckBoxButton::FadeImageTo( Actor actor , float opacity ) { - Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( mSelectedImage ); - if( imageView ) + if( actor ) { - imageView.RegisterProperty( "uTextureRect", Vector4(0.f, 0.f, 1.f, 1.f ) ); - imageView.RegisterProperty( "uTopLeft", Vector2::ZERO ); - - Property::Map shaderMap = CreateImageRegionEffect(); - imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, shaderMap ); + Dali::Animation transitionAnimation = GetTransitionAnimation(); - GetImpl( imageView ).SetDepthIndex( DepthIndex::DECORATION ); + if( transitionAnimation ) + { + transitionAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), opacity ); + } } } void CheckBoxButton::OnInitialize() { Button::OnInitialize(); - - // Wrap around all children - Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); - - SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR ); - SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR ); - SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR ); - SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR ); - - mSelectedImage = GetSelectedImage(); - SetTickUVEffect(); } -void CheckBoxButton::OnLabelSet( bool noPadding ) +void CheckBoxButton::PrepareForTransitionIn( Actor actor ) { - Actor& label = GetLabelActor(); - - if( label ) - { - label.SetParentOrigin( ParentOrigin::CENTER_LEFT ); - label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - - if( IsDisabled() && GetDisabledBackgroundImage() ) - { - label.SetX( GetDisabledBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if ( GetBackgroundImage() ) - { - label.SetX( GetBackgroundImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( IsSelected() && GetSelectedImage()) - { - label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( GetUnselectedImage() ) - { - label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else - { - label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - } + // Set Toolkit::Button::Property::SELECTED_VISUAL and Toolkit::Button::Property::UNSELECTED_VISUAL to opacity 0 + // Then get and start animation } -void CheckBoxButton::OnDisabled() +void CheckBoxButton::PrepareForTransitionOut( Actor actor ) { - Actor& backgroundImage = GetBackgroundImage(); - Actor& disabledBackgroundImage = GetDisabledBackgroundImage(); - - Actor& label = GetLabelActor(); - if( label ) - { - if( IsDisabled() && disabledBackgroundImage ) - { - label.SetX( disabledBackgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( backgroundImage ) - { - label.SetX( backgroundImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( IsSelected() && GetSelectedImage()) - { - label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( GetUnselectedImage() ) - { - label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else - { - label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - } -} - -void CheckBoxButton::PrepareForTranstionIn( Actor actor ) -{ - Actor& selectedImage = GetSelectedImage(); - if( actor == selectedImage ) - { - actor.SetScale( Vector3( 0.0f, 1.0f, 1.0f ) ); - actor.RegisterProperty( "uBottomRight", Vector2( 0.0f, 1.0f ) ); - - if( mSelectedImage != selectedImage ) - { - mSelectedImage = selectedImage; - SetTickUVEffect(); - } - } + // Set Toolkit::Button::Property::SELECTED_VISUAL and Toolkit::Button::Property::UNSELECTED_VISUAL to opacity 1 + // Then get and start animation } -void CheckBoxButton::PrepareForTranstionOut( Actor actor ) +void CheckBoxButton::OnTransitionIn( Actor actor ) { - Actor& selectedImage = GetSelectedImage(); - if( actor == selectedImage ) - { - actor.SetScale( Vector3::ONE ); - actor.RegisterProperty( "uBottomRight", Vector2::ONE ); - - if( mSelectedImage != selectedImage ) - { - mSelectedImage = selectedImage; - SetTickUVEffect(); - } - } + // Only transition selected and unselected visual, background doesn't change. + // Start Fade animation to 1 } -void CheckBoxButton::OnTransitionIn( Actor actor ) +void CheckBoxButton::OnTransitionOut( Actor actor ) { - Actor& selectedImage = GetSelectedImage(); - if( actor && actor == selectedImage ) - { - if( GetPaintState() == UnselectedState ) - { - Dali::Animation transitionAnimation = GetTransitionAnimation(); - if( transitionAnimation ) - { - // UV anim - transitionAnimation.AnimateTo( Property( actor, "uBottomRight" ), Vector2::ONE ); - - // Actor size anim - transitionAnimation.AnimateTo( Property( actor, Actor::Property::SCALE_X ), 1.0f ); - } - } - else - { - //explicitly end the swipe animation - actor.SetScale( Vector3::ONE ); - if( mSelectedImage == selectedImage ) - { - actor.RegisterProperty( "uBottomRight", Vector2::ONE ); - } - } - } + // Only transition selected and unselected visual, background doesn't change. + // Start Fade animation to 0 } } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.h b/dali-toolkit/internal/controls/buttons/check-box-button-impl.h index e3d6a46..c283392 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.h @@ -62,11 +62,6 @@ private: */ virtual ~CheckBoxButton(); - /** - * Setup the ticking effect to the selected image. - */ - void SetTickUVEffect(); - private: // From Button @@ -76,29 +71,29 @@ private: // From Button virtual void OnInitialize(); /** - * @copydoc Toolkit::Internal::Button::OnLabelSet + * @copydoc Toolkit::Internal::Button::PrepareForTranstionIn( Actor actor ) */ - virtual void OnLabelSet( bool noPadding ); + virtual void PrepareForTransitionIn( Actor actor ); /** - * @copydoc Toolkit::Internal::Button::OnDisabled + * @copydoc Toolkit::Internal::Button::PrepareForTranstionOut( Actor actor ) */ - virtual void OnDisabled(); + virtual void PrepareForTransitionOut( Actor actor ); /** - * @copydoc Toolkit::Internal::Button::PrepareForTranstionIn( Actor actor ) + * @copydoc Toolkit::Internal::Button::OnTransitionInImage( Actor actor ) */ - virtual void PrepareForTranstionIn( Actor actor ); + virtual void OnTransitionIn( Actor actor ); /** - * @copydoc Toolkit::Internal::Button::PrepareForTranstionOut( Actor actor ) + * @copydoc Toolkit::Internal::Button::OnTransitionOut( Actor actor ) */ - virtual void PrepareForTranstionOut( Actor actor ); + virtual void OnTransitionOut( Actor actor ); /** - * @copydoc Toolkit::Internal::Button::OnTransitionInImage( Actor actor ) + * @copydoc Toolkit::Internal::Button::OnButtonVisualRemoval( Property::Index visualIndex ) */ - virtual void OnTransitionIn( Actor actor ); + // virtual void OnButtonVisualRemoval( Property::Index visualIndex ); private: @@ -108,8 +103,6 @@ private: // Undefined CheckBoxButton& operator=( const CheckBoxButton& ); -private: - Actor mSelectedImage; }; } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index 2190016..cb5a747 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -23,10 +23,17 @@ #include #include #include +#include // INTERNAL INCLUDES #include #include +#include +#include + +#if defined(DEBUG_ENABLED) + extern Debug::Filter* gLogButtonFilter; +#endif namespace Dali { @@ -41,8 +48,6 @@ namespace { const float ANIMATION_TIME( 0.2f ); -const Padding DEFAULT_LABEL_PADDING( 12.0f, 12.0f, 12.0f, 12.0f ); -const Padding DEFAULT_ICON_PADDING( 12.0f, 12.0f, 12.0f, 12.0f ); BaseHandle Create() { @@ -71,31 +76,11 @@ const Dali::Scripting::StringEnum IconAlignmentTable[] = { { "BOTTOM", Toolkit::Internal::PushButton::BOTTOM }, }; const unsigned int IconAlignmentTableCount = sizeof( IconAlignmentTable ) / sizeof( IconAlignmentTable[0] ); -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 { -/** - * 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 SizeOfActorIfLarger( Actor root, Vector3& size ) -{ - if ( root ) - { - // 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 ); - } -} - } // unnamed namespace Dali::Toolkit::PushButton PushButton::New() @@ -115,10 +100,7 @@ Dali::Toolkit::PushButton PushButton::New() PushButton::PushButton() : Button(), - mLabelPadding( DEFAULT_LABEL_PADDING ), - mIconPadding( DEFAULT_ICON_PADDING ), - mIconAlignment( RIGHT ), - mSize() + mIconAlignment( RIGHT ) { SetAnimationTime( ANIMATION_TIME ); } @@ -134,32 +116,36 @@ void PushButton::OnInitialize() // Push button requires the Leave event. Actor self = Self(); self.SetLeaveRequired( true ); - - // Set resize policy to natural size so that buttons will resize to background images - self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - - SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR ); - SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR ); - SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR ); - SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR ); -} - -void PushButton::SetIcon( DecorationState state, const std::string iconFilename ) -{ - mIconName[ state ] = iconFilename; - SetDecoration( state, Toolkit::ImageView::New( iconFilename ) ); - ConfigureSizeNegotiation(); -} - -std::string& PushButton::GetIcon( DecorationState state ) -{ - return mIconName[ state ]; } void PushButton::SetIconAlignment( const PushButton::IconAlignment iconAlignment ) { mIconAlignment = iconAlignment; - ConfigureSizeNegotiation(); + Button::Align labelAlignment; + switch ( iconAlignment ) + { + case RIGHT: + { + labelAlignment = Button::BEGIN; + break; + } + case TOP: + { + labelAlignment = Button::BOTTOM; + break; + } + case BOTTOM: + { + labelAlignment = Button::TOP; + break; + } + case LEFT: + default: + labelAlignment = Button::END; + break; + } + + Button::SetLabelAlignment( labelAlignment ); } const PushButton::IconAlignment PushButton::GetIconAlignment() const @@ -167,28 +153,6 @@ const PushButton::IconAlignment PushButton::GetIconAlignment() const return mIconAlignment; } -void PushButton::SetLabelPadding( const Vector4& padding ) -{ - mLabelPadding = Padding( padding.x, padding.y, padding.z, padding.w ); - ConfigureSizeNegotiation(); -} - -Vector4 PushButton::GetLabelPadding() -{ - return Vector4( mLabelPadding.left, mLabelPadding.right, mLabelPadding.top, mLabelPadding.bottom ); -} - -void PushButton::SetIconPadding( const Vector4& padding ) -{ - mIconPadding = Padding( padding.x, padding.y, padding.z, padding.w ); - ConfigureSizeNegotiation(); -} - -Vector4 PushButton::GetIconPadding() -{ - return Vector4( mIconPadding.left, mIconPadding.right, mIconPadding.top, mIconPadding.bottom ); -} - void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value ) { Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( Dali::BaseHandle( object ) ); @@ -197,16 +161,18 @@ void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, { PushButton& pushButtonImpl( GetImplementation( pushButton ) ); + // Properties remain here for Tizen 3.0 legacy requirements. Are now in Button base class + switch ( propertyIndex ) { case Toolkit::PushButton::Property::UNSELECTED_ICON: { - pushButtonImpl.SetIcon( UNSELECTED_DECORATION, value.Get< std::string >() ); + pushButtonImpl.CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, value, DepthIndex::CONTENT ); break; } case Toolkit::PushButton::Property::SELECTED_ICON: { - pushButtonImpl.SetIcon( SELECTED_DECORATION, value.Get< std::string >() ); + pushButtonImpl.CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, value, DepthIndex::CONTENT ); break; } case Toolkit::PushButton::Property::ICON_ALIGNMENT: @@ -220,12 +186,14 @@ void PushButton::SetProperty( BaseObject* object, Property::Index propertyIndex, } case Toolkit::PushButton::Property::LABEL_PADDING: { - pushButtonImpl.SetLabelPadding( value.Get< Vector4 >() ); + Vector4 padding ( value.Get< Vector4 >() ); + pushButtonImpl.Button::SetLabelPadding( Padding( padding.x, padding.y, padding.z, padding.w ) ); break; } case Toolkit::PushButton::Property::ICON_PADDING: { - pushButtonImpl.SetIconPadding( value.Get< Vector4 >() ); + Vector4 padding ( value.Get< Vector4 >() ); + pushButtonImpl.Button::SetForegroundPadding( Padding( padding.x, padding.y, padding.z, padding.w ) ); break; } } @@ -246,12 +214,12 @@ Property::Value PushButton::GetProperty( BaseObject* object, Property::Index pro { case Toolkit::PushButton::Property::UNSELECTED_ICON: { - value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION ); + //value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION ); break; } case Toolkit::PushButton::Property::SELECTED_ICON: { - value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION ); + //value = pushButtonImpl.GetIcon( UNSELECTED_DECORATION ); break; } case Toolkit::PushButton::Property::ICON_ALIGNMENT: @@ -261,12 +229,14 @@ Property::Value PushButton::GetProperty( BaseObject* object, Property::Index pro } case Toolkit::PushButton::Property::LABEL_PADDING: { - value = pushButtonImpl.GetLabelPadding(); + Padding padding = pushButtonImpl.Button::GetLabelPadding(); + value = Vector4( padding.x, padding.y, padding.top, padding.bottom); break; } case Toolkit::PushButton::Property::ICON_PADDING: { - value = pushButtonImpl.GetIconPadding(); + Padding padding = pushButtonImpl.Button::GetForegroundPadding(); + value = Vector4( padding.x, padding.y, padding.top, padding.bottom); break; } } @@ -275,97 +245,31 @@ Property::Value PushButton::GetProperty( BaseObject* object, Property::Index pro return value; } -void PushButton::OnLabelSet( bool noPadding ) -{ - Actor& label = GetLabelActor(); - - if( label ) - { - if( noPadding ) - { - mLabelPadding = Padding( 0.0f, 0.0f, 0.0f, 0.0f ); - } - - Toolkit::TextLabel textLabel = Toolkit::TextLabel::DownCast( label ); - if( textLabel ) - { - textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, false ); - } - } - ConfigureSizeNegotiation(); -} - -void PushButton::OnButtonImageSet() -{ - ConfigureSizeNegotiation(); -} - -void PushButton::OnSelectedImageSet() -{ - ConfigureSizeNegotiation(); -} - -void PushButton::OnBackgroundImageSet() -{ - ConfigureSizeNegotiation(); -} - -void PushButton::OnSelectedBackgroundImageSet() -{ - ConfigureSizeNegotiation(); -} - -void PushButton::OnDisabledImageSet() -{ - ConfigureSizeNegotiation(); -} - -void PushButton::OnDisabledSelectedImageSet() -{ - ConfigureSizeNegotiation(); -} - -void PushButton::OnDisabledBackgroundImageSet() -{ - ConfigureSizeNegotiation(); -} - -void PushButton::OnSizeSet( const Vector3& targetSize ) -{ - if( targetSize != mSize ) - { - mSize = targetSize; - - Actor& label = GetLabelActor(); - - if( label ) - { - label.SetSize( mSize ); - } - } -} - void PushButton::PrepareForTranstionIn( Actor actor ) { - actor.SetOpacity( 0.0f ); + // Set Toolkit::Button::Property::SELECTED_VISUAL and Toolkit::Button::Property::UNSELECTED_VISUAL to opacity 0 + // Then get and start animation } void PushButton::PrepareForTranstionOut( Actor actor ) { - actor.SetOpacity( 1.0f ); + // Set Toolkit::Button::Property::SELECTED_VISUAL and Toolkit::Button::Property::UNSELECTED_VISUAL to opacity 1 + // Then get and start animation } void PushButton::OnTransitionIn( Actor actor ) { - FadeImageTo( actor, 1.f ); + // Only transition selected and unselected visual, background doesn't change. + // Start Fade animation to 1 } void PushButton::OnTransitionOut( Actor actor ) { - FadeImageTo( actor, 0.0f ); + // Only transition selected and unselected visual, background doesn't change. + // Start Fade animation to 0 } -void PushButton::FadeImageTo( Actor actor, float opacity ) +void PushButton::FadeImageTo( Actor actor , float opacity ) { if( actor ) { @@ -374,232 +278,13 @@ void PushButton::FadeImageTo( Actor actor, float opacity ) if( transitionAnimation ) { - transitionAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), opacity ); - } - } -} - -Vector3 PushButton::GetNaturalSize() -{ - Vector3 size; - - // If label, test against it's size - Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabelActor() ); - - Actor icon = GetDecoration( UNSELECTED_DECORATION ); - if( label || icon ) - { - Vector3 labelSize( Vector3::ZERO ); - Vector3 iconSize( Vector3::ZERO ); - - if( label ) - { - Vector3 labelNaturalSize = label.GetNaturalSize(); - labelSize.width = labelNaturalSize.width + mLabelPadding.left + mLabelPadding.right; - labelSize.height = labelNaturalSize.height + mLabelPadding.top + mLabelPadding.bottom; - } - - if( icon ) - { - Vector3 iconNaturalSize = icon.GetNaturalSize(); - iconSize.width = iconNaturalSize.width + mIconPadding.left + mIconPadding.right; - iconSize.height = iconNaturalSize.height + mIconPadding.top + mIconPadding.bottom; - - switch( mIconAlignment ) - { - case LEFT: - case RIGHT: - { - size.width = labelSize.width + iconSize.width; - size.height = std::max( labelSize.height, iconSize.height ); - break; - } - case TOP: - case BOTTOM: - { - size.width = std::max( labelSize.width, iconSize.width ); - size.height = labelSize.height + iconSize.height; - break; - } - } - } - else - { - // No icon, so size is the same as label size. - // (If there is no label this is zero). - size = labelSize; - } - } - else - { - // Check Image and Background image and use the largest size as the control's Natural size. - SizeOfActorIfLarger( GetUnselectedImage(), size ); - SizeOfActorIfLarger( GetBackgroundImage(), size ); - } - - return size; -} - -void PushButton::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) -{ - ConfigureSizeNegotiation(); -} - -void PushButton::ConfigureSizeNegotiation() -{ - std::vector< Actor > images; - images.reserve( 7 ); - - images.push_back( GetUnselectedImage() ); - images.push_back( GetSelectedImage() ); - images.push_back( GetSelectedBackgroundImage() ); - images.push_back( GetBackgroundImage() ); - images.push_back( GetDisabledImage() ); - images.push_back( GetDisabledSelectedImage() ); - images.push_back( GetDisabledBackgroundImage() ); - - Actor label = GetLabelActor(); - - for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i ) - { - ConfigureSizeNegotiationDimension( static_cast< Dimension::Type >( 1 << i ), images, label ); - } - - // Add any vertical padding directly to the actors. - Actor icon = GetDecoration( UNSELECTED_DECORATION ); - Actor selectedIcon = GetDecoration( SELECTED_DECORATION ); - bool iconExists = icon || selectedIcon; - - if( label ) - { - label.SetPadding( mLabelPadding ); - } - if( icon ) - { - icon.SetPadding( mIconPadding ); - } - if( selectedIcon ) - { - selectedIcon.SetPadding( mIconPadding ); - } - - // Calculate and apply horizontal alignments and offsets - // to text and icon (depending on existence). - Vector3 iconPosition( Vector3::ZERO ); - Vector3 labelPosition( Vector3::ZERO ); - Vector3 iconAnchoring( AnchorPoint::CENTER ); - Vector3 labelAnchoring( AnchorPoint::CENTER ); - std::string horizontalLabelAlignment = "CENTER"; - std::string verticalLabelAlignment = "CENTER"; - - if( iconExists && label ) - { - // There is an icon and a label to lay out. - switch( mIconAlignment ) - { - case LEFT: - { - iconPosition.x = mIconPadding.left; - labelPosition.x = -mLabelPadding.right; - iconAnchoring = AnchorPoint::CENTER_LEFT; - labelAnchoring = AnchorPoint::CENTER_RIGHT; - horizontalLabelAlignment = "END"; - break; - } - case RIGHT: - { - iconPosition.x = -mIconPadding.right; - labelPosition.x = mLabelPadding.left; - iconAnchoring = AnchorPoint::CENTER_RIGHT; - labelAnchoring = AnchorPoint::CENTER_LEFT; - horizontalLabelAlignment = "BEGIN"; - break; - } - case TOP: - { - iconPosition.y = mIconPadding.top; - labelPosition.y = -mLabelPadding.bottom; - iconAnchoring = AnchorPoint::TOP_CENTER; - labelAnchoring = AnchorPoint::BOTTOM_CENTER; - verticalLabelAlignment = "BOTTOM"; - break; - } - case BOTTOM: - { - iconPosition.y = -mIconPadding.bottom; - labelPosition.y = mLabelPadding.top; - iconAnchoring = AnchorPoint::BOTTOM_CENTER; - labelAnchoring = AnchorPoint::TOP_CENTER; - verticalLabelAlignment = "TOP"; - break; - } - } - } + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "PushButton::FadeImageTo(%f)\n", opacity ); - // Note: If there is only an icon, or only a label, the default values are now correct. - // Setup the icon(s) with the precalculated values. - if( icon ) - { - icon.SetPosition( iconPosition ); - icon.SetParentOrigin( iconAnchoring ); - icon.SetAnchorPoint( iconAnchoring ); - } - if( selectedIcon ) - { - selectedIcon.SetPosition( iconPosition ); - selectedIcon.SetParentOrigin( iconAnchoring ); - selectedIcon.SetAnchorPoint( iconAnchoring ); - } - - // Setup the label. - if( label ) - { - label.SetPosition( labelPosition ); - label.SetParentOrigin( labelAnchoring ); - label.SetAnchorPoint( labelAnchoring ); - label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, horizontalLabelAlignment ); - label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, verticalLabelAlignment ); - } - - RelayoutRequest(); -} - - -void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label ) -{ - ResizePolicy::Type imageResizePolicy = ResizePolicy::FILL_TO_PARENT; - ResizePolicy::Type labelResizePolicy = ResizePolicy::FILL_TO_PARENT; - - ResizePolicy::Type resizePolicy = Self().GetResizePolicy( dimension ); - - if( resizePolicy == ResizePolicy::FIT_TO_CHILDREN || resizePolicy == ResizePolicy::USE_NATURAL_SIZE ) - { - if( label ) - { - labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE; - } - else - { - imageResizePolicy = ResizePolicy::USE_NATURAL_SIZE; - } - } - - if( label ) - { - label.SetResizePolicy( labelResizePolicy, dimension ); - } - - for( std::vector< Actor >::const_iterator it = images.begin(), itEnd = images.end(); it != itEnd; ++it ) - { - Actor actor = *it; - if( actor ) - { - actor.SetResizePolicy( imageResizePolicy, dimension ); + transitionAnimation.AnimateTo( Property( actor, Actor::Property::COLOR_ALPHA ), opacity ); } } } - } // namespace Internal } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.h b/dali-toolkit/internal/controls/buttons/push-button-impl.h index a003e6d..990acf0 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.h @@ -101,46 +101,6 @@ private: // From Button virtual void OnInitialize(); /** - * @copydoc Toolkit::Internal::Button::OnLabelSet - */ - virtual void OnLabelSet( bool noPadding ); - - /** - * @copydoc Toolkit::Internal::Button::OnButtonImageSet - */ - virtual void OnButtonImageSet(); - - /** - * @copydoc Toolkit::Internal::Button::OnSelectedImageSet - */ - virtual void OnSelectedImageSet(); - - /** - * @copydoc Toolkit::Internal::Button::OnBackgroundImage - */ - virtual void OnBackgroundImageSet(); - - /** - * @copydoc Toolkit::Internal::Button::OnSelectedBackgroundImageSet - */ - virtual void OnSelectedBackgroundImageSet(); - - /** - * @copydoc Toolkit::Internal::Button::OnDisabledImageSet - */ - virtual void OnDisabledImageSet(); - - /** - * @copydoc Toolkit::Internal::Button::OnDisabledSelectedImageSet - */ - virtual void OnDisabledSelectedImageSet(); - - /** - * @copydoc Toolkit::Internal::Button::OnDisabledBackgroundImageSet - */ - virtual void OnDisabledBackgroundImageSet(); - - /** * @copydoc Toolkit::Internal::Button::PrepareForTranstionIn( Actor actor ) */ virtual void PrepareForTranstionIn( Actor actor ); @@ -151,72 +111,19 @@ private: // From Button virtual void PrepareForTranstionOut( Actor actor ); /** - * @copydoc Toolkit::Internal::Button::OnTransitionIn( Actor actor ) + * @copydoc Toolkit::Internal::Button::OnTransitionIn( Toolkit::Visual::Base& visual ) */ virtual void OnTransitionIn( Actor actor ); /** - * @copydoc Toolkit::Internal::Button::OnTransitionOut( Actor actor ) + * @copydoc Toolkit::Internal::Button::OnTransitionOut( Toolkit::Visual::Base& visual ) */ virtual void OnTransitionOut( Actor actor ); -private: // From Control - - /** - * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize ) - */ - virtual void OnSizeSet( const Vector3& targetSize ); - - /** - * @copydoc Toolkit::Control::GetNaturalSize - */ - virtual Vector3 GetNaturalSize(); - - /** - * @copydoc Toolkit::Control::OnSetResizePolicy - */ - virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ); private: /** - * It adds the actor to the root actor and to the fade in animation. - * @param[inout] actor The actor. - * @param[in] opacity The opacity to fade to - */ - void FadeImageTo( Actor actor, float opacity ); - - /** - * @brief Custom configuration for size negotiation - */ - void ConfigureSizeNegotiation(); - - /** - * @brief Configure size negotiation for a given dimension - * - * @param[in] dimension The dimension to configure - * @param[in] images The list of images to configure - * @param[in] label The text label to configure - */ - void ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label ); - - /** - * @brief Sets either the selected or unselected icon. - * - * @param[in] state The icon state to set - * @param[in] iconFilename The filename of the icon - */ - void SetIcon( DecorationState state, const std::string iconFilename ); - - /** - * @brief Gets either the selected or unselected icon. - * - * @param[in] state The icon state to get - * @return The filename of the icon - */ - std::string& GetIcon( DecorationState state ); - - /** * @brief Sets the alignment mode to use to align the icon to the label. * * @param[in] iconAlignment The alignment mode to use @@ -230,34 +137,6 @@ private: */ const PushButton::IconAlignment GetIconAlignment() const; - /** - * @brief Sets the padding for the label. - * - * @param[in] padding The padding to set - */ - void SetLabelPadding( const Vector4& padding ); - - /** - * @brief Gets the padding for the label. - * - * @return The label padding - */ - Vector4 GetLabelPadding(); - - /** - * @brief Sets the padding for the icon. - * - * @param[in] padding The padding to set - */ - void SetIconPadding( const Vector4& padding ); - - /** - * @brief Gets the padding for the icon. - * - * @return The icon padding - */ - Vector4 GetIconPadding(); - private: // Undefined @@ -268,11 +147,7 @@ private: private: - std::string mIconName[ DECORATION_STATES ]; ///< The original filenames for the icons. - Padding mLabelPadding; ///< The padding around the label (if present). - Padding mIconPadding; ///< The padding around the icon (if present). IconAlignment mIconAlignment; ///< The alignment of the icon against the label. - Vector3 mSize; ///< The button's size. }; } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp index 142dba1..c20fe23 100644 --- a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp @@ -20,9 +20,14 @@ #include "radio-button-impl.h" // EXTERNAL INCLUDES +#include #include #include +#if defined(DEBUG_ENABLED) + extern Debug::Filter* gLogButtonFilter; +#endif + namespace Dali { @@ -42,12 +47,6 @@ BaseHandle Create() TypeRegistration typeRegistration( typeid( Toolkit::RadioButton ), typeid( Toolkit::Button ), Create); -const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-unselected.png"; -const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-selected.png"; -const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-unselected-disabled.png"; -const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-selected-disabled.png"; - -const float DISTANCE_BETWEEN_IMAGE_AND_LABEL( 5.0f ); } Dali::Toolkit::RadioButton RadioButton::New() @@ -77,105 +76,47 @@ RadioButton::~RadioButton() void RadioButton::OnInitialize() { Button::OnInitialize(); - - Actor self = Self(); - - // Wrap size of radio button around all its children - self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); - - SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR ); - SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR ); - SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR ); - SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR ); - - RelayoutRequest(); } void RadioButton::OnButtonUp() { - if( ButtonDown == GetState() ) - { - // Don't allow selection on an already selected radio button - if( !IsSelected() ) - { - SetSelected( !IsSelected() ); - } - } -} - -void RadioButton::OnLabelSet( bool noPadding ) -{ - Actor& label = GetLabelActor(); + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "RadioButton::OnStateChange selecting:%s\n", ( (!IsSelected())?"true":"false" ) ); - if( label ) + // Don't allow un-selection on an already selected radio button, can only un-select by selecting a sibling radio button + if( !IsSelected() ) { - label.SetParentOrigin( ParentOrigin::CENTER_LEFT ); - label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - - // Radio button width is FIT_TO_CHILDREN, so the label must have a sensible policy to fill out the space - if( label.GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::FILL_TO_PARENT ) - { - label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); - } - - if( IsSelected() && GetSelectedImage() ) - { - label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else if( GetUnselectedImage() ) - { - label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - else - { - label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } + SetSelected( !IsSelected() ); } } -void RadioButton::OnSelected() +void RadioButton::OnStateChange( State newState ) { - Actor& label = GetLabelActor(); - - PaintState paintState = GetPaintState(); - switch( paintState ) - { - case UnselectedState: - { - Actor parent = Self().GetParent(); - if( parent ) - { - for( unsigned int i = 0; i < parent.GetChildCount(); ++i ) - { - Dali::Toolkit::RadioButton radioButtonChild = Dali::Toolkit::RadioButton::DownCast( parent.GetChildAt( i ) ); - if( radioButtonChild && radioButtonChild != Self() ) - { - radioButtonChild.SetSelected( false ); - } - } - } - - Actor& selectedImage = GetSelectedImage(); - if( label && selectedImage ) - { - label.SetX( selectedImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - break; - } - case SelectedState: - { - Actor& buttonImage = GetUnselectedImage(); - if( label && buttonImage ) - { - label.SetX( buttonImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - } - break; - } - default: - { - break; - } - } + // Radio button can be part of a group, if a button in the group is selected then all others should be unselected + DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "RadioButton::OnStateChange state(%d)\n", newState ); + + switch( newState ) + { + case SELECTED_STATE: + { + Actor parent = Self().GetParent(); + if( parent ) + { + for( unsigned int i = 0; i < parent.GetChildCount(); ++i ) + { + Dali::Toolkit::RadioButton radioButtonChild = Dali::Toolkit::RadioButton::DownCast( parent.GetChildAt( i ) ); + if( radioButtonChild && radioButtonChild != Self() ) + { + radioButtonChild.SetSelected( false ); + } + } + } + } + + default: + { + break; + } + } } } // namespace Internal diff --git a/dali-toolkit/internal/controls/buttons/radio-button-impl.h b/dali-toolkit/internal/controls/buttons/radio-button-impl.h index 630e1a3..ca5ba20 100644 --- a/dali-toolkit/internal/controls/buttons/radio-button-impl.h +++ b/dali-toolkit/internal/controls/buttons/radio-button-impl.h @@ -69,19 +69,15 @@ private: // From Button virtual void OnInitialize(); /** - * @copydoc Toolkit::Internal::Button::OnButtonUp + * @copydoc Toolkit::Internal::Button::OnStateChange */ - virtual void OnButtonUp(); + virtual void OnStateChange( State newState ); /** - * @copydoc Toolkit::Internal::Button::OnSelected + * @copydoc Toolkit::Internal::Button::OnButtonUp */ - virtual void OnSelected(); + virtual void OnButtonUp(); - /** - * @copydoc Toolkit::Internal::Button::OnLabelSet - */ - virtual void OnLabelSet( bool noPadding ); private: diff --git a/dali-toolkit/public-api/controls/buttons/button.cpp b/dali-toolkit/public-api/controls/buttons/button.cpp index 783e1e6..9f02049 100644 --- a/dali-toolkit/public-api/controls/buttons/button.cpp +++ b/dali-toolkit/public-api/controls/buttons/button.cpp @@ -20,6 +20,8 @@ // EXTERNAL INCLUDES #include +#include +#include // INTERNAL INCLUDES #include @@ -251,18 +253,32 @@ void Button::SetButtonImage( Image image ) { DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetButtonImage() is deprecated and will be removed from next release. Use Styling file instead.\n" ); - Actor imageView = Toolkit::ImageView::New( image ); - imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - Dali::Toolkit::GetImplementation( *this ).SetButtonImage( imageView ); + Dali::ResourceImage resourceImage = Dali::ResourceImage::DownCast( image ); + + std::string imageUrl; + + if ( resourceImage ) + { + imageUrl = resourceImage.GetUrl(); + } + + Dali::Toolkit::GetImplementation( *this ).SetUnselectedImage( imageUrl ); } void Button::SetSelectedImage( Image image ) { DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetSelectedImage() is deprecated and will be removed from next release. Use Styling file instead.\n" ); - Actor imageView = Toolkit::ImageView::New( image ); - imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( imageView ); + Dali::ResourceImage resourceImage = Dali::ResourceImage::DownCast( image ); + + std::string imageUrl; + + if ( resourceImage ) + { + imageUrl = resourceImage.GetUrl(); + } + + Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( imageUrl ); } Actor Button::GetButtonImage() const @@ -279,7 +295,6 @@ Actor Button::GetSelectedImage() const return Dali::Toolkit::GetImplementation( *this ).GetSelectedImage(); } - Button::Button( Internal::Button& implementation ) : Control( implementation ) { diff --git a/dali-toolkit/public-api/controls/buttons/button.h b/dali-toolkit/public-api/controls/buttons/button.h index dbb0618..3b649d1 100644 --- a/dali-toolkit/public-api/controls/buttons/button.h +++ b/dali-toolkit/public-api/controls/buttons/button.h @@ -37,7 +37,7 @@ class Button; */ /** - * @brief Button is a base class for different kind of buttons. + * @brief Button is a base class for different kinds of buttons. * * This class provides the disabled property and the clicked signal. * @@ -59,14 +59,47 @@ class Button; * When \e togglable is set to \e true, a Button::StateChangedSignal() signal is emitted, with the selected state. * * - * The button's appearance can be modified by setting properties for the various image filenames. + * 'Visual' describes not just traditional images like png, bmp but refers to whatever is used to show the button, it could be a color, gradient or some other kind of renderer. * - * The \e background is always shown and doesn't change if the button is pressed or released. The \e button image is shown over the \e background image when the - * button is not pressed and is replaced by the \e selected image when the button is pressed. The text label is placed always on the top of all images. + * The button's appearance can be modified by setting properties for the various images. * - * When the button is disabled, \e background, \e button and \e selected images are replaced by their \e disabled images. + * It is not mandatory to set all visuals. A button could be defined only by setting its \e background visual or by setting its \e background and \e selected visuals. * - * Is not mandatory to set all images. A button could be defined only by setting its \e background image or by setting its \e background and \e selected images. + * The \e button visual is shown over the \e background visual.. + * When pressed the unselected visuals are replaced by the \e selected visual. The text label is always placed on the top of all images. + * + * When the button is disabled, \e background, \e button and \e selected visuals are replaced by their \e disabled visuals. + * + + * + * @brief A control which renders a short text string. + * + * Text labels are lightweight, non-editable and do not respond to user input. + * + * + * @section ButtonProperties Properties + * |%Property enum |String name |Type |Writable|Animatable| + * |-------------------------------------------------------|----------------------------------------|--------------|--------|----------| + * | Property::DISABLED | disabled | BOOLEAN | Y | N | + * | Property::AUTO_REPEATING | autoRepeating | BOOLEAN | Y | N | + * | Property::INITIAL_AUTO_REPEATING_DELAY | initialAutoRepeatingDelay | FLOAT | Y | N | + * | Property::NEXT_AUTO_REPEATING_DELAY | nextAutoRepeatingDelay | FLOAT | Y | N | + * | Property::TOGGLABLE | togglable | BOOLEAN | Y | N | + * | Property::SELECTED | selected | BOOLEAN | Y | N | + * | Property::LABEL | label | MAP | Y | N | + * | Property::UNSELECTED_STATE_VISUAL | unselectedVisual | MAP | Y | N | + * | Property::SELECTED_VISUAL | selectedVisual | MAP | Y | N | + * | Property::DISABLED_SELECTED_VISUAL | disabledSelectedVisual | MAP | Y | N | + * | Property::DISABLED_UNSELECTED_VISUAL | disabledUnselectedVisual | MAP | Y | N | + * | Property::UNSELECTED_BACKGROUND_VISUAL | unselectedBackgroundVisual | MAP | Y | N | + * | Property::SELECTED_BACKGROUND_VISUAL | selectedBackgroundVisual | MAP | Y | N | + * | Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL | disabledUnselectedBackgroundVisual | MAP | Y | N | + * | Property::DISABLED_SELECTED_BACKGROUND_VISUAL | disabledSelectedBackgroundVisual | MAP | Y | N | + * | Property::LABEL_STRUT_LENGTH | labelStrutLength | INTEGER | Y | N | + * | Property::LABEL_RELATIVE_ALIGNMENT | labelRelativeAlignment | STRING | Y | N | + * ------------------------------------------------------------------------------------------------------------------------------------- + * + * Note, *_VISUAL properties of type MAP can also be passed a uri of type STRING * * Signals * | %Signal Name | Method | @@ -108,21 +141,168 @@ public: */ enum { - DISABLED = PROPERTY_START_INDEX, ///< name "disabled", @see SetDisabled(), type bool @SINCE_1_0.0 - AUTO_REPEATING, ///< name "autoRepeating", @see SetAutoRepeating(), type bool @SINCE_1_0.0 - INITIAL_AUTO_REPEATING_DELAY, ///< name "initialAutoRepeatingDelay", @see SetInitialAutoRepeatingDelay(), type float @SINCE_1_0.0 - NEXT_AUTO_REPEATING_DELAY, ///< name "nextAutoRepeatingDelay", @see SetNextAutoRepeatingDelay(), type float @SINCE_1_0.0 - TOGGLABLE, ///< name "togglable", @see SetTogglableButton(), type bool @SINCE_1_0.0 - SELECTED, ///< name "selected", @see SetSelected(), type bool @SINCE_1_0.0 - UNSELECTED_STATE_IMAGE, ///< name "unselectedStateImage", @see SetUnselectedImage(), type std::string @SINCE_1_0.0 - SELECTED_STATE_IMAGE, ///< name "selectedStateImage", @see SetSelectedImage(), type std::string @SINCE_1_0.0 - DISABLED_STATE_IMAGE, ///< name "disabledStateImage", @see SetDisabledImage(), type std::string @SINCE_1_0.0 - UNSELECTED_COLOR, ///< name "unselectedColor", type Vector4 @SINCE_1_0.0 - SELECTED_COLOR, ///< name "selectedColor", type Vector4 @SINCE_1_0.0 - LABEL, ///< name "label", type Property::Map @SINCE_1_0.0 - - // Deprecated properties: - LABEL_TEXT, ///< name "labelText", @see SetLabelText(), type std::string @SINCE_1_0.0 + /** + * @brief name "disabled", type bool + * @details Sets the button as \e disabled. + * @SINCE_1_0.0 + */ + DISABLED = PROPERTY_START_INDEX, + + /** + * @brief name "autoRepeating", type bool + * @details If the \e autorepeating property is set to \e true then the \e togglable property is set to false + * @SINCE_1_0.0 + */ + AUTO_REPEATING, + + /** + * @brief name "initialAutoRepeatingDelay", type float + * @details By default this value is set to 0.15 seconds. + * @SINCE_1_0.0 + */ + INITIAL_AUTO_REPEATING_DELAY, + + /** + * @brief name "nextAutoRepeatingDelay", type float + * @details default this value is set to 0.05 seconds + * @SINCE_1_0.0 + */ + NEXT_AUTO_REPEATING_DELAY, + + /** + * @brief name "togglable", type bool + * @details If the \e togglable property is set to \e true, then the \e autorepeating property is set to false. + * @SINCE_1_0.0 + */ + TOGGLABLE, + + /** + * @brief name "selected", type bool + * @details Sets the togglable button as either selected or unselected, \e togglable property must be set to \e true. + * @SINCE_1_0.0 + */ + SELECTED, + + /** + * @DEPRECATED_1_1.XX Use UNSELECTED_VISUAL + * @brief name "unselectedStateImage", type string if it is a url, map otherwise + * @details Sets the unselected button foreground image + * @SINCE_1_0.0 + */ + UNSELECTED_STATE_IMAGE, + + /** + * @DEPRECATED_1_1.XX Use SELECTED_VISUAL + * @brief name "selectedStateImage", type string if it is a url, map otherwise + * @details Sets the selected button foreground image + * @SINCE_1_0.0 + */ + SELECTED_STATE_IMAGE, + + /** + * @DEPRECATED_1_1.XX Use DISABLED_UNSELECTED_VISUAL + * @brief name "disabledStateImage", type string if it is a url, map otherwise + * @details Sets the disabled whilst unselected foreground button visual + * @SINCE_1_0.0 + */ + DISABLED_STATE_IMAGE, + + /** + * @DEPRECATED_1_1.XX Use UNSELECTED_BACKGROUND_VISUAL + * @brief name "unselectedColor", type Vector4 + * @SINCE_1_0.0 + */ + UNSELECTED_COLOR, + + /** + * @DEPRECATED_1_1.XX Use SELECTED_BACKGROUND_VISUAL + * @brief name "selectedColor", type Vector4 + * @SINCE_1_0.0 + */ + SELECTED_COLOR, + + /** + * @brief name "label", type Property::Map + * @SINCE_1_0.0 + */ + LABEL, + + /** + * @DEPRECATED_1_1.32 Use LABEL + * @brief name "labelText", type std::string + * @SINCE_1_0.0 + */ + LABEL_TEXT, + + /** + * @brief name "unselectedVisual", type string if it is a url, map otherwise + * @details Sets the unselected button foreground/icon visual + * @SINCE_1_2.XX + */ + UNSELECTED_VISUAL, + + /** + * @brief name "selectedImage", type string if it is a url, map otherwise + * @details Sets the selected button foreground/icon visual + * @SINCE_1_2.XX + */ + SELECTED_VISUAL, + + /** + * @brief name "disabledSelectedVisual", type string if it is a url, map otherwise + * @details Sets the disabled selected state foreground/icon button visual + * @SINCE_1_2.XX + */ + DISABLED_SELECTED_VISUAL, + + /** + * @brief name "disabledUnSelectedVisual", type string if it is a url, map otherwise + * @details Sets the disabled unselected state foreground/icon visual + * @SINCE_1_2.XX + */ + DISABLED_UNSELECTED_VISUAL, + + /** + * @brief name "unselectedBackgroundVisual", type string if it is a url, map otherwise + * @details Sets the disabled in the unselected state background, button visual + * @SINCE_1_2.XX + */ + UNSELECTED_BACKGROUND_VISUAL, + + /** + * @brief name "selectedBackgroundVisual", type string if it is a url, map otherwise + * @details Sets the selected background button visual + * @SINCE_1_2.XX + */ + SELECTED_BACKGROUND_VISUAL, + + /** + * @brief name "disabledUnselectedBackgroundVisual", type string if it is a url, map otherwise + * @details Sets the disabled while unselected background button visual + * @SINCE_1_2.XX + */ + DISABLED_UNSELECTED_BACKGROUND_VISUAL, + + /** + * @brief name "disabledSelectedBackgroundVisual", type string if it is a url, map otherwise + * @details Sets the disabled while selected background button visual + * @SINCE_1_2.XX + */ + DISABLED_SELECTED_BACKGROUND_VISUAL, + + /** + * @brief name "labelStrutLength", type INTEGER + * @details Sets the distance between the label and foreground/icon visual if both present + * @SINCE_1_2.XX + */ + LABEL_STRUT_LENGTH, // todo ????? remove + + /** + * @brief name "labelRelativeAlignment", type STRING + * @details Sets the position of the the label in relation to the foreground/icon if both present + * @SINCE_1_2.XX + */ + LABEL_RELATIVE_ALIGNMENT, }; }; @@ -326,7 +506,7 @@ public: float GetAnimationTime() const DALI_DEPRECATED_API; /** - * @DEPRECATED_1_1.32 SetProperty LABEL or Styling file + * @DEPRECATED_1_1.32 SetProperty Property::LABEL or Styling file * * @brief Sets the button's label. * @@ -346,7 +526,7 @@ public: std::string GetLabelText() const DALI_DEPRECATED_API; /** - * @DEPRECATED_1_1.32 Use Styling file + * @DEPRECATED_1_1.32 Use Styling file Property::UNSELECTED_STATE_IMAGE * * @brief Sets the unselected button image. * @@ -357,8 +537,9 @@ public: /** * @DEPRECATED_1_1.32 Use styling + * Use Property::UNSELECTED_BACKGROUND_VISUAL * - * @brief Sets the background image. + * @brief Sets the unselected background image. * * @SINCE_1_0.0 * @param[in] filename The background image. @@ -366,7 +547,7 @@ public: void SetBackgroundImage( const std::string& filename ) DALI_DEPRECATED_API; /** - * @DEPRECATED_1_1.32 Use styling file + * @DEPRECATED_1_1.32 Use styling file, Property::SELECTED_STATE_IMAGE * * @brief Sets the selected image. * @@ -376,7 +557,8 @@ public: void SetSelectedImage( const std::string& filename ) DALI_DEPRECATED_API; /** - * @DEPRECATED_1_1.32 Use styling file + * @DEPRECATED_1_2.32 Use styling file + * Use Property::SELECTED_BACKGROUND_VISUAL * * @brief Sets the selected background image. * @@ -387,6 +569,7 @@ public: /** * @DEPRECATED_1_1.32 Use styling file + * Use Property::DISABLED_SELECTED_BACKGROUND_VISUAL * * @brief Sets the disabled background image. * @@ -396,7 +579,7 @@ public: void SetDisabledBackgroundImage( const std::string& filename ) DALI_DEPRECATED_API; /** - * @DEPRECATED_1_1.32 Use styling file + * @DEPRECATED_1_1.32 Use styling file Property::DISABLED_STATE_IMAGE * * @brief Sets the disabled button image. * @@ -407,6 +590,7 @@ public: /** * @DEPRECATED_1_1.32 Use styling file + * Use Property::DISABLED_SELECTED_VISUAL * * @brief Sets the disabled selected button image. * diff --git a/dali-toolkit/public-api/controls/buttons/push-button.cpp b/dali-toolkit/public-api/controls/buttons/push-button.cpp index 5e40b55..80f8b16 100644 --- a/dali-toolkit/public-api/controls/buttons/push-button.cpp +++ b/dali-toolkit/public-api/controls/buttons/push-button.cpp @@ -21,6 +21,8 @@ // EXTERNAL INCLUDES #include +#include + // INTERNAL INCLUDES #include @@ -80,49 +82,46 @@ void PushButton::SetButtonImage( Actor image ) { DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetButtonImage() is deprecated and will be removed from next release. Use Button.SetProperty UNSELECTED_STATE_IMAGE or Styling file instead.\n" ); - Dali::Toolkit::GetImplementation( *this ).SetButtonImage( image ); + // Passing Image as Actor not supported } void PushButton::SetBackgroundImage( Actor image ) { DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetBackgroundImage() is deprecated and will be removed from next release.\n" ); - Dali::Toolkit::GetImplementation( *this ).SetBackgroundImage( image ); + // Passing Image as Actor not supported} } void PushButton::SetSelectedImage( Actor image ) { DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetSelectedImage() is deprecated and will be removed from next release. Use Button.SetProperty SELECTED_STATE_IMAGE or Styling file instead.\n" ); - Dali::Toolkit::GetImplementation( *this ).SetSelectedImage( image ); + // Passing Image as Actor not supported} } void PushButton::SetSelectedBackgroundImage( Actor image ) { DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetSelectedBackgroundImage() is deprecated and will be removed from next release.\n" ); - Dali::Toolkit::GetImplementation( *this ).SetSelectedBackgroundImage( image ); + // Passing Image as Actor not supported} } void PushButton::SetDisabledBackgroundImage( Actor image ) { DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabledBackgroundImage() is deprecated and will be removed from next release.\n" ); - - Dali::Toolkit::GetImplementation( *this ).SetDisabledBackgroundImage( image ); + // Passing Image as Actor not supported} } void PushButton::SetDisabledImage( Actor image ) { DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabledImage() is deprecated and will be removed from next release. Use Button.SetProperty DISABLED_STATE_IMAGE or Styling file instead.\n" ); - - Dali::Toolkit::GetImplementation( *this ).SetDisabledImage( image ); + // Passing Image as Actor not supported } void PushButton::SetDisabledSelectedImage( Actor image ) { DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: SetDisabledSelectedImage() is deprecated and will be removed from next release.\n" ); - - Dali::Toolkit::GetImplementation( *this ).SetDisabledSelectedImage( image ); + // Passing Image as Actor not supported } } // namespace Toolkit diff --git a/dali-toolkit/public-api/controls/buttons/push-button.h b/dali-toolkit/public-api/controls/buttons/push-button.h index 6142413..f0d2e29 100644 --- a/dali-toolkit/public-api/controls/buttons/push-button.h +++ b/dali-toolkit/public-api/controls/buttons/push-button.h @@ -111,9 +111,9 @@ public: */ enum { - UNSELECTED_ICON = PROPERTY_START_INDEX, ///< Property, name "unselectedIcon", type std::string @SINCE_1_0.0 - SELECTED_ICON, ///< Property, name "selectedIcon", type std::string @SINCE_1_0.0 - ICON_ALIGNMENT, ///< Property, name "iconAlignment", type std::string @SINCE_1_0.0 + UNSELECTED_ICON = PROPERTY_START_INDEX, ///< Property, name "unselectedIcon", type std::string @SINCE_1_0.0 @DEPRECATED_1_2.XX Button::Property::UNSELECTED_VISUAL + SELECTED_ICON, ///< Property, name "selectedIcon", type std::string @SINCE_1_0.0 @DEPRECATED_1_2.XX Button::Property::SELECTED_VISUAL + ICON_ALIGNMENT, ///< Property, name "iconAlignment", type std::string @SINCE_1_0.0 @DEPRECATED_1_2.XX Use Button::Property::LABEL_RELATIVE_ALIGNMENT LABEL_PADDING, ///< Property, name "labelPadding", type Vector4 @SINCE_1_0.0 ICON_PADDING, ///< Property, name "iconPadding", type Vector4 @SINCE_1_0.0 }; @@ -172,7 +172,7 @@ public: */ static PushButton DownCast( BaseHandle handle ); - + /////////////////////////////////////////////////////////////////////////// // Deprecated API using Button::SetButtonImage; diff --git a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json index a710272..78b8a87 100644 --- a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json @@ -159,6 +159,94 @@ "ProgressBarValueTextLabel": { "textColor":[0.8,0.8,1,1] + }, + "Button": + { + "initialAutoRepeatingDelay":2.0, + "nextAutoRepeatingDelay":0.9, + "label": + { + "visualType": "TEXT", + "horizontalAlignment": "CENTER", + "pointSize" : 15.0, // Point size must always be provided to Text Visual + "verticalAlignment": "CENTER" + } + // Note: Visuals added to Button will be used in all derived buttons unless overridden. + }, + "PushButton": + { + "styles":["Button"], + "autoRepeating":false, + "togglable":false, + "labelPadding":[ 12.0, 12.0, 12.0, 12.0 ], + "unselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-up.9.png" + }, + "selectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-down.9.png" + }, + "disabledSelectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-down-disabled.9.png" + }, + "disabledUnselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-disabled.9.png" + } + }, + "CheckBoxButton": + { + "styles":["Button"], + "unselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-unselected.png" + }, + "selectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-selected.png" + }, + "disabledUnselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-unselected-disabled.png" + }, + "disabledSelectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-selected-disabled.png" + } + }, + "RadioButton": + { + "styles":["Button"], + "unselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-unselected.png" + }, + "selectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-selected.png" + }, + "disabledUnselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-unselected-disabled.png" + }, + "disabledSelectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-selected-disabled.png" + } } } } diff --git a/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json b/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json index 4ec9d10..7ee4416 100644 --- a/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json @@ -57,14 +57,6 @@ { "pointSize":25 }, - "RadioButton": - { - "unselectedStateImage":"{DALI_IMAGE_DIR}radio-button-unselected.png", - "selectedStateImage":"{DALI_IMAGE_DIR}radio-button-selected.png", - "disabledUnselectedStateImage":"{DALI_IMAGE_DIR}radio-button-unselected-disabled.png", - "disabledSelectedStateImage":"{DALI_IMAGE_DIR}radio-button-selected-disabled.png" - }, - "TextField": { "pointSize":18, @@ -214,6 +206,88 @@ "ProgressBarValueTextLabel": { "textColor":[0.8,0.8,1,1] + }, + "Button": + { + "initialAutoRepeatingDelay":2.0, + "nextAutoRepeatingDelay":0.9, + "labelStrutLength":12 + // Note: Visuals added to Button will be used in all derived buttons unless overridden. + }, + "PushButton": + { + "styles":["Button"], + "autoRepeating":false, + "togglable":false, + "labelPadding":[ 12.0, 12.0, 12.0, 12.0 ], + "unselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-up.9.png" + }, + "selectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-down.9.png" + }, + "disabledSelectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-down-disabled.9.png" + }, + "disabledUnselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-disabled.9.png" + } + }, + "CheckBoxButton": + { + "styles":["Button"], + "unselectedVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-unselected.png" + }, + "selectedVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-selected.png" + }, + "disabledUnselectedVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-unselected-disabled.png" + }, + "disabledSelectedVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-selected-disabled.png" + } + }, + "RadioButton": + { + "styles":["Button"], + "unselectedVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-unselected.png" + }, + "selectedVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-selected.png" + }, + "disabledUnselectedVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-unselected-disabled.png" + }, + "disabledSelectedVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-selected-disabled.png" + } } } } diff --git a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json index bc8931d..a57d641 100644 --- a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json @@ -214,6 +214,88 @@ "ProgressBarValueTextLabel": { "textColor":[0.8,0.8,1,1] + }, + "Button": + { + "initialAutoRepeatingDelay":2.0, + "nextAutoRepeatingDelay":0.9, + "labelStrutLength":12 + // Note: Visuals added to Button will be used in all derived buttons unless overridden. + }, + "PushButton": + { + "styles":["Button"], + "autoRepeating":false, + "togglable":false, + "labelPadding":[ 12.0, 12.0, 12.0, 12.0 ], + "unselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-up.9.png" + }, + "selectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-down.9.png" + }, + "disabledSelectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-down-disabled.9.png" + }, + "disabledUnselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}button-disabled.9.png" + } + }, + "CheckBoxButton": + { + "styles":["Button"], + "unselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-unselected.png" + }, + "selectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-selected.png" + }, + "disabledUnselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-unselected-disabled.png" + }, + "disabledSelectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}checkbox-selected-disabled.png" + } + }, + "RadioButton": + { + "styles":["Button"], + "unselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-unselected.png" + }, + "selectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-selected.png" + }, + "disabledUnselectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-unselected-disabled.png" + }, + "disabledSelectedBackgroundVisual": + { + "visualType": "IMAGE", + "url": "{DALI_IMAGE_DIR}radio-button-selected-disabled.png" + } } } } diff --git a/dali-toolkit/styles/images-common/checkbox-selected-diabled.png b/dali-toolkit/styles/images-common/checkbox-selected-disabled.png similarity index 100% rename from dali-toolkit/styles/images-common/checkbox-selected-diabled.png rename to dali-toolkit/styles/images-common/checkbox-selected-disabled.png -- 2.7.4