- Vector3 labelNaturalSize = label.GetNaturalSize();
- labelSize.width = labelNaturalSize.width + mLabelPadding.left + mLabelPadding.right;
- labelSize.height = labelNaturalSize.height + mLabelPadding.top + mLabelPadding.bottom;
- }
-
- if( icon )
- {
- Vector3 iconNaturalSize = icon.GetNaturalSize();
- iconSize.width = iconNaturalSize.width + mIconPadding.left + mIconPadding.right;
- iconSize.height = iconNaturalSize.height + mIconPadding.top + mIconPadding.bottom;
-
- switch( mIconAlignment )
- {
- case LEFT:
- case RIGHT:
- {
- size.width = labelSize.width + iconSize.width;
- size.height = std::max( labelSize.height, iconSize.height );
- break;
- }
- case TOP:
- case BOTTOM:
- {
- size.width = std::max( labelSize.width, iconSize.width );
- size.height = labelSize.height + iconSize.height;
- break;
- }
- }
- }
- else
- {
- // No icon, so size is the same as label size.
- // (If there is no label this is zero).
- size = labelSize;
- }
- }
- else
- {
- // Check Image and Background image and use the largest size as the control's Natural size.
- SizeOfActorIfLarger( GetUnselectedImage(), size );
- SizeOfActorIfLarger( GetBackgroundImage(), size );
- }
-
- return size;
-}
-
-void PushButton::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
-{
- ConfigureSizeNegotiation();
-}
-
-void PushButton::ConfigureSizeNegotiation()
-{
- std::vector< Actor > images;
- images.reserve( 7 );
-
- images.push_back( GetUnselectedImage() );
- images.push_back( GetSelectedImage() );
- images.push_back( GetSelectedBackgroundImage() );
- images.push_back( GetBackgroundImage() );
- images.push_back( GetDisabledImage() );
- images.push_back( GetDisabledSelectedImage() );
- images.push_back( GetDisabledBackgroundImage() );
-
- Actor label = GetLabelActor();
-
- for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
- {
- ConfigureSizeNegotiationDimension( static_cast< Dimension::Type >( 1 << i ), images, label );
- }
-
- // Add any vertical padding directly to the actors.
- Actor icon = GetDecoration( UNSELECTED_DECORATION );
- Actor selectedIcon = GetDecoration( SELECTED_DECORATION );
- bool iconExists = icon || selectedIcon;
-
- if( label )
- {
- label.SetPadding( mLabelPadding );
- }
- if( icon )
- {
- icon.SetPadding( mIconPadding );
- }
- if( selectedIcon )
- {
- selectedIcon.SetPadding( mIconPadding );
- }
-
- // Calculate and apply horizontal alignments and offsets
- // to text and icon (depending on existence).
- Vector3 iconPosition( Vector3::ZERO );
- Vector3 labelPosition( Vector3::ZERO );
- Vector3 iconAnchoring( AnchorPoint::CENTER );
- Vector3 labelAnchoring( AnchorPoint::CENTER );
- std::string horizontalLabelAlignment = "CENTER";
- std::string verticalLabelAlignment = "CENTER";
-
- if( iconExists && label )
- {
- // There is an icon and a label to lay out.
- switch( mIconAlignment )
- {
- case LEFT:
- {
- iconPosition.x = mIconPadding.left;
- labelPosition.x = -mLabelPadding.right;
- iconAnchoring = AnchorPoint::CENTER_LEFT;
- labelAnchoring = AnchorPoint::CENTER_RIGHT;
- horizontalLabelAlignment = "END";
- break;
- }
- case RIGHT:
- {
- iconPosition.x = -mIconPadding.right;
- labelPosition.x = mLabelPadding.left;
- iconAnchoring = AnchorPoint::CENTER_RIGHT;
- labelAnchoring = AnchorPoint::CENTER_LEFT;
- horizontalLabelAlignment = "BEGIN";
- break;
- }
- case TOP:
- {
- iconPosition.y = mIconPadding.top;
- labelPosition.y = -mLabelPadding.bottom;
- iconAnchoring = AnchorPoint::TOP_CENTER;
- labelAnchoring = AnchorPoint::BOTTOM_CENTER;
- verticalLabelAlignment = "BOTTOM";
- break;
- }
- case BOTTOM:
- {
- iconPosition.y = -mIconPadding.bottom;
- labelPosition.y = mLabelPadding.top;
- iconAnchoring = AnchorPoint::BOTTOM_CENTER;
- labelAnchoring = AnchorPoint::TOP_CENTER;
- verticalLabelAlignment = "TOP";
- break;
- }