Implement vertical scroll animation on text input
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-vertical-scroller.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
20
21 // EXTERNAL INCLUDES
22
23 // INTERNAL INCLUDES
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace
32 {
33
34 const float DEFAULT_VERTICAL_SCROLL_DURATION(0.15f);     ///< Duration to complete scroll animation
35
36 } // namespace
37
38 namespace Text
39 {
40
41 TextVerticalScrollerPtr TextVerticalScroller::New()
42 {
43   TextVerticalScrollerPtr textScroller( new TextVerticalScroller() );
44   return textScroller;
45 }
46
47 TextVerticalScroller::TextVerticalScroller()
48 : mDuration( DEFAULT_VERTICAL_SCROLL_DURATION )
49 {
50 }
51
52 TextVerticalScroller::~TextVerticalScroller()
53 {
54 }
55
56 void TextVerticalScroller::CheckStartAnimation( Actor& sourceActor, float x, float y, float scrollAmount )
57 {
58   if ( Equals( scrollAmount, 0.0f, Math::MACHINE_EPSILON_1 ) )
59   {
60     // scroll animation isn't required, set position only
61     if( mScrollAnimation && mScrollAnimation.GetState() == Animation::PLAYING )
62     {
63       mScrollAnimation.Clear();
64     }
65     sourceActor.SetPosition( x, y );
66     return;
67   }
68   float toY = y + scrollAmount;
69   // Either actor or scroll area is changed, so restart animation
70   if( mScrollAnimation )
71   {
72     mScrollAnimation.Clear();
73   }
74   else
75   {
76     // Create animation at first
77     mScrollAnimation = Animation::New( mDuration );
78   }
79   mScrollingActor = sourceActor;
80   mScrollTo = toY;
81
82   // Set animation attribute
83   sourceActor.SetPosition( x, y );
84   mScrollAnimation.AnimateTo( Property(sourceActor, Actor::Property::POSITION_Y), mScrollTo, AlphaFunction::EASE_OUT_SINE );
85   mScrollAnimation.Play();
86 }
87
88 void TextVerticalScroller::SetDuration( float duration )
89 {
90   mDuration = duration;
91 }
92
93 } // namespace Text
94
95 } // namespace Toolkit
96
97 } // namespace Dali