(ScrollView) Inlined one line Getters/Setters
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scroll-view / scroll-base-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SCROLL_BASE_H
2 #define DALI_TOOLKIT_INTERNAL_SCROLL_BASE_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 // TODO - Replace list with dali-vector.h
23 #include <dali/public-api/animation/constraint.h>
24 #include <list>
25
26 // INTERNAL INCLUDES
27
28 #include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
29 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
30
31 namespace Dali
32 {
33 namespace Toolkit
34 {
35 namespace Internal
36 {
37 class ScrollBase;
38
39 typedef IntrusivePtr<Actor>   ActorPtr;
40 typedef std::list<Constraint> ConstraintStack;
41
42 /**
43  * ScrollBase represents a set of properties (time, position
44  * scale etc.) that constrain a set of actors.
45  */
46 class ScrollBase : public Scrollable
47 {
48 public:
49   struct ActorInfo : public Dali::RefObject
50   {
51     /**
52      * ActorInfo constructor
53      * @param[in] actor The actor that this ActorInfo represents.
54      */
55     ActorInfo(Actor actor)
56     : mActor(actor)
57     {
58     }
59
60     /**
61      * ActorInfo destructor
62      * removes scrollview-related constraints only.
63      */
64     ~ActorInfo()
65     {
66       RemoveConstraints();
67     }
68
69     /**
70      * Apply a constraint to this actor
71      * The constraint will be applied to the actor,
72      * and the ActorInfo will keep track of this constraint.
73      * @param[in] constraint The constraint to apply to the actor
74      */
75     void ApplyConstraint(Constraint constraint)
76     {
77       Constraint clone = constraint.Clone(mActor);
78       clone.Apply();
79       mConstraints.push_back(clone);
80     }
81
82     /**
83      * Remove constraints from this actor.
84      * All of the constraints that have been applied to the
85      * actor via this ActorInfo will be removed.
86      */
87     void RemoveConstraints()
88     {
89       std::vector<Constraint>::iterator it  = mConstraints.begin();
90       std::vector<Constraint>::iterator end = mConstraints.end();
91       for(; it != end; ++it)
92       {
93         it->Remove();
94       }
95       mConstraints.clear();
96     }
97
98     Actor                   mActor;       ///< The Actor that this ActorInfo represents.
99     std::vector<Constraint> mConstraints; ///< A list keeping track of constraints applied to the actor via this delegate.
100   };
101
102   typedef IntrusivePtr<ActorInfo>            ActorInfoPtr;
103   typedef std::vector<ActorInfoPtr>          ActorInfoContainer;
104   typedef ActorInfoContainer::iterator       ActorInfoIter;
105   typedef ActorInfoContainer::const_iterator ActorInfoConstIter;
106
107 public:
108   /**
109    * Sets the delay in seconds.
110    * This delay affects the animation timing for all
111    * Bound Actors.
112    *
113    * @param[in] delay The delay in seconds.
114    */
115   void SetDelay(float delay)
116   {
117     mDelay = delay;
118   }
119
120   /**
121    * Gets the current delay in seconds.
122    *
123    * @return The delay in seconds.
124    */
125   float GetDelay() const
126   {
127     return mDelay;
128   }
129
130 public:
131   /**
132    * Sets ScrollBase Parent
133    *
134    * @param[in] parent The parent that this ScrollBase belongs to.
135    */
136   void SetParent(ScrollBase* parent);
137
138   /**
139    * Bind Actor to this scroll view/group.
140    * Once Bound, this scroll view/group will affect the actor (child)
141    *
142    * @param[in] child The actor to be bound.
143    */
144   void BindActor(Actor child);
145
146   /**
147    * Unbind Actor from this scroll view/group
148    * Once Unbound, this scroll view/group will not affect the actor
149    *
150    * @note this does not remove the child from the ScrollView container
151    *
152    * @param[in] child The actor to be unbound
153    */
154   void UnbindActor(Actor child);
155
156   /**
157    * Searches associated ScrollBases for the Actor, and attempts to Unbind
158    * systematically this Actor from the ScrollView or Groups attached.
159    *
160    * @param[in] child The actor to be unbound.
161    */
162   virtual void FindAndUnbindActor(Actor child);
163
164   /**
165    * Applies constraint to the bound actors within this ScrollView/Group only.
166    *
167    * @param[in] constraint, the constraint to apply to these bound actors and future
168    * ones.
169    */
170   void ApplyConstraintToBoundActors(Constraint constraint);
171
172   /**
173    * Removes all constraints from the bound actors within this ScrollView/Group only.
174    */
175   void RemoveConstraintsFromBoundActors();
176
177 protected:
178   static const char* const SCROLL_DOMAIN_OFFSET_PROPERTY_NAME;
179
180 protected:
181   /**
182    * Removed default costructor.
183    */
184   ScrollBase() = delete;
185
186   /**
187    * @brief Construct a new ScrollBase.
188    *
189    * @param[in] behaviourFlags Flags to enable
190    */
191   ScrollBase(ControlBehaviour behaviourFlags);
192
193 protected:
194   ScrollBase* mParent; ///< Pointer to ScrollBase parent, if exists.
195
196 private:
197   float              mDelay;           ///< delay in seconds.
198   ConstraintStack    mConstraintStack; ///< The list of constraints to apply to any actors
199   ActorInfoContainer mBoundActors;     ///< The list of actors that have been bound to this ScrollBase.
200 };
201
202 } // namespace Internal
203
204 } // namespace Toolkit
205
206 } // namespace Dali
207
208 #endif // DALI_TOOLKIT_INTERNAL_SCROLL_BASE_H