(TextController) Reformatted to reduce LOC
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-vertical-scroller.cpp
1 /*
2  * Copyright (c) 2021 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 namespace Toolkit
28 {
29 namespace
30 {
31 const float DEFAULT_VERTICAL_SCROLL_DURATION(0.15f); ///< Duration to complete scroll animation
32
33 } // namespace
34
35 namespace Text
36 {
37 TextVerticalScrollerPtr TextVerticalScroller::New()
38 {
39   TextVerticalScrollerPtr textScroller(new TextVerticalScroller());
40   return textScroller;
41 }
42
43 TextVerticalScroller::TextVerticalScroller()
44 : mDuration(DEFAULT_VERTICAL_SCROLL_DURATION),
45   mScrollTo(0.0f)
46 {
47 }
48
49 TextVerticalScroller::~TextVerticalScroller()
50 {
51 }
52
53 void TextVerticalScroller::CheckStartAnimation(Actor& sourceActor, float x, float y, float scrollAmount)
54 {
55   if(Equals(scrollAmount, 0.0f, Math::MACHINE_EPSILON_1))
56   {
57     // scroll animation isn't required, set position only
58     if(mScrollAnimation && mScrollAnimation.GetState() == Animation::PLAYING)
59     {
60       mScrollAnimation.Clear();
61     }
62     sourceActor.SetProperty(Actor::Property::POSITION, Vector2(x, y));
63     return;
64   }
65   float toY = y + scrollAmount;
66   // Either actor or scroll area is changed, so restart animation
67   if(mScrollAnimation)
68   {
69     mScrollAnimation.Clear();
70   }
71   else
72   {
73     // Create animation at first
74     mScrollAnimation = Animation::New(mDuration);
75   }
76   mScrollingActor = sourceActor;
77   mScrollTo       = toY;
78
79   // Set animation attribute
80   sourceActor.SetProperty(Actor::Property::POSITION, Vector2(x, y));
81   mScrollAnimation.AnimateTo(Property(sourceActor, Actor::Property::POSITION_Y), mScrollTo, AlphaFunction::EASE_OUT_SINE);
82   mScrollAnimation.Play();
83 }
84
85 void TextVerticalScroller::SetDuration(float duration)
86 {
87   mDuration = duration;
88 }
89
90 } // namespace Text
91
92 } // namespace Toolkit
93
94 } // namespace Dali