X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fradio-button-impl.cpp;h=739972a336ad35e3fe239a0568498a495ae09837;hb=refs%2Fchanges%2F00%2F44400%2F3;hp=b3bcb31d956783adf534680c574850b5244acf38;hpb=306d2f61a1b64179e801fa8a0bb2bd7b4e9dd682;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp index b3bcb31..739972a 100644 --- a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp @@ -21,10 +21,16 @@ // EXTERNAL INCLUDES #include -#include +#include -using namespace Dali; -using namespace Dali::Toolkit::Internal; +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ namespace { @@ -38,8 +44,10 @@ TypeRegistration typeRegistration( typeid( Toolkit::RadioButton ), typeid( Toolk const char* const UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-unselected.png"; const char* const SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-selected.png"; +const char* const DISABLED_UNSELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-unselected-disabled.png"; +const char* const DISABLED_SELECTED_BUTTON_IMAGE_DIR = DALI_IMAGE_DIR "radio-button-selected-disabled.png"; -const Vector3 DISTANCE_BETWEEN_IMAGE_AND_LABEL(5.0f, 0.0f, 0.0f); +const float DISTANCE_BETWEEN_IMAGE_AND_LABEL( 5.0f ); } Dali::Toolkit::RadioButton RadioButton::New() @@ -58,179 +66,118 @@ Dali::Toolkit::RadioButton RadioButton::New() } RadioButton::RadioButton() - : mSelected(false) { - mUnselectedImage = Dali::Image::New( UNSELECTED_BUTTON_IMAGE_DIR ); - mSelectedImage = Dali::Image::New( SELECTED_BUTTON_IMAGE_DIR ); - - mRadioIcon = Dali::ImageActor::New( mUnselectedImage ); + SetTogglableButton(true); } RadioButton::~RadioButton() { } -void RadioButton::SetLabel(const std::string& label) +void RadioButton::OnButtonInitialize() { - // TODO + Actor self = Self(); + + // Wrap size of radio button around all its children + self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS ); + + SetUnselectedImage( UNSELECTED_BUTTON_IMAGE_DIR ); + SetSelectedImage( SELECTED_BUTTON_IMAGE_DIR ); + SetDisabledImage( DISABLED_UNSELECTED_BUTTON_IMAGE_DIR ); + SetDisabledSelectedImage( DISABLED_SELECTED_BUTTON_IMAGE_DIR ); RelayoutRequest(); } -void RadioButton::SetLabel(Actor label) +void RadioButton::OnButtonUp() { - if( mLabel != label ) + if( ButtonDown == GetState() ) { - if( mLabel ) + // Don't allow selection on an already selected radio button + if( !IsSelected() ) { - mRadioIcon.Remove( mLabel ); + SetSelected( !IsSelected() ); } + } +} + +void RadioButton::OnLabelSet() +{ + Actor& label = GetLabelActor(); + + if( label ) + { + label.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - if( label ) + // Radio button width is FIT_TO_CHILDREN, so the label must have a sensible policy to fill out the space + if( label.GetResizePolicy( Dimension::WIDTH ) == ResizePolicy::FILL_TO_PARENT ) { - label.SetParentOrigin( ParentOrigin::CENTER_RIGHT ); - label.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - label.MoveBy( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); - mRadioIcon.Add( label ); + label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::WIDTH ); } - mLabel = label; - - RelayoutRequest(); + if( IsSelected() && GetSelectedImage() ) + { + label.SetX( GetSelectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + else if( GetUnselectedImage() ) + { + label.SetX( GetUnselectedImage().GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + else + { + label.SetX( DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } } } -Actor RadioButton::GetLabel() const +void RadioButton::OnSelected() { - return mLabel; -} + Actor& label = GetLabelActor(); -void RadioButton::SetSelected(bool selected) -{ - if( mSelected != selected ) + PaintState paintState = GetPaintState(); + switch( paintState ) { - if( selected ) + case UnselectedState: { Actor parent = Self().GetParent(); if( parent ) { for( unsigned int i = 0; i < parent.GetChildCount(); ++i ) { - Dali::Toolkit::RadioButton rbChild = Dali::Toolkit::RadioButton::DownCast(parent.GetChildAt(i)); - - if( rbChild ) + Dali::Toolkit::RadioButton radioButtonChild = Dali::Toolkit::RadioButton::DownCast( parent.GetChildAt( i ) ); + if( radioButtonChild && radioButtonChild != Self() ) { - rbChild.SetSelected(false); + radioButtonChild.SetSelected( false ); } } } - mSelected = true; - mRadioIcon.SetImage(mSelectedImage); - } - else - { - mSelected = false; - mRadioIcon.SetImage(mUnselectedImage); + Actor& selectedImage = GetSelectedImage(); + if( label && selectedImage ) + { + label.SetX( selectedImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + break; } - - // Raise state changed signal - Toolkit::RadioButton handle( GetOwner() ); - mStateChangedSignal.Emit( handle, mSelected ); - - RelayoutRequest(); - } -} - -bool RadioButton::IsSelected()const -{ - return mSelected; -} - -void RadioButton::ToggleState() -{ - SetSelected(!mSelected); -} - -void RadioButton::OnRelayout( const Vector2& /*size*/, ActorSizeContainer& container ) -{ - Vector3 newSize( mRadioIcon.GetNaturalSize() ); - - if( mLabel ) - { - // Offset the label from the radio button image - newSize.width += DISTANCE_BETWEEN_IMAGE_AND_LABEL.width; - - // Find the size of the control using size negotiation - Vector3 actorNaturalSize( mLabel.GetNaturalSize() ); - Control::Relayout( mLabel, Vector2( actorNaturalSize.width, actorNaturalSize.height ), container ); - - Vector3 actorSize( mLabel.GetSize() ); - newSize.width += actorSize.width; - newSize.height = std::max( newSize.height, actorSize.height ); - } - - Self().SetSize( newSize ); -} - -void RadioButton::OnInitialize() -{ - mRadioIcon.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - mRadioIcon.SetParentOrigin( ParentOrigin::CENTER_LEFT ); - Self().Add( mRadioIcon ); - - RelayoutRequest(); -} - -void RadioButton::OnButtonUp() -{ - // Don't allow selection on an already selected radio button - if( !mSelected ) - { - ToggleState(); - } -} - -void RadioButton::SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value) -{ - Toolkit::RadioButton radioButton = Toolkit::RadioButton::DownCast( Dali::BaseHandle( object ) ); - - if( radioButton ) - { - RadioButton& radioButtonImpl( GetImplementation( radioButton ) ); - - if ( propertyIndex == Toolkit::Button::PROPERTY_TOGGLED ) + case SelectedState: { - radioButtonImpl.SetSelected( value.Get< bool >( ) ); + Actor& buttonImage = GetUnselectedImage(); + if( label && buttonImage ) + { + label.SetX( buttonImage.GetNaturalSize().width + DISTANCE_BETWEEN_IMAGE_AND_LABEL ); + } + break; } - else if ( propertyIndex == Toolkit::Button::PROPERTY_LABEL_ACTOR ) + default: { - radioButtonImpl.SetLabel( Scripting::NewActor( value.Get< Property::Map >( ) ) ); + break; } } } -Property::Value RadioButton::GetProperty(BaseObject* object, Property::Index propertyIndex) -{ - Property::Value value; +} // namespace Internal - Toolkit::RadioButton radioButton = Toolkit::RadioButton::DownCast( Dali::BaseHandle(object) ); +} // namespace Toolkit - if( radioButton ) - { - RadioButton& radioButtonImpl( GetImplementation( radioButton ) ); - - if ( propertyIndex == Toolkit::Button::PROPERTY_TOGGLED ) - { - value = radioButtonImpl.mSelected; - } - else if ( propertyIndex == Toolkit::Button::PROPERTY_LABEL_ACTOR ) - { - Property::Map map; - Scripting::CreatePropertyMap( radioButtonImpl.mLabel, map ); - value = map; - } - } - - return value; -} +} // namespace Dali