2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <dali-toolkit/dali-toolkit.h>
18 #include <dali-toolkit/devel-api/controls/control-devel.h>
19 #include <dali/public-api/animation/animation.h>
21 #include "expanding-buttons-impl.h"
24 using namespace Dali::Toolkit;
34 const unsigned int GAP_BETWEEN_BUTTONS = 3;
36 const char* const STYLES_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_Main.png";
37 const char* const TICK_IMAGE_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_OK_02.png";
40 * Unparent the given number of registered controls from the supplied Vector of controls.
42 void ResetControls( std::vector< WeakHandle< Control > > controls, unsigned int numberOfButtons )
44 for( unsigned int index = 0; index < numberOfButtons; index++)
46 Dali::Toolkit::Control control = controls[index].GetHandle();
47 UnparentAndReset( control );
51 } // anonymous namespace
54 Internal::ExpandingButtons::ExpandingButtons()
55 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
56 mStyleButtonsHidden( false )
60 Internal::ExpandingButtons::~ExpandingButtons()
64 Demo::ExpandingButtons Internal::ExpandingButtons::New()
66 IntrusivePtr<Internal::ExpandingButtons> impl = new Internal::ExpandingButtons();
67 Demo::ExpandingButtons handle = Demo::ExpandingButtons( *impl );
72 void ExpandingButtons::OnInitialize()
74 mExpandButton = PushButton::New();
76 mExpandButton.ClickedSignal().Connect( this, &ExpandingButtons::OnExpandButtonClicked );
77 mExpandButton.SetProperty( Button::Property::TOGGLABLE, true );
78 mExpandButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, STYLES_IMAGE ); // Default for Styles
79 mExpandButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, TICK_IMAGE_IMAGE );
80 mExpandButton.SetProperty( Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
81 Self().Add( mExpandButton );
84 void ExpandingButtons::OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container )
86 mButtonSize = targetSize;
87 mExpandButton.SetSize( targetSize );
90 void ExpandingButtons::RegisterButton( Dali::Toolkit::Control& control )
92 mExpandingControls.push_back( control );
95 void ExpandingButtons::Expand()
97 if ( !mExpandCollapseAnimation )
99 mExpandCollapseAnimation = Animation::New( 0.2f );
100 mExpandCollapseAnimation.FinishedSignal().Connect( this, &ExpandingButtons::OnExpandAnimationFinished );
103 unsigned int numberOfControls = mExpandingControls.size();
105 for( unsigned int index = 0; index < numberOfControls; index++ )
107 Dali::Toolkit::Control control = mExpandingControls[index].GetHandle();
110 Self().Add( control );
111 AlphaFunction focusedAlphaFunction = AlphaFunction( Vector2 ( 0.32f, 0.08f ), Vector2( 0.38f, 1.72f ) );
112 mExpandCollapseAnimation.AnimateTo( Property( control, Actor::Property::POSITION_X ), mButtonSize.width + ( mButtonSize.width + GAP_BETWEEN_BUTTONS ) * (index) , focusedAlphaFunction );
116 mStyleButtonsHidden = false;
117 mExpandCollapseAnimation.Play();
120 void ExpandingButtons::OnExpandAnimationFinished( Animation& animation )
122 if ( mStyleButtonsHidden )
124 unsigned int numberOfControls = mExpandingControls.size();
125 ResetControls( mExpandingControls, numberOfControls );
131 void ExpandingButtons::Collapse()
133 Demo::ExpandingButtons handle( GetOwner() );
134 mCollapsedSignal.Emit( handle );
136 mStyleButtonsHidden = true;
137 mExpandButton.SetProperty(Button::Property::SELECTED, false );
139 if ( mExpandCollapseAnimation )
141 unsigned int numberOfControls = mExpandingControls.size();
143 for ( unsigned int index = 0; index < numberOfControls; index++ )
145 Dali::Toolkit::Control control = mExpandingControls[index].GetHandle();
148 mExpandCollapseAnimation.AnimateTo( Property( control, Actor::Property::POSITION_X ), 0.0f );
151 mExpandCollapseAnimation.Play();
155 // Hide or show (expand) buttons if expand button pressed
156 bool ExpandingButtons::OnExpandButtonClicked( Toolkit::Button button )
158 if ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>() )
171 Demo::ExpandingButtons::ExpandingButtonsSignalType& ExpandingButtons::CollapsingSignal()
173 return mCollapsedSignal;