-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
#include "push-button-default-painter-impl.h"
#include <dali-toolkit/public-api/controls/text-view/text-view.h>
+#include <dali-toolkit/internal/controls/relayout-helper.h>
namespace Dali
{
const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
+const float TEXT_PADDING = 12.0f;
+
// Helper function used to cast a ButtonPainter to PushButtonDefaultPainter
PushButtonDefaultPainterPtr GetPushButtonPainter( Dali::Toolkit::Internal::ButtonPainterPtr painter )
{
return static_cast<PushButtonDefaultPainter*>( painter.Get() );
}
+/**
+ * Find the first image actor in the actor hierarchy
+ */
+ImageActor FindImageActor( Actor root )
+{
+ ImageActor imageActor = ImageActor::DownCast( root );
+ if( !imageActor && root )
+ {
+ for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i )
+ {
+ ImageActor childImageActor = FindImageActor( root.GetChildAt( i ) );
+ if( childImageActor )
+ {
+ return childImageActor;
+ }
+ }
+ }
+
+ return imageActor;
+}
+
+
} // unnamed namespace
Dali::Toolkit::PushButton PushButton::New()
DoClickAction(attributes);
}
+Vector3 PushButton::GetNaturalSize()
+{
+ Vector3 size = Control::GetNaturalSize();
+
+ const bool widthIsZero = EqualsZero( size.width );
+ const bool heightIsZero = EqualsZero( size.height );
+
+ if( widthIsZero || heightIsZero )
+ {
+ // If background and background not scale9 try get size from that
+ ImageActor imageActor = FindImageActor( mButtonImage );
+ if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
+ {
+ Vector3 imageSize = RelayoutHelper::GetNaturalSize( imageActor );
+
+ if( widthIsZero )
+ {
+ size.width = imageSize.width;
+ }
+
+ if( heightIsZero )
+ {
+ size.height = imageSize.height;
+ }
+ }
+
+ ImageActor backgroundImageActor = FindImageActor( mBackgroundImage );
+ if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH )
+ {
+ Vector3 imageSize = RelayoutHelper::GetNaturalSize( backgroundImageActor );
+
+ if( widthIsZero )
+ {
+ size.width = std::max( size.width, imageSize.width );
+ }
+
+ if( heightIsZero )
+ {
+ size.height = std::max( size.height, imageSize.height );
+ }
+ }
+
+ // If label, test against it's size
+ Toolkit::TextView textView = Toolkit::TextView::DownCast( mLabel );
+ if( textView )
+ {
+ Vector3 textViewSize = textView.GetNaturalSize();
+
+ if( widthIsZero )
+ {
+ size.width = std::max( size.width, textViewSize.width + TEXT_PADDING * 2.0f );
+ }
+
+ if( heightIsZero )
+ {
+ size.height = std::max( size.height, textViewSize.height + TEXT_PADDING * 2.0f );
+ }
+ }
+ }
+
+ return size;
+}
+
void PushButton::DoClickAction(const PropertyValueContainer& attributes)
{
// Prevents the button signals from doing a recursive loop by sending an action