/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
#include "button-impl.h"
// EXTERNAL INCLUDES
-#include <cstring> // for strcmp
+#include <dali/devel-api/object/property-helper-devel.h>
#include <dali/devel-api/scripting/enum-helper.h>
+#include <dali/devel-api/scripting/scripting.h>
#include <dali/integration-api/debug.h>
-#include <dali/public-api/events/touch-data.h>
-#include <dali/public-api/images/resource-image.h>
-#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/events/touch-event.h>
#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/size-negotiation/relayout-container.h>
-#include <dali/devel-api/scripting/scripting.h>
+#include <cstring> // for strcmp
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/visuals/text/text-visual.h>
+#include <dali-toolkit/public-api/align-enumerations.h>
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
+#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
-#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
-#include <dali-toolkit/devel-api/align-enums.h>
-#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
-#include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
-#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
-
+#include <dali-toolkit/public-api/visuals/text-visual-properties.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
#if defined(DEBUG_ENABLED)
- Debug::Filter* gLogButtonFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_BUTTON_CONTROL");
+Debug::Filter* gLogButtonFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_BUTTON_CONTROL");
#endif
namespace Dali
{
-
namespace Toolkit
{
-
namespace Internal
{
-
namespace
{
-
BaseHandle Create()
{
// empty handle as we cannot create button (but type registered for clicked signal)
}
// 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", 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, "labelRelativeAlignment", STRING, LABEL_RELATIVE_ALIGNMENT )
+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, "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, "label", MAP, LABEL)
+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_DEVEL_PROPERTY_REGISTRATION(Toolkit, Button, "labelRelativeAlignment", STRING, LABEL_RELATIVE_ALIGNMENT)
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, Button, "labelPadding", VECTOR4, LABEL_PADDING)
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, Button, "visualPadding", VECTOR4, VISUAL_PADDING)
// Signals:
-DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED )
-DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED )
-DALI_SIGNAL_REGISTRATION( Toolkit, Button, "clicked", SIGNAL_CLICKED )
-DALI_SIGNAL_REGISTRATION( Toolkit, Button, "stateChanged", SIGNAL_STATE_CHANGED )
+DALI_SIGNAL_REGISTRATION(Toolkit, Button, "pressed", SIGNAL_PRESSED)
+DALI_SIGNAL_REGISTRATION(Toolkit, Button, "released", SIGNAL_RELEASED)
+DALI_SIGNAL_REGISTRATION(Toolkit, Button, "clicked", SIGNAL_CLICKED)
+DALI_SIGNAL_REGISTRATION(Toolkit, Button, "stateChanged", SIGNAL_STATE_CHANGED)
// Actions:
-DALI_ACTION_REGISTRATION( Toolkit, Button, "buttonClick", ACTION_BUTTON_CLICK )
+DALI_ACTION_REGISTRATION(Toolkit, Button, "buttonClick", ACTION_BUTTON_CLICK)
DALI_TYPE_REGISTRATION_END()
-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 )
+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 },
+ {
+ {"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 unsigned int ALIGNMENT_STRING_TABLE_COUNT = sizeof(ALIGNMENT_STRING_TABLE) / sizeof(ALIGNMENT_STRING_TABLE[0]);
+
+const Property::Index 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}};
-const Property::Index GET_VISUAL_INDEX_FOR_STATE[][Button::STATE_COUNT] =
+/**
+ * Checks if given map contains a text string
+ */
+bool MapContainsTextString(Property::Map& map)
{
- { 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 }
-};
+ bool result = false;
+ Property::Value* value = map.Find(Toolkit::TextVisual::Property::TEXT);
+ if(value)
+ {
+ std::string textString;
+ value->Get(textString);
+ if(!textString.empty())
+ {
+ result = true;
+ }
+ }
+ return result;
+}
} // unnamed namespace
Button::Button()
-: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
+: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
mAutoRepeatingTimer(),
- mTextLabelAlignment( END ),
- mAutoRepeating( false ),
- mTogglableButton( false ),
- mInitialAutoRepeatingDelay( 0.0f ),
- mNextAutoRepeatingDelay( 0.0f ),
- mAnimationTime( 0.0f ),
- mButtonPressedState( UNPRESSED ),
- mButtonState( UNSELECTED_STATE ),
- mPreviousButtonState( mButtonState ),
- mClickActionPerforming( false )
+ mTextLabelAlignment(END),
+ mAutoRepeating(false),
+ mTogglableButton(false),
+ mTextStringSetFlag(false),
+ mInitialAutoRepeatingDelay(0.0f),
+ mNextAutoRepeatingDelay(0.0f),
+ mAnimationTime(0.0f),
+ mButtonPressedState(UNPRESSED),
+ mButtonState(UNSELECTED_STATE),
+ mPreviousButtonState(mButtonState),
+ mClickActionPerforming(false)
{
}
{
}
-void Button::SetAutoRepeating( bool autoRepeating )
+void Button::SetAutoRepeating(bool autoRepeating)
{
mAutoRepeating = autoRepeating;
- // An autorepeating button can't be a togglable button.
- if( autoRepeating )
+ // An autorepeating button can't be a toggle button.
+ if(autoRepeating)
{
- mTogglableButton = false;
-
- if( IsSelected() )
+ if(IsSelected())
{
- SetSelected( false );
+ SetSelected(false); // UnSelect before switching off Toggle feature.
}
+ mTogglableButton = false;
}
}
-bool Button::IsAutoRepeating() const
+void Button::SetInitialAutoRepeatingDelay(float initialAutoRepeatingDelay)
{
- return mAutoRepeating;
-}
-
-void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
-{
- DALI_ASSERT_DEBUG( initialAutoRepeatingDelay > 0.f );
+ DALI_ASSERT_DEBUG(initialAutoRepeatingDelay > 0.f);
mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
}
-float Button::GetInitialAutoRepeatingDelay() const
-{
- return mInitialAutoRepeatingDelay;
-}
-
-void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
+void Button::SetNextAutoRepeatingDelay(float nextAutoRepeatingDelay)
{
- DALI_ASSERT_DEBUG( nextAutoRepeatingDelay > 0.f );
+ DALI_ASSERT_DEBUG(nextAutoRepeatingDelay > 0.f);
mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
}
-float Button::GetNextAutoRepeatingDelay() const
-{
- return mNextAutoRepeatingDelay;
-}
-
-void Button::SetTogglableButton( bool togglable )
+void Button::SetTogglableButton(bool togglable)
{
mTogglableButton = togglable;
// A toggle button can't be an autorepeating button.
- if( togglable )
+ if(togglable)
{
mAutoRepeating = false;
}
}
-bool Button::IsTogglableButton() const
+void Button::SetSelected(bool selected)
{
- return mTogglableButton;
-}
-
-void Button::SetSelected( bool selected )
-{
- if( mTogglableButton )
+ if(mTogglableButton)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetSelected (%s)\n", (selected?"true":"false") );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::SetSelected (%s)\n", (selected ? "true" : "false"));
- if ( selected && ( mButtonState != SELECTED_STATE ) )
+ if(selected && (mButtonState != SELECTED_STATE))
{
- ChangeState( SELECTED_STATE );
+ ChangeState(SELECTED_STATE);
}
- else if ( !selected && ( mButtonState != UNSELECTED_STATE ) )
+ else if(!selected && (mButtonState != UNSELECTED_STATE))
{
- ChangeState( UNSELECTED_STATE );
+ ChangeState(UNSELECTED_STATE);
}
}
}
-void Button::SetDisabled( bool disabled )
+void Button::SetDisabled(bool disabled)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetDisabled(%s) state(%d)\n", (disabled)?"disabled":"active", mButtonState );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::SetDisabled(%s) state(%d)\n", (disabled) ? "disabled" : "active", mButtonState);
- if ( disabled )
+ if(disabled)
{
- if ( mButtonState == SELECTED_STATE )
+ if(mButtonState == SELECTED_STATE)
{
- ChangeState( DISABLED_SELECTED_STATE );
+ ChangeState(DISABLED_SELECTED_STATE);
}
- else if ( mButtonState == UNSELECTED_STATE )
+ else if(mButtonState == UNSELECTED_STATE)
{
- ChangeState( DISABLED_UNSELECTED_STATE );
+ ChangeState(DISABLED_UNSELECTED_STATE);
}
}
else
{
- if ( mButtonState == DISABLED_SELECTED_STATE )
+ if(mButtonState == DISABLED_SELECTED_STATE)
{
- ChangeState( SELECTED_STATE );
+ ChangeState(SELECTED_STATE);
}
- else if ( mButtonState == DISABLED_UNSELECTED_STATE )
+ else if(mButtonState == DISABLED_UNSELECTED_STATE)
{
- ChangeState( UNSELECTED_STATE );
+ ChangeState(UNSELECTED_STATE);
}
}
}
bool Button::IsDisabled() const
{
- return ( mButtonState == DISABLED_SELECTED_STATE || mButtonState == DISABLED_UNSELECTED_STATE ) ;
+ return (mButtonState == DISABLED_SELECTED_STATE || mButtonState == DISABLED_UNSELECTED_STATE);
}
-bool Button::ValidateState( State requestedState )
+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 }
- };
+ /* 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");
+ 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] );
-
- RelayoutRequest();
-}
-
-void Button::ChangeState( State requestedState )
+void Button::ChangeState(State requestedState)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ChangeState ReuestedState(%d)\n", requestedState );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::ChangeState ReuestedState(%d)\n", requestedState);
// Validate State before changing
- if ( !ValidateState( requestedState ))
+ if(!ValidateState(requestedState))
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ChangeState ReuestedState(%d) not validated\n", requestedState );
+ 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
+ // 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
- if ( Self().OnStage() )
+ if(Self().GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE))
{
- OnStateChange( mButtonState ); // Notify derived buttons
- PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
+ OnStateChange(mButtonState); // Notify derived buttons
+ SelectRequiredVisual(VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND]);
+ SelectRequiredVisual(VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND]);
// If animation supported then visual removal should be performed after any transition animation has completed.
- PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
+ // If Required Visual is not loaded before current visual is removed then a flickering will be evident.
+ // Derived button can override OnButtonVisualRemoval
+ OnButtonVisualRemoval(VISUAL_INDEX_FOR_STATE[mPreviousButtonState][BACKGROUND]);
+ OnButtonVisualRemoval(VISUAL_INDEX_FOR_STATE[mPreviousButtonState][FOREGROUND]);
+ RelayoutRequest();
}
- Toolkit::Button handle( GetOwner() );
+ Toolkit::Button handle(GetOwner());
// Emit signal.
- mStateChangedSignal.Emit( handle );
+ mStateChangedSignal.Emit(handle);
}
bool Button::IsSelected() const
{
- bool selected = ( mButtonState == SELECTED_STATE ) || ( mButtonState == DISABLED_SELECTED_STATE );
+ bool selected = (mButtonState == SELECTED_STATE) || (mButtonState == DISABLED_SELECTED_STATE);
return mTogglableButton && selected;
}
-void Button::SetLabelText( const std::string& label )
+void Button::MergeWithExistingLabelProperties(const Property::Map& inMap, Property::Map& outMap)
{
- Property::Map labelProperty;
- labelProperty.Insert( "text", label );
- SetupLabel( labelProperty );
-}
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "MergeLabelProperties with %d properties\n", inMap.Count());
-std::string Button::GetLabelText() const
-{
- Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel );
- if( label )
+ /**
+ * Properties for the Label visual could be from a style sheet but after being set the "TEXT" property could be set.
+ * Hence would need to create the Text Visual with the complete merged set of properties.
+ *
+ * 1) Find Label Visual
+ * 2) Retrieve current properties ( settings )
+ * 3) Merge with new properties ( settings )
+ * 4) Return new merged map
+ */
+ Toolkit::Visual::Base visual = DevelControl::GetVisual(*this, Toolkit::Button::Property::LABEL);
+ if(visual)
{
- return label.GetProperty<std::string>( Dali::Toolkit::TextLabel::Property::TEXT );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "MergeLabelProperties Visual already exists, retrieving existing map\n");
+ visual.CreatePropertyMap(outMap);
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "MergeLabelProperties retrieved %d properties\n", outMap.Count());
}
- return std::string();
-}
-
-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.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 );
- }
+ outMap.Merge(inMap);
- // Set any properties specified for the label by iterating through all property key-value pairs.
- for( unsigned int i = 0, mapCount = properties.Count(); i < mapCount; ++i )
- {
- const StringValuePair& propertyPair( properties.GetPair( i ) );
+ // Store if a text string has been supplied.
- // Convert the property string to a property index.
- Property::Index setPropertyIndex = mLabel.GetPropertyIndex( propertyPair.first );
- if( setPropertyIndex != Property::INVALID_INDEX )
- {
- // If the conversion worked, we have a valid property index,
- // Set the property to the new value.
- mLabel.SetProperty( setPropertyIndex, propertyPair.second );
- }
- }
+ mTextStringSetFlag = MapContainsTextString(outMap);
- RelayoutRequest();
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "MergeLabelProperties now has %d properties\n", outMap.Count());
}
-void Button::SetLabelAlignment( Button::Align labelAlignment)
+void Button::SetLabelAlignment(Button::Align labelAlignment)
{
mTextLabelAlignment = labelAlignment;
RelayoutRequest();
return mTextLabelAlignment;
}
-void Button::CreateVisualsForComponent( Property::Index index, const Property::Value& value, const float visualDepth )
+/**
+ * Create Visual for given index from a property map or url.
+ * 1) Check if value passed in is a url and create visual
+ * 2) Create visual from map if step (1) is false
+ * 3) Register visual with control with false for enable flag. Button will later enable visual when needed ( Button::SelectRequiredVisual )
+ * 4) Unregister visual if empty map was provided. This is the method to remove a visual
+ */
+void Button::CreateVisualsForComponent(Property::Index index, const Property::Value& value, const int visualDepth)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent index(%d)\n", index );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent index(%d)\n", index);
Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
- Toolkit::Visual::Base buttonVisual;
+ Toolkit::Visual::Base buttonVisual;
std::string imageUrl;
- if( value.Get( imageUrl ) )
+ if(value.Get(imageUrl))
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using image URL(%d)\n", index );
- if ( !imageUrl.empty() )
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using image URL(%d)\n", index);
+ if(!imageUrl.empty())
{
- buttonVisual = visualFactory.CreateVisual( imageUrl, ImageDimensions() );
+ DALI_ASSERT_DEBUG(index != Toolkit::Button::Property::LABEL && "Creating a Image Visual instead of Text Visual ");
+ buttonVisual = visualFactory.CreateVisual(imageUrl, ImageDimensions());
}
}
else
{
// 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.
+ const 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 );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using Map(%d)\n", index);
+ buttonVisual = visualFactory.CreateVisual(*map);
}
}
- if ( buttonVisual )
+ if(buttonVisual)
{
- 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 );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent RegisterVisual index(%d) enabled(%s)\n", index, DevelControl::IsVisualEnabled(*this, index) ? "true" : "false");
+ // enable the visual if needed for current state
+ const bool enabled = ((index == VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND]) ||
+ (index == VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND]) ||
+ (index == Toolkit::Button::Property::LABEL));
+ DevelControl::RegisterVisual(*this, index, buttonVisual, enabled, visualDepth);
}
else
{
- UnregisterVisual( index );
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "Button visual not created or empty map provided (clearing visual).(%d)\n", index);
+ DevelControl::UnregisterVisual(*this, index);
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "CreateVisualsForComponent Visual not created or empty map (clearing visual).(%d)\n", index);
+ }
+ RelayoutRequest();
+}
+
+bool Button::GetPropertyMapForVisual(Property::Index visualIndex, Property::Map& retreivedMap) const
+{
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "GetPropertyMapForVisual visual(%d)\n", visualIndex);
+ bool success = false;
+ Toolkit::Visual::Base visual = DevelControl::GetVisual(*this, visualIndex);
+ if(visual)
+ {
+ visual.CreatePropertyMap(retreivedMap);
+ success = true;
}
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "GetPropertyMapForVisual %s\n", success ? "Success" : "Failure");
+ return success;
}
-bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
+bool Button::DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes)
{
bool ret = false;
- Dali::BaseHandle handle( object );
+ Dali::BaseHandle handle(object);
- Toolkit::Button button = Toolkit::Button::DownCast( handle );
+ Toolkit::Button button = Toolkit::Button::DownCast(handle);
- DALI_ASSERT_DEBUG( button );
+ DALI_ASSERT_DEBUG(button);
- if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
+ if(0 == strcmp(actionName.c_str(), ACTION_BUTTON_CLICK))
{
- ret = GetImplementation( button ).DoClickAction( attributes );
+ ret = GetImplementation(button).DoClickAction(attributes);
}
return ret;
}
-bool Button::DoClickAction( const Property::Map& attributes )
+bool Button::DoClickAction(const Property::Map& attributes)
{
// Prevents the button signals from doing a recursive loop by sending an action
// and re-emitting the signals.
- if( !mClickActionPerforming )
+ if(!mClickActionPerforming)
{
mClickActionPerforming = true;
ButtonDown();
- if ( !mTogglableButton )
+ if(!mTogglableButton)
{
mButtonPressedState = DEPRESSED;
}
void Button::ButtonDown()
{
- if( mTogglableButton )
+ if(mTogglableButton)
{
- if ( mButtonState != SELECTED_STATE )
+ if(mButtonState != SELECTED_STATE)
{
- SetSelected( true );
+ SetSelected(true);
mButtonPressedState = TOGGLE_DEPRESSED;
}
else
{
Pressed();
mButtonPressedState = DEPRESSED;
- if( mAutoRepeating )
+ if(mAutoRepeating)
{
- SetUpTimer( mInitialAutoRepeatingDelay );
+ SetUpTimer(mInitialAutoRepeatingDelay);
}
}
// The pressed signal should be emitted regardless of toggle mode.
- Toolkit::Button handle( GetOwner() );
- mPressedSignal.Emit( handle );
+ Toolkit::Button handle(GetOwner());
+ mPressedSignal.Emit(handle);
}
void Button::ButtonUp()
{
- if( DEPRESSED == mButtonPressedState )
- {
- bool validButtonAction = false;
+ bool emitSignalsForPressAndReleaseAction = false;
- if( mTogglableButton ) // Button up will change state
+ if(DEPRESSED == mButtonPressedState)
+ {
+ if(mTogglableButton) // Button up will change state
{
- validButtonAction = OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour
+ emitSignalsForPressAndReleaseAction = OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour
}
else
{
Released(); // Button up will result in unselected state
- if( mAutoRepeating )
+ if(mAutoRepeating)
{
mAutoRepeatingTimer.Reset();
}
- validButtonAction = true;
+ emitSignalsForPressAndReleaseAction = true;
}
+ }
+ else if(TOGGLE_DEPRESSED == mButtonPressedState)
+ {
+ emitSignalsForPressAndReleaseAction = true; // toggle released after being pressed, a click
+ }
- if ( validButtonAction )
- {
- // The clicked and released signals should be emitted regardless of toggle mode.
- Toolkit::Button handle( GetOwner() );
- mReleasedSignal.Emit( handle );
- mClickedSignal.Emit( handle );
- }
+ if(emitSignalsForPressAndReleaseAction)
+ {
+ // The clicked and released signals should be emitted regardless of toggle mode.
+ Toolkit::Button handle(GetOwner());
+ mReleasedSignal.Emit(handle);
+ mClickedSignal.Emit(handle);
}
}
bool Button::OnToggleReleased()
{
- SetSelected( !IsSelected() );
+ SetSelected(!IsSelected());
mButtonPressedState = UNPRESSED;
return true;
}
-
void Button::OnTouchPointLeave()
{
- if( DEPRESSED == mButtonPressedState )
+ if(DEPRESSED == mButtonPressedState)
{
- if( !mTogglableButton )
+ if(!mTogglableButton)
{
Released();
- if( mAutoRepeating )
+ if(mAutoRepeating)
{
mAutoRepeatingTimer.Reset();
}
mButtonPressedState = UNPRESSED;
// The released signal should be emitted regardless of toggle mode.
- Toolkit::Button handle( GetOwner() );
- mReleasedSignal.Emit( handle );
+ Toolkit::Button handle(GetOwner());
+ mReleasedSignal.Emit(handle);
}
}
return mStateChangedSignal;
}
-bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
+bool Button::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
{
- Dali::BaseHandle handle( object );
+ Dali::BaseHandle handle(object);
- bool connected( true );
- Toolkit::Button button = Toolkit::Button::DownCast( handle );
+ bool connected(true);
+ Toolkit::Button button = Toolkit::Button::DownCast(handle);
- if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) )
+ if(0 == strcmp(signalName.c_str(), SIGNAL_PRESSED))
{
- button.PressedSignal().Connect( tracker, functor );
+ button.PressedSignal().Connect(tracker, functor);
}
- else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) )
+ else if(0 == strcmp(signalName.c_str(), SIGNAL_RELEASED))
{
- button.ReleasedSignal().Connect( tracker, functor );
+ button.ReleasedSignal().Connect(tracker, functor);
}
- else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) )
+ else if(0 == strcmp(signalName.c_str(), SIGNAL_CLICKED))
{
- button.ClickedSignal().Connect( tracker, functor );
+ button.ClickedSignal().Connect(tracker, functor);
}
- else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) )
+ else if(0 == strcmp(signalName.c_str(), SIGNAL_STATE_CHANGED))
{
- button.StateChangedSignal().Connect( tracker, functor );
+ button.StateChangedSignal().Connect(tracker, functor);
}
else
{
void Button::OnInitialize()
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnInitialize\n" );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::OnInitialize\n");
Actor self = Self();
mTapDetector = TapGestureDetector::New();
- mTapDetector.Attach( self );
+ mTapDetector.Attach(self);
mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
- self.SetKeyboardFocusable( true );
+ self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
+ self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
- self.TouchSignal().Connect( this, &Button::OnTouch );
+ self.TouchedSignal().Connect(this, &Button::OnTouch);
}
bool Button::OnAccessibilityActivated()
return OnKeyboardEnter();
}
-bool Button::OnTouch( Actor actor, const TouchData& touch )
+bool Button::OnTouch(Actor actor, const TouchEvent& touch)
{
-
- // Only events are processed when the button is not disabled and the touch event has only
- // one touch point.
-
- if( !IsDisabled() && ( 1 == touch.GetPointCount() ) )
+ if(!IsDisabled() && (actor == touch.GetHitActor(0)))
{
- switch( touch.GetState( 0 ) )
+ if(1 == touch.GetPointCount())
{
- case PointState::DOWN:
- {
- ButtonDown();
- break;
- }
- case PointState::UP:
- {
- ButtonUp();
- break;
- }
- case PointState::INTERRUPTED:
- {
- OnTouchPointInterrupted();
- break;
- }
- case PointState::LEAVE:
- {
- OnTouchPointLeave();
- break;
- }
- case PointState::MOTION:
- case PointState::STATIONARY: // FALLTHROUGH
+ switch(touch.GetState(0))
{
- // Nothing to do
- break;
+ case PointState::DOWN:
+ {
+ ButtonDown();
+ break;
+ }
+ case PointState::UP:
+ {
+ ButtonUp();
+ break;
+ }
+ case PointState::INTERRUPTED:
+ {
+ OnTouchPointInterrupted();
+ break;
+ }
+ case PointState::LEAVE:
+ {
+ OnTouchPointLeave();
+ break;
+ }
+ case PointState::MOTION:
+ case PointState::STATIONARY: // FALLTHROUGH
+ {
+ // Nothing to do
+ break;
+ }
}
}
- }
- else if( 1 < touch.GetPointCount() )
- {
- OnTouchPointLeave(); // Notification for derived classes.
+ else if(1 < touch.GetPointCount())
+ {
+ OnTouchPointLeave(); // Notification for derived classes.
- // Sets the button state to the default
- mButtonPressedState = UNPRESSED;
+ // Sets the button state to the default
+ mButtonPressedState = UNPRESSED;
+ }
}
-
return false;
}
{
// When the enter key is pressed, or button is activated, the click action is performed.
Property::Map attributes;
- bool ret = DoClickAction( attributes );
+ bool ret = DoClickAction(attributes);
return ret;
}
-void Button::OnStageDisconnection()
+void Button::OnSceneDisconnection()
{
- if( DEPRESSED == mButtonPressedState )
+ if(DEPRESSED == mButtonPressedState)
{
- if( !mTogglableButton )
+ if(!mTogglableButton)
{
Released();
- if( mAutoRepeating )
+ if(mAutoRepeating)
{
mAutoRepeatingTimer.Reset();
}
mButtonPressedState = UNPRESSED;
- Control::OnStageDisconnection(); // Visuals will be set off stage
+ Control::OnSceneDisconnection(); // Visuals will be set off stage
}
-void Button::OnStageConnection( int depth )
+void Button::OnSceneConnection(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
-
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::OnSceneConnection ptr(%p) \n", this);
+ OnButtonVisualRemoval(VISUAL_INDEX_FOR_STATE[mPreviousButtonState][BACKGROUND]);
+ OnButtonVisualRemoval(VISUAL_INDEX_FOR_STATE[mPreviousButtonState][FOREGROUND]);
+ SelectRequiredVisual(Toolkit::Button::Property::LABEL);
+ SelectRequiredVisual(VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND]);
+ SelectRequiredVisual(VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND]);
+ Control::OnSceneConnection(depth); // Enabled visuals will be put on stage
+ RelayoutRequest();
}
Vector3 Button::GetNaturalSize()
bool horizontalAlignment = mTextLabelAlignment == BEGIN || mTextLabelAlignment == END; // label and visual side by side
// Get natural size of foreground ( largest of the possible visuals )
- Size largestForegroundVisual;
- Size labelSize;
+ Size largestProvidedVisual;
+ Size labelSize = Size::ZERO;
+
+ bool foreGroundVisualUsed = false;
+
+ for(int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++)
+ {
+ Toolkit::Visual::Base visual = DevelControl::GetVisual(*this, VISUAL_INDEX_FOR_STATE[state][FOREGROUND]);
+ Size visualSize;
+ if(visual)
+ {
+ visual.GetNaturalSize(visualSize);
+ largestProvidedVisual.width = std::max(largestProvidedVisual.width, visualSize.width);
+ largestProvidedVisual.height = std::max(largestProvidedVisual.height, visualSize.height);
+ foreGroundVisualUsed = true;
+ }
+ }
- for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++)
+ if(!foreGroundVisualUsed) // If foreground visual not supplied then use the background visual to calculate Natural size
{
- Toolkit::Visual::Base visual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
- Size visualSize;
- if ( visual )
+ for(int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++)
{
- visual.GetNaturalSize( visualSize );
- largestForegroundVisual.width = std::max(largestForegroundVisual.width, visualSize.width );
- largestForegroundVisual.height = std::max(largestForegroundVisual.height, visualSize.height );
+ Toolkit::Visual::Base visual = DevelControl::GetVisual(*this, VISUAL_INDEX_FOR_STATE[state][BACKGROUND]);
+ Size visualSize;
+ if(visual)
+ {
+ visual.GetNaturalSize(visualSize);
+ largestProvidedVisual.width = std::max(largestProvidedVisual.width, visualSize.width);
+ largestProvidedVisual.height = std::max(largestProvidedVisual.height, visualSize.height);
+ }
}
}
// Get horizontal padding total
- if ( largestForegroundVisual.width > 0 ) // if visual exists
+ if(largestProvidedVisual.width > 0) // if visual exists
{
- size.width += largestForegroundVisual.width + mForegroundPadding.left + mForegroundPadding.right;
+ size.width += largestProvidedVisual.width + mForegroundPadding.left + mForegroundPadding.right;
}
// Get vertical padding total
- if ( largestForegroundVisual.height > 0 )
+ if(largestProvidedVisual.height > 0)
{
- size.height += largestForegroundVisual.height + mForegroundPadding.top + mForegroundPadding.bottom;
+ size.height += largestProvidedVisual.height + mForegroundPadding.top + mForegroundPadding.bottom;
}
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize visual Size(%f,%f)\n",
- largestForegroundVisual.width, largestForegroundVisual.height );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "GetNaturalSize visual Size(%f,%f)\n", largestProvidedVisual.width, largestProvidedVisual.height);
- // Get natural size of label
- if ( mLabel )
+ // Get natural size of label if text has been set
+ if(mTextStringSetFlag)
{
- labelSize = Vector2( mLabel.GetNaturalSize());
+ Toolkit::Visual::Base visual = DevelControl::GetVisual(*this, Toolkit::Button::Property::LABEL);
+
+ if(visual)
+ {
+ visual.GetNaturalSize(labelSize);
- 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);
+ 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);
- labelSize.width += mLabelPadding.left + mLabelPadding.right;
- labelSize.height += mLabelPadding.top + mLabelPadding.bottom;
+ labelSize.width += mLabelPadding.left + mLabelPadding.right;
+ labelSize.height += mLabelPadding.top + mLabelPadding.bottom;
- // 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 );
+ // 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);
+ }
}
}
- if( size.width < 1 && size.height < 1 )
+ 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");
+ 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 );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "Button GetNaturalSize (%f,%f)\n", size.width, size.height);
return size;
}
-void Button::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
+void Button::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnSetResizePolicy\n");
-
- if ( policy != ResizePolicy::USE_NATURAL_SIZE || policy != ResizePolicy::FIT_TO_CHILDREN )
- {
- 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 );
- }
- }
-
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "OnSetResizePolicy\n");
RelayoutRequest();
}
-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 );
+/**
+ * Visuals are sized and positioned in this function.
+ * Whilst the control has it's size negotiated it has to size it's visuals explicitly here.
+ */
- Toolkit::Visual::Base currentVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND] );
+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);
- Toolkit::Visual::Base currentBackGroundVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND] );
+ Toolkit::Visual::Base currentVisual = DevelControl::GetVisual(*this, VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND]);
+ Toolkit::Visual::Base currentBackGroundVisual = DevelControl::GetVisual(*this, VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND]);
// 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 );
+ 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);
- if ( mLabel )
+ if(mTextStringSetFlag)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Label padding setting padding:%f,%f,%f,%f\n", mLabelPadding.y, mLabelPadding.x, mLabelPadding.width,mLabelPadding.height );
+ 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 )
+ 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 );
+ 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 ));
+ 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);
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout visualAndPaddingSize(%f,%f)\n", visualAndPaddingSize.width, visualAndPaddingSize.height);
+ // 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;
- switch ( mTextLabelAlignment )
+ switch(mTextLabelAlignment)
{
- case BEGIN :
+ case BEGIN:
{
visualAnchorPoint = Toolkit::Align::TOP_END;
- visualPosition.x = foregroundVisualPadding.right;
- visualPosition.y = foregroundVisualPadding.top;
+ visualPosition.x = foregroundVisualPadding.right;
+ visualPosition.y = foregroundVisualPadding.top;
labelPosition.x = labelVisualPadding.x;
labelPosition.y = labelVisualPadding.top;
+
+ remainingSpaceForText.width = size.width - visualAndPaddingSize.width - labelVisualPadding.x - labelVisualPadding.y;
+ remainingSpaceForText.height = size.height - labelVisualPadding.top - labelVisualPadding.bottom;
break;
}
- case END :
+ case END:
{
visualAnchorPoint = Toolkit::Align::TOP_BEGIN;
- visualPosition.x = foregroundVisualPadding.left;
- visualPosition.y = foregroundVisualPadding.top;
+ visualPosition.x = foregroundVisualPadding.left;
+ visualPosition.y = foregroundVisualPadding.top;
labelPosition.x = visualAndPaddingSize.width + labelVisualPadding.x;
labelPosition.y = labelVisualPadding.top;
+
+ remainingSpaceForText.width = size.width - visualAndPaddingSize.width - labelVisualPadding.x - labelVisualPadding.y;
+ remainingSpaceForText.height = size.height - labelVisualPadding.top - labelVisualPadding.bottom;
break;
}
- case TOP :
+ case TOP:
{
visualAnchorPoint = Toolkit::Align::BOTTOM_END;
- visualPosition.x = foregroundVisualPadding.left;
- visualPosition.y = foregroundVisualPadding.bottom;
+ visualPosition.x = foregroundVisualPadding.left;
+ visualPosition.y = foregroundVisualPadding.bottom;
labelPosition.x = labelVisualPadding.left;
labelPosition.y = labelVisualPadding.top;
+
+ remainingSpaceForText.width = size.width - labelVisualPadding.x - labelVisualPadding.y;
+ remainingSpaceForText.height = size.height - visualAndPaddingSize.height - labelVisualPadding.top - labelVisualPadding.bottom;
+
break;
}
- case BOTTOM :
+ case BOTTOM:
{
visualAnchorPoint = Toolkit::Align::TOP_END;
- visualPosition.x = foregroundVisualPadding.left;
- visualPosition.y = foregroundVisualPadding.top;
+ visualPosition.x = foregroundVisualPadding.left;
+ visualPosition.y = foregroundVisualPadding.top;
labelPosition.x = labelVisualPadding.left;
labelPosition.y = visualAndPaddingSize.height + labelVisualPadding.top;
+
+ remainingSpaceForText.width = size.width - labelVisualPadding.x - labelVisualPadding.y;
+ remainingSpaceForText.height = size.height - visualAndPaddingSize.height - labelVisualPadding.top - labelVisualPadding.bottom;
+
break;
}
}
- if ( currentBackGroundVisual )
+ if(currentBackGroundVisual)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual bakcground size to(%f,%f)\n", size.width, size.height);
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "OnRelayout Setting visual background size to(%f,%f)\n", size.width, size.height);
Property::Map visualTransform;
- visualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, size )
- .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 0.0f, 0.0f, 1.0f, 1.0f) ); // Use relative size
+ visualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, size)
+ .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE));
- currentBackGroundVisual.SetTransformAndSize( visualTransform, size );
+ currentBackGroundVisual.SetTransformAndSize(visualTransform, size);
}
- if ( currentVisual )
+ 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 )
- );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "OnRelayout Setting visual size to(%f,%f)\n", visualSize.width, visualSize.height);
+
+ Property::Map visualTransform;
+
+ visualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, visualSize)
+ .Add(Toolkit::Visual::Transform::Property::OFFSET, visualPosition)
+ .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
+ .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
+ .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
+ .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, visualAnchorPoint);
+
+ currentVisual.SetTransformAndSize(visualTransform, size);
}
- if ( mLabel )
+ if(mTextStringSetFlag)
{
- // 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.
+ Toolkit::Visual::Base textVisual = DevelControl::GetVisual(*this, Toolkit::Button::Property::LABEL); // No need to search for Label visual if no text set.
- 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 )
+ if(textVisual)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Only Text\n");
+ if(!currentVisual)
+ {
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "OnRelayout Only Text\n");
+ labelPosition.x = labelVisualPadding.left;
+ labelPosition.y = labelVisualPadding.height;
+ }
- // Center Text if no foreground visual
- Size labelNaturalSize = Vector2( mLabel.GetNaturalSize() );
+ Vector2 preSize = Vector2(static_cast<int>(remainingSpaceForText.x), static_cast<int>(remainingSpaceForText.y));
- // 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);
+
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "OnRelayout text Size -- (%f,%f) text Position(%f,%f) \n", preSize.width, preSize.height, labelPosition.x, labelPosition.y);
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout text Size(%f,%f) text Position(%f,%f) \n", remainingSpaceForText.width, remainingSpaceForText.height, labelPosition.x, labelPosition.y);
+ Property::Map textVisualTransform;
+ textVisualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, preSize)
+ .Add(Toolkit::Visual::Transform::Property::OFFSET, labelPosition)
+ .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
+ .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
+ .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
+ .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, visualAnchorPoint);
- mLabel.SetPosition( labelPosition.x, labelPosition.y );
- container.Add( mLabel, remainingSpaceForText ); // Currently a TextLabel is used and size can not be set here.
+ textVisual.SetTransformAndSize(textVisualTransform, size);
+ }
}
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout << \n");
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "OnRelayout selected (%s) \n", IsSelected() ? "yes" : "no");
+
+ DALI_LOG_INFO(gLogButtonFilter, Debug::General, "OnRelayout << \n");
}
void Button::OnTap(Actor actor, const TapGesture& tap)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnTap\n" );
+ // Prevents Parent getting a tap event
}
-void Button::SetUpTimer( float delay )
+void Button::SetUpTimer(float delay)
{
- mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
- mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
+ mAutoRepeatingTimer = Dali::Timer::New(static_cast<unsigned int>(1000.f * delay));
+ mAutoRepeatingTimer.TickSignal().Connect(this, &Button::AutoRepeatingSlot);
mAutoRepeatingTimer.Start();
}
bool Button::AutoRepeatingSlot()
{
bool consumed = false;
- if( !IsDisabled() )
+ if(!IsDisabled())
{
// Restart the autorepeat timer.
- SetUpTimer( mNextAutoRepeatingDelay );
+ SetUpTimer(mNextAutoRepeatingDelay);
Pressed();
- Toolkit::Button handle( GetOwner() );
+ Toolkit::Button handle(GetOwner());
//Emit signal.
- consumed = mReleasedSignal.Emit( handle );
- consumed = mClickedSignal.Emit( handle );
- consumed |= mPressedSignal.Emit( handle );
- }
+ consumed = mReleasedSignal.Emit(handle);
+ consumed = mClickedSignal.Emit(handle);
+ consumed |= mPressedSignal.Emit(handle);
+ }
return consumed;
}
void Button::Pressed()
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Pressed\n" );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::Pressed\n");
- if( mButtonState == UNSELECTED_STATE )
+ if(mButtonState == UNSELECTED_STATE)
{
- ChangeState( SELECTED_STATE );
- OnPressed(); // Notifies the derived class the button has been pressed.
+ ChangeState(SELECTED_STATE);
+ OnPressed(); // Notifies the derived class the button has been pressed.
}
}
void Button::Released()
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Released\n" );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::Released\n");
- if( mButtonState == SELECTED_STATE && !mTogglableButton )
+ if(mButtonState == SELECTED_STATE && !mTogglableButton)
{
- ChangeState( UNSELECTED_STATE );
+ ChangeState(UNSELECTED_STATE);
OnReleased(); // // Notifies the derived class the button has been released.
}
mButtonPressedState = UNPRESSED;
}
-void Button::SelectRequiredVisual( Property::Index visualIndex )
+void Button::SelectRequiredVisual(Property::Index visualIndex)
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SelectRequiredVisual index(%d) state(%d)\n", visualIndex, mButtonState );
-
- EnableVisual( visualIndex, true );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::SelectRequiredVisual index(%d) state(%d)\n", visualIndex, mButtonState);
+ // only enable visuals that exist
+ if(DevelControl::GetVisual(*this, visualIndex))
+ {
+ DevelControl::EnableVisual(*this, visualIndex, true);
+ }
}
-void Button::RemoveVisual( Property::Index visualIndex )
+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 );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::RemoveVisual index(%d) state(%d)\n", visualIndex, mButtonState);
- Toolkit::Visual::Base visual = GetVisual( visualIndex );
+ Toolkit::Visual::Base visual = DevelControl::GetVisual(*this, visualIndex);
- if( visual )
+ if(visual)
{
- EnableVisual( visualIndex, false );
+ DevelControl::EnableVisual(*this, visualIndex, false);
}
}
-void Button::OnButtonVisualRemoval( Property::Index visualIndex )
+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 );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::OnButtonVisualRemoval index(%d)\n", visualIndex);
+ RemoveVisual(visualIndex);
}
-void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+void Button::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
{
- Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
+ Toolkit::Button button = Toolkit::Button::DownCast(Dali::BaseHandle(object));
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty index[%d]\n", index );
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::SetProperty index[%d]\n", index);
- if ( button )
+ if(button)
{
- switch ( index )
+ switch(index)
{
case Toolkit::Button::Property::DISABLED:
{
- GetImplementation( button ).SetDisabled( value.Get< bool >() );
+ GetImplementation(button).SetDisabled(value.Get<bool>());
break;
}
case Toolkit::Button::Property::AUTO_REPEATING:
{
- GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
+ GetImplementation(button).SetAutoRepeating(value.Get<bool>());
break;
}
case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
{
- GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
+ GetImplementation(button).SetInitialAutoRepeatingDelay(value.Get<float>());
break;
}
case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
{
- GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
+ GetImplementation(button).SetNextAutoRepeatingDelay(value.Get<float>());
break;
}
case Toolkit::Button::Property::TOGGLABLE:
{
- GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
+ GetImplementation(button).SetTogglableButton(value.Get<bool>());
break;
}
case Toolkit::Button::Property::SELECTED:
{
- GetImplementation( button ).SetSelected( value.Get< bool >() );
+ GetImplementation(button).SetSelected(value.Get<bool>());
break;
}
- case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: // Legacy Tizen 3.0
- {
- GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
- break;
- }
- 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 ).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 );
+ GetImplementation(button).CreateVisualsForComponent(index, value, DepthIndex::CONTENT);
break;
}
case Toolkit::Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL:
case Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL:
{
- GetImplementation( button ).CreateVisualsForComponent( index , value, DepthIndex::BACKGROUND);
+ GetImplementation(button).CreateVisualsForComponent(index, value, DepthIndex::BACKGROUND);
break;
}
- case Toolkit::Button::Property::UNSELECTED_COLOR:
+ case Toolkit::Button::Property::LABEL:
{
- 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;
- }
+ Property::Map outTextVisualProperties;
+ std::string textString;
- case Toolkit::Button::Property::SELECTED_COLOR:
- {
- 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 );
+ if(value.Get(textString))
+ {
+ DALI_LOG_INFO(gLogButtonFilter, Debug::Verbose, "Button::SetProperty Setting TextVisual with string[%s]\n", textString.c_str());
+
+ Property::Map setPropertyMap;
+ setPropertyMap.Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT)
+ .Add(Toolkit::TextVisual::Property::TEXT, textString);
+
+ GetImplementation(button).MergeWithExistingLabelProperties(setPropertyMap, outTextVisualProperties);
+ }
+ else
+ {
+ // Get a Property::Map from the property if possible.
+ const Property::Map* setPropertyMap = value.GetMap();
+ if(setPropertyMap)
+ {
+ Property::Map indexKeys = TextVisual::ConvertStringKeysToIndexKeys(*setPropertyMap);
+ GetImplementation(button).MergeWithExistingLabelProperties(indexKeys, outTextVisualProperties);
+ }
+ }
+
+ if(!outTextVisualProperties.Empty())
+ {
+ GetImplementation(button).CreateVisualsForComponent(index, outTextVisualProperties, DepthIndex::CONTENT);
+ }
break;
}
- case Toolkit::Button::Property::LABEL_TEXT:
+ case Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT:
{
- 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 );
+ 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;
}
- case Toolkit::Button::Property::LABEL:
+ case Toolkit::DevelButton::Property::LABEL_PADDING:
{
- // Get a Property::Map from the property if possible.
- Property::Map setPropertyMap;
- if( value.Get( setPropertyMap ) )
- {
- GetImplementation( button ).SetupLabel( setPropertyMap );
- }
+ Vector4 padding(value.Get<Vector4>());
+ GetImplementation(button).SetLabelPadding(Padding(padding.x, padding.y, padding.z, padding.w));
break;
}
- case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
+ case Toolkit::DevelButton::Property::VISUAL_PADDING:
{
- Button::Align labelAlignment(END);
- Scripting::GetEnumeration< Button::Align> ( value.Get< std::string >().c_str(),
- ALIGNMENT_TABLE, ALIGNMENT_TABLE_COUNT,
- labelAlignment );
-
- GetImplementation( button ).SetLabelAlignment( labelAlignment );
+ Vector4 padding(value.Get<Vector4>());
+ GetImplementation(button).SetForegroundPadding(Padding(padding.x, padding.y, padding.z, padding.w));
break;
}
}
}
}
-Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
+Property::Value Button::GetProperty(BaseObject* object, Property::Index propertyIndex)
{
Property::Value value;
- Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
+ Toolkit::Button button = Toolkit::Button::DownCast(Dali::BaseHandle(object));
- if ( button )
+ if(button)
{
- switch ( propertyIndex )
+ switch(propertyIndex)
{
case Toolkit::Button::Property::DISABLED:
{
- value = GetImplementation( button ).IsDisabled();
+ value = GetImplementation(button).IsDisabled();
break;
}
case Toolkit::Button::Property::AUTO_REPEATING:
{
- value = GetImplementation( button ).mAutoRepeating;
+ value = GetImplementation(button).mAutoRepeating;
break;
}
case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
{
- value = GetImplementation( button ).mInitialAutoRepeatingDelay;
+ value = GetImplementation(button).mInitialAutoRepeatingDelay;
break;
}
case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
{
- value = GetImplementation( button ).mNextAutoRepeatingDelay;
+ value = GetImplementation(button).mNextAutoRepeatingDelay;
break;
}
case Toolkit::Button::Property::TOGGLABLE:
{
- value = GetImplementation( button ).mTogglableButton;
+ value = GetImplementation(button).mTogglableButton;
break;
}
case Toolkit::Button::Property::SELECTED:
{
- value = GetImplementation( button ).IsSelected();
- break;
- }
-
- case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
- {
- value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::UNSELECTED_VISUAL );
- break;
- }
-
- case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
- {
- value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::SELECTED_VISUAL );
- break;
- }
-
- case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
- {
- value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL );
- break;
- }
-
- case Toolkit::Button::Property::UNSELECTED_COLOR:
- {
- value = GetImplementation( button ).GetUnselectedColor();
+ value = GetImplementation(button).IsSelected();
break;
}
- case Toolkit::Button::Property::SELECTED_COLOR:
+ 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:
+ 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:
+ case Toolkit::Button::Property::LABEL:
{
- value = GetImplementation( button ).GetSelectedColor();
+ Property::Map visualProperty;
+ if(GetImplementation(button).GetPropertyMapForVisual(propertyIndex, visualProperty))
+ {
+ value = visualProperty;
+ }
break;
}
- case Toolkit::Button::Property::LABEL_TEXT:
+ case Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT:
{
- value = GetImplementation( button ).GetLabelText();
- break;
- }
+ const char* alignment = Scripting::GetEnumerationName<Button::Align>(GetImplementation(button).GetLabelAlignment(),
+ ALIGNMENT_STRING_TABLE,
+ ALIGNMENT_STRING_TABLE_COUNT);
+ if(alignment)
+ {
+ value = std::string(alignment);
+ }
- case Toolkit::Button::Property::LABEL:
- {
- Property::Map emptyMap;
- value = emptyMap;
break;
}
- case Toolkit::Button::Property::LABEL_STRUT_LENGTH:
+ case Toolkit::DevelButton::Property::LABEL_PADDING:
{
- value = GetImplementation( button ).GetLabelStrutLength();
+ Padding padding = GetImplementation(button).GetLabelPadding();
+ value = Vector4(padding.x, padding.y, padding.top, padding.bottom);
break;
}
- case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
+ case Toolkit::DevelButton::Property::VISUAL_PADDING:
{
- const char* alignment = Scripting::GetEnumerationName< Button::Align >( GetImplementation( button ).GetLabelAlignment(),
- ALIGNMENT_STRING_TABLE,
- ALIGNMENT_STRING_TABLE_COUNT );
- if( alignment )
- {
- value = std::string( alignment );
- }
-
- break;
+ Padding padding = GetImplementation(button).GetForegroundPadding();
+ value = Vector4(padding.x, padding.y, padding.top, padding.bottom);
}
}
}
return value;
}
-void Button::SetLabelPadding( const Padding& padding)
+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 );
+ 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();
}
return mLabelPadding;
}
-void Button::SetForegroundPadding( const Padding& padding)
+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 );
+ 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();
}
return mForegroundPadding;
}
-////////////////////////////////////////////////////////////////////////
-// Legacy functions from Tizen 2.4 and 3.0
-
-// Legacy code needed 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 ( visualIndex == Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL )
- {
- mSelectedColor = color;
- }
- else
- {
- mUnselectedColor = color;
- }
-
- Property::Map map;
- map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
- map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
-
- CreateVisualsForComponent( visualIndex, map, DepthIndex::BACKGROUND );
-}
-
-const Vector4 Button::GetUnselectedColor() const
-{
- return mUnselectedColor;
-}
-
-const Vector4 Button::GetSelectedColor() const
-{
- return mSelectedColor;
-}
-
-void Button::SetAnimationTime( float animationTime )
-{
- // Used by deprecated API
- mAnimationTime = animationTime;
-}
-
-float Button::GetAnimationTime() const
-{
- // Used by deprecated API
- return mAnimationTime;
-}
-
-void Button::SetLabel( Actor label )
-{
- if ( label )
- {
- Property::Value value ="";
- value = label.GetProperty(Toolkit::TextLabel::Property::TEXT);
-
- SetLabelText( value.Get<std::string>() );
- }
-}
-
-void Button::SetUnselectedImage( const std::string& filename )
-{
- if( !filename.empty() )
- {
- CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
- }
-}
-
-void Button::SetBackgroundImage( const std::string& filename )
-{
- if( !filename.empty() )
- {
- CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
- }
-}
-
-void Button::SetSelectedImage( const std::string& filename )
-{
- if( !filename.empty() )
- {
- CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, filename, DepthIndex::CONTENT );
- }
-}
-
-void Button::SetSelectedBackgroundImage( const std::string& filename )
-{
- if( !filename.empty() )
- {
- CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
- }
-}
-
-void Button::SetDisabledBackgroundImage( const std::string& filename )
-{
- if( !filename.empty() )
- {
- CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
- }
-}
-
-void Button::SetDisabledImage( const std::string& filename )
-{
- if( !filename.empty() )
- {
- CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
- }
-}
-
-void Button::SetDisabledSelectedImage( const std::string& filename )
-{
- if( !filename.empty() )
- {
- CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_SELECTED_VISUAL, filename, DepthIndex::CONTENT );
- }
-}
-
-std::string Button::GetUrlForImageVisual( const Property::Index index ) const
-{
- Toolkit::Visual::Base visual = GetVisual( index );
- std::string result;
-
- 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<std::string>();
- }
- }
-
- return result;
-}
-
-// Below functions DEPRECATED_1_0.50 - Return empty Actors
-
-namespace
+std::string Button::AccessibleImpl::GetNameRaw()
{
-std::string GetUrlFromImage( Image& image )
-{
- ResourceImage resourceImage = ResourceImage::DownCast( image );
-
- std::string imageUrl;
+ std::string labelText;
+ auto slf = Toolkit::Button::DownCast(self);
+ Property::Map labelMap = slf.GetProperty<Property::Map>(Toolkit::Button::Property::LABEL);
- if ( resourceImage )
+ Property::Value* textPropertyPtr = labelMap.Find(Toolkit::TextVisual::Property::TEXT);
+ if(textPropertyPtr)
{
- imageUrl = resourceImage.GetUrl();
+ textPropertyPtr->Get(labelText);
}
- return imageUrl;
-}
-
-} // namespace
-
-
-void Button::SetButtonImage( Image image )
-{
- DALI_LOG_WARNING("Button::SetButtonImage @DEPRECATED_1_0.50\n");
- SetUnselectedImage( GetUrlFromImage( image ) );
-}
-void Button::SetSelectedImage( Image image )
-{
- DALI_LOG_WARNING("Button::SetSelectedImage @DEPRECATED_1_0.50\n");
- SetSelectedImage( GetUrlFromImage( image ) );
+ return labelText;
}
-Actor Button::GetButtonImage() const
+Property::Index Button::AccessibleImpl::GetNamePropertyIndex()
{
- DALI_LOG_WARNING("Button::GetButtonImage @DEPRECATED_1_0.50\n");
- Actor imageView = Toolkit::ImageView::New( GetUrlForImageVisual( Toolkit::Button::Property::UNSELECTED_VISUAL ) );
+ Property::Index label = Toolkit::Button::Property::LABEL;
+ Property::Map labelMap = self.GetProperty<Property::Map>(label);
- return imageView;
+ if(MapContainsTextString(labelMap))
+ return label;
+ else
+ return Property::INVALID_INDEX;
}
-Actor Button::GetSelectedImage() const
+Dali::Accessibility::States Button::AccessibleImpl::CalculateStates()
{
- DALI_LOG_WARNING("Button::GetSelectedImage @DEPRECATED_1_0.50\n");
- Actor imageView = Toolkit::ImageView::New( GetUrlForImageVisual( Toolkit::Button::Property::SELECTED_VISUAL ) );
-
- return imageView;
+ auto tmp = Control::Impl::AccessibleImpl::CalculateStates();
+ tmp[Dali::Accessibility::State::SELECTABLE] = true;
+ auto slf = Toolkit::Button::DownCast(self);
+ tmp[Dali::Accessibility::State::ENABLED] = !slf.GetProperty<bool>(Toolkit::Button::Property::DISABLED);
+ tmp[Dali::Accessibility::State::CHECKED] = slf.GetProperty<bool>(Toolkit::Button::Property::SELECTED);
+ return tmp;
}
} // namespace Internal