2 * Copyright (c) 2018 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-toolkit/devel-api/controls/buttons/button-devel.h>
20 #include <dali/public-api/animation/animation.h>
22 #include "expanding-buttons-impl.h"
25 using namespace Dali::Toolkit;
35 const unsigned int GAP_BETWEEN_BUTTONS = 3;
37 const char* const STYLES_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_Main.png";
38 const char* const TICK_IMAGE_IMAGE = DEMO_IMAGE_DIR "FontStyleButton_OK_02.png";
41 * Unparent the given number of registered controls from the supplied Vector of controls.
43 void ResetControls( std::vector< WeakHandle< Control > > controls, unsigned int numberOfButtons )
45 for( unsigned int index = 0; index < numberOfButtons; index++)
47 Dali::Toolkit::Control control = controls[index].GetHandle();
48 UnparentAndReset( control );
52 } // anonymous namespace
55 Internal::ExpandingButtons::ExpandingButtons()
56 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
57 mStyleButtonsHidden( false )
61 Internal::ExpandingButtons::~ExpandingButtons()
65 Demo::ExpandingButtons Internal::ExpandingButtons::New()
67 IntrusivePtr<Internal::ExpandingButtons> impl = new Internal::ExpandingButtons();
68 Demo::ExpandingButtons handle = Demo::ExpandingButtons( *impl );
73 void ExpandingButtons::OnInitialize()
75 mExpandButton = PushButton::New();
77 mExpandButton.ClickedSignal().Connect( this, &ExpandingButtons::OnExpandButtonClicked );
78 mExpandButton.SetProperty( Button::Property::TOGGLABLE, true );
79 mExpandButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, STYLES_IMAGE ); // Default for Styles
80 mExpandButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TICK_IMAGE_IMAGE );
81 mExpandButton.SetProperty( Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
82 Self().Add( mExpandButton );
85 void ExpandingButtons::OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container )
87 mButtonSize = targetSize;
88 mExpandButton.SetSize( targetSize );
91 void ExpandingButtons::RegisterButton( Dali::Toolkit::Control& control )
93 mExpandingControls.push_back( control );
96 void ExpandingButtons::Expand()
98 if ( !mExpandCollapseAnimation )
100 mExpandCollapseAnimation = Animation::New( 0.2f );
101 mExpandCollapseAnimation.FinishedSignal().Connect( this, &ExpandingButtons::OnExpandAnimationFinished );
104 unsigned int numberOfControls = mExpandingControls.size();
106 for( unsigned int index = 0; index < numberOfControls; index++ )
108 Dali::Toolkit::Control control = mExpandingControls[index].GetHandle();
111 Self().Add( control );
112 AlphaFunction focusedAlphaFunction = AlphaFunction( Vector2 ( 0.32f, 0.08f ), Vector2( 0.38f, 1.72f ) );
113 mExpandCollapseAnimation.AnimateTo( Property( control, Actor::Property::POSITION_X ), mButtonSize.width + ( mButtonSize.width + GAP_BETWEEN_BUTTONS ) * (index) , focusedAlphaFunction );
117 mStyleButtonsHidden = false;
118 mExpandCollapseAnimation.Play();
121 void ExpandingButtons::OnExpandAnimationFinished( Animation& animation )
123 if ( mStyleButtonsHidden )
125 unsigned int numberOfControls = mExpandingControls.size();
126 ResetControls( mExpandingControls, numberOfControls );
132 void ExpandingButtons::Collapse()
134 Demo::ExpandingButtons handle( GetOwner() );
135 mCollapsedSignal.Emit( handle );
137 mStyleButtonsHidden = true;
138 mExpandButton.SetProperty(Button::Property::SELECTED, false );
140 if ( mExpandCollapseAnimation )
142 unsigned int numberOfControls = mExpandingControls.size();
144 for ( unsigned int index = 0; index < numberOfControls; index++ )
146 Dali::Toolkit::Control control = mExpandingControls[index].GetHandle();
149 mExpandCollapseAnimation.AnimateTo( Property( control, Actor::Property::POSITION_X ), 0.0f );
152 mExpandCollapseAnimation.Play();
156 // Hide or show (expand) buttons if expand button pressed
157 bool ExpandingButtons::OnExpandButtonClicked( Toolkit::Button button )
159 if ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>() )
172 Demo::ExpandingButtons::ExpandingButtonsSignalType& ExpandingButtons::CollapsingSignal()
174 return mCollapsedSignal;