[Tizen] Fixed actor relayout dimension dependencies
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / custom-actor-internal.h
1 #ifndef DALI_INTERNAL_CUSTOM_ACTOR_H
2 #define DALI_INTERNAL_CUSTOM_ACTOR_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 // INTERNAL INCLUDES
22 #include <dali/internal/event/actors/actor-declarations.h>
23 #include <dali/internal/event/actors/actor-impl.h>
24 #include <dali/public-api/actors/custom-actor.h>
25 #include <dali/public-api/animation/animation.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class CustomActor : public Actor
32 {
33 public:
34   /**
35    * Create a new custom actor.
36    * @return A smart-pointer to the newly allocated Actor.
37    */
38   static CustomActorPtr New(CustomActorImpl& extension);
39
40   /**
41    * Retrieve the custom actor implementation.
42    * @return The implementation, or an invalid pointer if no implementation was set.
43    */
44   CustomActorImpl& GetImplementation()
45   {
46     return *mImpl;
47   }
48
49   /**
50    * Retrieve the custom actor implementation.
51    * @return The implementation, or an invalid pointer if no implementation was set.
52    */
53   const CustomActorImpl& GetImplementation() const
54   {
55     return *mImpl;
56   }
57
58   /**
59    * Get the type info associated with this object.
60    *
61    * @return The type info
62    */
63   Dali::TypeInfo GetTypeInfo();
64
65 protected:
66   /**
67    * A reference counted object may only be deleted by calling Unreference()
68    */
69   ~CustomActor() override;
70
71 private:
72   /**
73    * @copydoc Internal::Actor::OnSceneConnectionExternal
74    */
75   void OnSceneConnectionExternal(int32_t depth) override
76   {
77     mImpl->OnSceneConnection(depth);
78   }
79
80   /**
81    * @copydoc Internal::Actor::OnSceneDisconnectionExternal
82    */
83   void OnSceneDisconnectionExternal() override
84   {
85     mImpl->OnSceneDisconnection();
86   }
87
88   /**
89    * @copydoc Internal::Actor::OnChildAdd
90    */
91   void OnChildAdd(Actor& child) override
92   {
93     Dali::Actor handle(&child);
94     mImpl->OnChildAdd(handle);
95   }
96
97   /**
98    * @copydoc Internal::Actor::OnChildRemove
99    */
100   void OnChildRemove(Actor& child) override
101   {
102     Dali::Actor handle(&child);
103     mImpl->OnChildRemove(handle);
104   }
105
106   /**
107    * @copydoc Internal::Actor::OnPropertySet
108    */
109   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override
110   {
111     mImpl->OnPropertySet(index, propertyValue);
112   }
113
114   /**
115    * @copydoc Internal::Actor::OnSizeSet
116    */
117   void OnSizeSet(const Vector3& targetSize) override
118   {
119     mImpl->OnSizeSet(targetSize);
120   }
121
122   /**
123    * @copydoc Internal::Actor::OnSizeAnimation
124    */
125   void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override
126   {
127     Dali::Animation animationHandle(&animation);
128     mImpl->OnSizeAnimation(animationHandle, targetSize);
129   }
130
131   /**
132    * @copydoc Internal::Actor::OnRelayout
133    */
134   void OnRelayout(const Vector2& size, RelayoutContainer& container) override
135   {
136     mImpl->OnRelayout(size, container);
137   }
138
139   /**
140    * @copydoc Internal::Actor::OnSetResizePolicy
141    */
142   void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override
143   {
144     mImpl->OnSetResizePolicy(policy, dimension);
145   }
146
147   /**
148    * @copydoc Internal::Actor::GetNaturalSize
149    */
150   Vector3 GetNaturalSize() const override
151   {
152     return mImpl->GetNaturalSize();
153   }
154
155   /**
156    * @copydoc Internal::Actor::CalculateChildSize
157    */
158   float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override
159   {
160     return mImpl->CalculateChildSize(child, dimension);
161   }
162
163   /**
164    * @copydoc Internal::Actor::GetHeightForWidth
165    */
166   float GetHeightForWidth(float width) override
167   {
168     return mImpl->GetHeightForWidth(width);
169   }
170
171   /**
172    * @copydoc Internal::Actor::GetWidthForHeight
173    */
174   float GetWidthForHeight(float height) override
175   {
176     return mImpl->GetWidthForHeight(height);
177   }
178
179   /**
180    * @copydoc Internal::Actor::RelayoutDependentOnChildren
181    */
182   bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override
183   {
184     return mImpl->RelayoutDependentOnChildren(dimension);
185   }
186
187   /**
188    * @copydoc Internal::Actor::OnCalculateRelayoutSize
189    */
190   void OnCalculateRelayoutSize(Dimension::Type dimension) override
191   {
192     return mImpl->OnCalculateRelayoutSize(dimension);
193   }
194
195   /**
196    * @copydoc Internal::Actor::OnLayoutNegotiated
197    */
198   void OnLayoutNegotiated(float size, Dimension::Type dimension) override
199   {
200     return mImpl->OnLayoutNegotiated(size, dimension);
201   }
202
203   /**
204    * Private constructor; see also CustomActor::New()
205    */
206   CustomActor(const SceneGraph::Node& node, CustomActorImpl& extension);
207
208   // no default or copy constructor or assignment
209   CustomActor()                   = delete;
210   CustomActor(const CustomActor&) = delete;
211   CustomActor& operator=(const CustomActor& rhs) = delete;
212
213 protected:
214   CustomActorImplPtr mImpl;
215 };
216
217 } // namespace Internal
218
219 // Helpers for public-api forwarding methods
220
221 inline Internal::CustomActor& GetImpl(Dali::CustomActor& actor)
222 {
223   DALI_ASSERT_ALWAYS(actor && "CustomActor handle is empty");
224
225   BaseObject& handle = actor.GetBaseObject();
226
227   return static_cast<Internal::CustomActor&>(handle);
228 }
229
230 inline const Internal::CustomActor& GetImpl(const Dali::CustomActor& actor)
231 {
232   DALI_ASSERT_ALWAYS(actor && "CustomActor handle is empty");
233
234   const BaseObject& handle = actor.GetBaseObject();
235
236   return static_cast<const Internal::CustomActor&>(handle);
237 }
238
239 } // namespace Dali
240
241 #endif // DALI_INTERNAL_CUSTOM_ACTOR_H