+Vector3 PushButton::GetNaturalSize()
+{
+ Vector3 size;
+
+ // If label, test against it's size
+ Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( GetLabel() );
+ if( label )
+ {
+ size.width = std::max( size.width, label.GetRelayoutSize( Dimension::WIDTH ) );
+ size.height = std::max( size.height, label.GetRelayoutSize( Dimension::HEIGHT ) );
+ }
+ else
+ {
+ // Check Image and Background image and use the largest size as the control's Natural size.
+ SizeOfActorIfLarger( GetButtonImage(), 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( GetButtonImage() );
+ images.push_back( GetSelectedImage() );
+ images.push_back( GetSelectedBackgroundImage() );
+ images.push_back( GetBackgroundImage() );
+ images.push_back( GetDisabledImage() );
+ images.push_back( GetDisabledSelectedImage() );
+ images.push_back( GetDisabledBackgroundImage() );
+
+ Actor label = GetLabel();
+
+ for( unsigned int i = 0; i < Dimension::DIMENSION_COUNT; ++i )
+ {
+ ConfigureSizeNegotiationDimension( static_cast< Dimension::Type >( 1 << i ), images, label );
+ }
+
+ if( label )
+ {
+ Padding padding;
+
+ if( label.GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::USE_NATURAL_SIZE )
+ {
+ padding.left = TEXT_PADDING;
+ padding.right = TEXT_PADDING;
+ }
+
+ if( label.GetResizePolicy( Dimension::HEIGHT ) == ResizePolicy::USE_NATURAL_SIZE )
+ {
+ padding.top = TEXT_PADDING;
+ padding.bottom = TEXT_PADDING;
+ }
+
+ label.SetPadding( padding );
+ }
+}
+
+void PushButton::ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label )
+{
+ ResizePolicy::Type imageResizePolicy = ResizePolicy::FILL_TO_PARENT;
+ ResizePolicy::Type labelResizePolicy = ResizePolicy::FILL_TO_PARENT;
+
+ switch( Self().GetResizePolicy( dimension ) )
+ {
+ case ResizePolicy::FIT_TO_CHILDREN:
+ {
+ imageResizePolicy = labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
+ break;
+ }
+ case ResizePolicy::USE_NATURAL_SIZE:
+ {
+ if( label )
+ {
+ labelResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
+ }
+ else
+ {
+ imageResizePolicy = ResizePolicy::USE_NATURAL_SIZE;
+ }
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+
+ if( label )
+ {
+ label.SetResizePolicy( labelResizePolicy, dimension );
+ }
+
+ for( std::vector< Actor >::const_iterator it = images.begin(), itEnd = images.end(); it != itEnd; ++it )
+ {
+ Actor actor = *it;
+ if( actor )
+ {
+ actor.SetResizePolicy( imageResizePolicy, dimension );
+ }
+ }
+}
+