/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
#include <dali/public-api/size-negotiation/relayout-container.h>
+#include <dali/devel-api/object/property-helper-devel.h>
#include <dali/devel-api/scripting/scripting.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
#include <dali-toolkit/public-api/controls/image-view/image-view.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/public-api/align-enumerations.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/controls/control-devel.h>
+#include <dali-toolkit/devel-api/controls/buttons/button-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/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");
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_DEVEL_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedVisual", MAP, UNSELECTED_VISUAL )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, Button, "selectedVisual", MAP, SELECTED_VISUAL )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, Button, "disabledSelectedVisual", MAP, DISABLED_SELECTED_VISUAL )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, Button, "disabledUnselectedVisual", MAP, DISABLED_UNSELECTED_VISUAL )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedBackgroundVisual", MAP, UNSELECTED_BACKGROUND_VISUAL )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, Button, "selectedBackgroundVisual", MAP, SELECTED_BACKGROUND_VISUAL )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, Button, "disabledUnselectedBackgroundVisual", MAP, DISABLED_UNSELECTED_BACKGROUND_VISUAL )
+DALI_DEVEL_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 )
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 }
+ { Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, Toolkit::DevelButton::Property::UNSELECTED_VISUAL },
+ { Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, Toolkit::DevelButton::Property::SELECTED_VISUAL },
+ { Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL },
+ { Toolkit::DevelButton::Property::DISABLED_SELECTED_BACKGROUND_VISUAL, Toolkit::DevelButton::Property::DISABLED_SELECTED_VISUAL }
};
+/**
+ * Checks if given map contains a text string
+ */
+bool MapContainsTextString( Property::Map& map )
+{
+ 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()
mTextLabelAlignment( END ),
mAutoRepeating( false ),
mTogglableButton( false ),
+ mTextStringSetFlag( false ),
mInitialAutoRepeatingDelay( 0.0f ),
mNextAutoRepeatingDelay( 0.0f ),
mAnimationTime( 0.0f ),
{
mAutoRepeating = autoRepeating;
- // An autorepeating button can't be a togglable button.
+ // An autorepeating button can't be a toggle button.
if( autoRepeating )
{
- mTogglableButton = false;
-
if( IsSelected() )
{
- SetSelected( false );
+ SetSelected( false ); // UnSelect before switching off Toggle feature.
}
+ mTogglableButton = false;
}
}
return;
}
- // If not on stage the button could have still been set to selected so update 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
OnStateChange( mButtonState ); // Notify derived buttons
PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
// If animation supported then visual removal should be performed after any transition animation has completed.
+ // If Required Visual is not loaded before current visual is removed then a flickering will be evident.
PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
}
void Button::SetLabelText( const std::string& label )
{
- Property::Map labelProperty;
- labelProperty.Insert( "text", label );
- SetupLabel( labelProperty );
+ Self().SetProperty( Toolkit::Button::Property::LABEL, label );
}
std::string Button::GetLabelText() const
{
- Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel );
- if( label )
+ Property::Value value = Self().GetProperty( Toolkit::Button::Property::LABEL );
+
+ Property::Map *labelProperty = value.GetMap();
+
+ std::string textLabel;
+
+ if ( labelProperty )
{
- return label.GetProperty<std::string>( Dali::Toolkit::TextLabel::Property::TEXT );
+ Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
+ if( value )
+ {
+ value->Get( textLabel );
+ }
}
- return std::string();
+
+ return textLabel;
}
-void Button::SetupLabel( const Property::Map& properties )
+void Button::MergeWithExistingLabelProperties( const Property::Map& inMap, Property::Map& outMap )
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "SetupLabel\n");
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "MergeLabelProperties with %d properties\n", inMap.Count() );
- // If we don't have a label yet, create one.
- if( !mLabel )
+ /**
+ * 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 )
{
- // 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 );
+ 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() );
}
- // 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 ) );
+ outMap.Merge( inMap );
- // 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 );
- }
- }
+ // Store if a text string has been supplied.
- RelayoutRequest();
+ mTextStringSetFlag = MapContainsTextString( outMap );
+
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "MergeLabelProperties now has %d properties\n", outMap.Count() );
}
void Button::SetLabelAlignment( Button::Align labelAlignment)
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 );
Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using image URL(%d)\n", index );
if ( !imageUrl.empty() )
{
+ DALI_ASSERT_DEBUG( index != Toolkit::Button::Property::LABEL && "Creating a Image Visual instead of Text Visual " );
buttonVisual = visualFactory.CreateVisual( imageUrl, ImageDimensions() );
}
}
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" );
+ DevelControl::RegisterVisual( *this, index, buttonVisual, DevelControl::IsVisualEnabled( *this, index ), 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);
}
+ PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
+}
+
+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 )
void Button::ButtonUp()
{
+ bool emitSignalsForPressAndReleaseAction = false;
+
if( DEPRESSED == mButtonPressedState )
{
- bool validButtonAction = false;
-
if( mTogglableButton ) // Button up will change state
{
- OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour
+ emitSignalsForPressAndReleaseAction = OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour
}
else
{
{
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::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.
+ // Only events are processed when the button is not disabled
+ auto result( false );
- if( !IsDisabled() && ( 1 == touch.GetPointCount() ) )
+ if( !IsDisabled() )
{
- switch( touch.GetState( 0 ) )
+ if ( 1 == touch.GetPointCount() )
{
- case PointState::DOWN:
- {
- ButtonDown();
- break;
- }
- case PointState::UP:
- {
- ButtonUp();
- break;
- }
- case PointState::INTERRUPTED:
+ switch( touch.GetState( 0 ) )
{
- OnTouchPointInterrupted();
- break;
- }
- case PointState::LEAVE:
- {
- OnTouchPointLeave();
- break;
- }
- case PointState::MOTION:
- case PointState::STATIONARY: // FALLTHROUGH
- {
- // 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;
+ }
+ result = true;
}
-
- return false;
+ return result;
}
bool Button::OnKeyboardEnter()
void Button::OnStageConnection( int depth )
{
DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnStageConnection ptr(%p) \n", this );
+ PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState );
+ SelectRequiredVisual( Toolkit::Button::Property::LABEL );
PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
Control::OnStageConnection( depth ); // Enabled visuals will be put on stage
-
}
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++)
+ for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++ )
{
- Toolkit::Visual::Base visual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( *this, GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
Size visualSize;
if ( visual )
{
visual.GetNaturalSize( visualSize );
- largestForegroundVisual.width = std::max(largestForegroundVisual.width, visualSize.width );
- largestForegroundVisual.height = std::max(largestForegroundVisual.height, visualSize.height );
+ largestProvidedVisual.width = std::max(largestProvidedVisual.width, visualSize.width );
+ largestProvidedVisual.height = std::max(largestProvidedVisual.height, visualSize.height );
+ foreGroundVisualUsed = true;
+ }
+ }
+
+ if ( !foreGroundVisualUsed ) // If foreground visual not supplied then use the background visual to calculate Natural size
+ {
+ for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++ )
+ {
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( *this, GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND] );
+ Size visualSize;
+ if ( visual )
+ {
+ visual.GetNaturalSize( visualSize );
+ largestProvidedVisual.width = std::max(largestProvidedVisual.width, visualSize.width );
+ largestProvidedVisual.height = std::max(largestProvidedVisual.height, visualSize.height );
+ }
}
}
// Get horizontal padding total
- if ( largestForegroundVisual.width > 0 ) // if visual exists
+ if ( largestProvidedVisual.width > 0 ) // if visual exists
{
- size.width += largestForegroundVisual.width + mForegroundPadding.left + mForegroundPadding.right;
+ size.width += largestProvidedVisual.width + mForegroundPadding.left + mForegroundPadding.right;
}
// Get vertical padding total
- if ( largestForegroundVisual.height > 0 )
+ if ( largestProvidedVisual.height > 0 )
{
- size.height += largestForegroundVisual.height + mForegroundPadding.top + mForegroundPadding.bottom;
+ size.height += largestProvidedVisual.height + mForegroundPadding.top + mForegroundPadding.bottom;
}
DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize visual Size(%f,%f)\n",
- largestForegroundVisual.width, largestForegroundVisual.height );
+ largestProvidedVisual.width, largestProvidedVisual.height );
- // Get natural size of label
- if ( 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 );
- 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);
+ if ( visual )
+ {
+ visual.GetNaturalSize( labelSize );
- labelSize.width += mLabelPadding.left + mLabelPadding.right;
- labelSize.height += 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);
- // 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 );
+ 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 );
+ }
}
}
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 );
- }
- }
-
RelayoutRequest();
}
+/**
+ * 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.
+ */
+
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 currentVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND] );
+ Toolkit::Visual::Base currentVisual = DevelControl::GetVisual( *this, GET_VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND] );
- Toolkit::Visual::Base currentBackGroundVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND] );
+ Toolkit::Visual::Base currentBackGroundVisual = DevelControl::GetVisual( *this, GET_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;
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 );
labelVisualPadding = mLabelPadding;
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 )
{
case BEGIN :
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 :
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 :
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 :
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 )
{
- 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 );
}
if ( currentVisual )
{
- DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual size to(%f,%f)\n", visualSize.width, visualSize.height);
+ 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 )
- );
+ 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);
- mLabel.SetPosition( labelPosition.x, labelPosition.y );
- container.Add( mLabel, remainingSpaceForText ); // Currently a TextLabel is used and size can not be set here.
+ 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 );
+
+ textVisual.SetTransformAndSize( textVisualTransform, size );
+ }
}
+ 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 )
{
DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SelectRequiredVisual index(%d) state(%d)\n", visualIndex, mButtonState );
- EnableVisual( visualIndex, true );
+ DevelControl::EnableVisual( *this, visualIndex, true );
}
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 );
- Toolkit::Visual::Base visual = GetVisual( visualIndex );
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( *this, visualIndex );
if( visual )
{
- EnableVisual( visualIndex, false );
+ DevelControl::EnableVisual( *this, visualIndex, false );
}
}
case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: // Legacy Tizen 3.0
{
- GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
+ GetImplementation( button ).CreateVisualsForComponent( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, value, DepthIndex::BACKGROUND );
break;
}
case Toolkit::Button::Property::DISABLED_STATE_IMAGE: // Legacy Tizen 3.0
{
- GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
+ GetImplementation( button ).CreateVisualsForComponent( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, value, DepthIndex::BACKGROUND );
break;
}
case Toolkit::Button::Property::SELECTED_STATE_IMAGE: // Legacy Tizen 3.0
{
- GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, value, DepthIndex::CONTENT );
+ GetImplementation( button ).CreateVisualsForComponent( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, value, DepthIndex::BACKGROUND );
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:
+ case Toolkit::DevelButton::Property::UNSELECTED_VISUAL:
+ case Toolkit::DevelButton::Property::SELECTED_VISUAL:
+ case Toolkit::DevelButton::Property::DISABLED_SELECTED_VISUAL:
+ case Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL:
{
GetImplementation( button ).CreateVisualsForComponent( index, value, DepthIndex::CONTENT );
break;
}
- 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::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL:
+ case Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL:
+ case Toolkit::DevelButton::Property::DISABLED_SELECTED_BACKGROUND_VISUAL:
+ case Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL:
{
GetImplementation( button ).CreateVisualsForComponent( index , value, DepthIndex::BACKGROUND);
break;
case Toolkit::Button::Property::UNSELECTED_COLOR:
{
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 );
+ GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL );
break;
}
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 );
+ GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL );
break;
}
case Toolkit::Button::Property::LABEL_TEXT:
{
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 );
+ GetImplementation( button ).SetLabelText(value.Get< std::string >() );
break;
}
case Toolkit::Button::Property::LABEL:
{
- // Get a Property::Map from the property if possible.
- Property::Map setPropertyMap;
- if( value.Get( setPropertyMap ) )
+ Property::Map outTextVisualProperties;
+ std::string textString;
+
+ if ( value.Get( textString ) )
+ {
+ DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty Setting TextVisual with string[%s]\n", textString.c_str() );
+
+ Property::Map setPropertyMap;
+ setPropertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
+ .Add( Toolkit::TextVisual::Property::TEXT, textString );
+
+ GetImplementation( button ).MergeWithExistingLabelProperties( setPropertyMap, outTextVisualProperties );
+ }
+ else
{
- GetImplementation( button ).SetupLabel( setPropertyMap );
+ // Get a Property::Map from the property if possible.
+ Property::Map* setPropertyMap = value.GetMap();
+ if( setPropertyMap )
+ {
+ TextVisual::ConvertStringKeysToIndexKeys( *setPropertyMap );
+ GetImplementation( button ).MergeWithExistingLabelProperties( *setPropertyMap, outTextVisualProperties );
+ }
+ }
+
+ if( !outTextVisualProperties.Empty() )
+ {
+ GetImplementation( button ).CreateVisualsForComponent( index, outTextVisualProperties, DepthIndex::CONTENT );
+ GetImplementation( button ).RelayoutRequest();
}
break;
}
- case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
+ case Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT:
{
Button::Align labelAlignment(END);
Scripting::GetEnumeration< Button::Align> ( value.Get< std::string >().c_str(),
labelAlignment );
GetImplementation( button ).SetLabelAlignment( labelAlignment );
+ GetImplementation( button ).RelayoutRequest();
+ break;
+ }
+
+ case Toolkit::DevelButton::Property::LABEL_PADDING:
+ {
+ Vector4 padding ( value.Get< Vector4 >() );
+ GetImplementation( button ).SetLabelPadding( Padding( padding.x, padding.y, padding.z, padding.w ) );
+ break;
+ }
+
+ case Toolkit::DevelButton::Property::VISUAL_PADDING:
+ {
+ Vector4 padding ( value.Get< Vector4 >() );
+ GetImplementation( button ).SetForegroundPadding( Padding( padding.x, padding.y, padding.z, padding.w ) );
+ GetImplementation( button ).RelayoutRequest();
break;
}
}
case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
{
- value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::UNSELECTED_VISUAL );
+ value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL );
break;
}
case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
{
- value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::SELECTED_VISUAL );
+ value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL );
break;
}
case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
{
- value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL );
+ value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL );
+ break;
+ }
+
+ case Toolkit::DevelButton::Property::UNSELECTED_VISUAL:
+ case Toolkit::DevelButton::Property::SELECTED_VISUAL:
+ case Toolkit::DevelButton::Property::DISABLED_SELECTED_VISUAL:
+ case Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL:
+ case Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL:
+ case Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL:
+ case Toolkit::DevelButton::Property::DISABLED_SELECTED_BACKGROUND_VISUAL:
+ case Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL:
+ case Toolkit::Button::Property::LABEL:
+ {
+ Property::Map visualProperty;
+ if ( GetImplementation( button ).GetPropertyMapForVisual( propertyIndex, visualProperty ) )
+ {
+ value = visualProperty;
+ }
break;
}
break;
}
- case Toolkit::Button::Property::LABEL:
- {
- Property::Map emptyMap;
- value = emptyMap;
- break;
- }
-
- case Toolkit::Button::Property::LABEL_STRUT_LENGTH:
- {
- value = GetImplementation( button ).GetLabelStrutLength();
- break;
- }
-
- case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
+ case Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT:
{
const char* alignment = Scripting::GetEnumerationName< Button::Align >( GetImplementation( button ).GetLabelAlignment(),
ALIGNMENT_STRING_TABLE,
break;
}
+
+ case Toolkit::DevelButton::Property::LABEL_PADDING:
+ {
+ Padding padding = GetImplementation( button ).GetLabelPadding();
+ value = Vector4( padding.x, padding.y, padding.top, padding.bottom);
+ break;
+ }
+
+ case Toolkit::DevelButton::Property::VISUAL_PADDING:
+ {
+ Padding padding = GetImplementation( button ).GetForegroundPadding();
+ value = Vector4( padding.x, padding.y, padding.top, padding.bottom);
+ }
}
}
// 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 )
+ if ( visualIndex == Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL )
{
mSelectedColor = color;
}
void Button::SetAnimationTime( float animationTime )
{
- // Used by depreciated API
+ // Used by deprecated API
mAnimationTime = animationTime;
}
float Button::GetAnimationTime() const
{
- // Used by depreciated API
+ // Used by deprecated API
return mAnimationTime;
}
void Button::SetUnselectedImage( const std::string& filename )
{
- if( !filename.empty() )
- {
- CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
- }
+ SetBackgroundImage( filename );
}
void Button::SetBackgroundImage( const std::string& filename )
{
if( !filename.empty() )
{
- CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
+ CreateVisualsForComponent( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
+ }
+ else
+ {
+ DevelControl::UnregisterVisual( *this, Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL );
}
}
void Button::SetSelectedImage( const std::string& filename )
{
- if( !filename.empty() )
- {
- CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, filename, DepthIndex::CONTENT );
- }
+ SetSelectedBackgroundImage( filename );
}
void Button::SetSelectedBackgroundImage( const std::string& filename )
{
if( !filename.empty() )
{
- CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
+ CreateVisualsForComponent( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
+ }
+ else
+ {
+ DevelControl::UnregisterVisual( *this, Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL );
}
}
{
if( !filename.empty() )
{
- CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
+ CreateVisualsForComponent( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
}
}
{
if( !filename.empty() )
{
- CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
+ CreateVisualsForComponent( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
}
}
{
if( !filename.empty() )
{
- CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_SELECTED_VISUAL, filename, DepthIndex::CONTENT );
+ CreateVisualsForComponent( Toolkit::DevelButton::Property::DISABLED_SELECTED_VISUAL, filename, DepthIndex::CONTENT );
}
}
-std::string Button::GetUrlForImageVisual( Property::Index index )
+// Used by Deprecated Properties which don't use the Visual Property maps for setting and getting
+std::string Button::GetUrlForImageVisual( const Property::Index index ) const
{
- Toolkit::Visual::Base visual = GetVisual( index );
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( *this, index );
std::string result;
if ( visual )
// Below functions DEPRECATED_1_0.50 - Return empty Actors
+namespace
+{
+std::string GetUrlFromImage( Image& image )
+{
+ ResourceImage resourceImage = ResourceImage::DownCast( image );
+
+ std::string imageUrl;
+
+ if ( resourceImage )
+ {
+ imageUrl = resourceImage.GetUrl();
+ }
+ return imageUrl;
+}
+
+} // namespace
+
+
+void Button::SetButtonImage( Image image )
+{
+ DALI_LOG_WARNING("Button::SetButtonImage @DEPRECATED_1_0.50\n");
+ SetUnselectedImage( GetUrlFromImage( image ) );
+ mSetButtonImage = image;
+}
+
+void Button::SetSelectedImage( Image image )
+{
+ DALI_LOG_WARNING("Button::SetSelectedImage @DEPRECATED_1_0.50\n");
+ SetSelectedImage( GetUrlFromImage( image ) );
+ mSetSelectedImage = image;
+}
+
Actor Button::GetButtonImage() const
{
- DALI_LOG_WARNING("Button::GetButtonImage @DEPRECATED_1_0.50 Returning empty Actor \n");
- return Actor();;
+ // When deprecated ImageView API removed then this button API can be removed too.
+ DALI_LOG_WARNING("Button::GetButtonImage @DEPRECATED_1_0.50\n");
+
+ Actor imageView;
+
+ if ( mSetButtonImage )
+ {
+ imageView = Toolkit::ImageView::New( mSetButtonImage );
+ }
+ else
+ {
+ ResourceImage image = ResourceImage::New( GetUrlForImageVisual( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL ) );
+ imageView = Toolkit::ImageView::New( image );
+ }
+
+ return imageView;
}
Actor Button::GetSelectedImage() const
{
- DALI_LOG_WARNING("Button::GetSelectedImage @DEPRECATED_1_0.50 Returning empty Actor \n");
- return Actor();
+ // When deprecated ImageView API removed then this button API can be removed too.
+ DALI_LOG_WARNING("Button::GetSelectedImage @DEPRECATED_1_0.50\n");
+
+ Actor imageView;
+
+ if ( mSetSelectedImage )
+ {
+ imageView = Toolkit::ImageView::New( mSetSelectedImage );
+ }
+ else
+ {
+ ResourceImage image = ResourceImage::New( GetUrlForImageVisual( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL ) );
+ imageView = Toolkit::ImageView::New( image );
+ }
+ return imageView;
}
} // namespace Internal