1 #ifndef DALI_CUSTOM_ACTOR_IMPL_H
2 #define DALI_CUSTOM_ACTOR_IMPL_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <cstdint> // uint32_t
25 #include <dali/public-api/actors/actor-enumerations.h>
26 #include <dali/public-api/math/compile-time-math.h>
27 #include <dali/public-api/object/property.h>
28 #include <dali/public-api/object/ref-object.h>
33 * @addtogroup dali_core_actors
37 namespace Internal DALI_INTERNAL
45 class CustomActorImpl;
46 class RelayoutContainer;
54 * @brief Pointer to Dali::CustomActorImpl object.
57 using CustomActorImplPtr = IntrusivePtr<CustomActorImpl>;
60 * @brief CustomActorImpl is an abstract base class for custom control implementations.
62 * This provides a series of pure virtual methods, which are called when actor-specific events occur.
63 * And CustomActorImpl is typically owned by a single CustomActor instance; see also CustomActor::CustomActor( CustomActorImpl &implementation ).
66 class DALI_CORE_API CustomActorImpl : public Dali::RefObject
69 class Extension; ///< Forward declare future extension interface
73 * @brief Virtual destructor
76 ~CustomActorImpl() override;
80 * @brief Used by derived CustomActorImpl instances, to access the public Actor interface.
83 * @return A pointer to self, or an uninitialized pointer if the CustomActorImpl is not owned.
85 CustomActor Self() const;
88 * @brief Called after the actor has been connected to the Scene.
90 * When an actor is connected, it will be directly or indirectly parented to the root Actor.
92 * @param[in] depth The depth in the hierarchy for the actor
94 * @note The root Actor is provided automatically by the Scene, and is always considered to be connected.
95 * When the parent of a set of actors is connected to the scene, then all of the children
96 * will received this callback.
97 * For the following actor tree, the callback order will be A, B, D, E, C, and finally F.
109 virtual void OnSceneConnection(int32_t depth) = 0;
112 * @brief Called after the actor has been disconnected from the Scene.
114 * If an actor is disconnected, it either has no parent or is parented to a disconnected actor.
117 * @note When the parent of a set of actors is disconnected to the scene, then all of the children
118 * will received this callback, starting with the leaf actors.
119 * For the following actor tree, the callback order will be D, E, B, F, C, and finally A.
131 virtual void OnSceneDisconnection() = 0;
134 * @brief Called after a child has been added to the owning actor.
137 * @param[in] child The child which has been added
139 virtual void OnChildAdd(Actor& child) = 0;
142 * @brief Called after the owning actor has attempted to remove a child (regardless of whether it succeeded or not).
145 * @param[in] child The child being removed
147 virtual void OnChildRemove(Actor& child) = 0;
150 * @brief Called when the owning actor property is set.
153 * @param[in] index The Property index that was set
154 * @param[in] propertyValue The value to set
156 virtual void OnPropertySet(Property::Index index, const Property::Value& propertyValue);
159 * @brief Called when the owning actor's size is set e.g. using Actor::SetSize().
162 * @param[in] targetSize The target size. Note that this target size may not match the size returned via @ref Actor::GetTargetSize
164 virtual void OnSizeSet(const Vector3& targetSize) = 0;
167 * @brief Called when the owning actor's size is animated e.g. using Animation::AnimateTo( Property( actor, Actor::Property::SIZE ), ... ).
170 * @param[in] animation The object which is animating the owning actor
171 * @param[in] targetSize The target size. Note that this target size may not match the size returned via @ref Actor::GetTargetSize
173 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) = 0;
176 * @brief Called after the size negotiation has been finished for this control.
178 * The control is expected to assign this given size to itself/its children.
180 * Should be overridden by derived classes if they need to layout
181 * actors differently after certain operations like add or remove
182 * actors, resize or after changing specific properties.
185 * @param[in] size The allocated size
186 * @param[in,out] container The control should add actors to this container that it is not able
187 * to allocate a size for
188 * @note As this function is called from inside the size negotiation algorithm, you cannot
189 * call RequestRelayout (the call would just be ignored).
191 virtual void OnRelayout(const Vector2& size, RelayoutContainer& container) = 0;
194 * @brief Notification for deriving classes.
197 * @param[in] policy The policy being set
198 * @param[in] dimension The dimension the policy is being set for
200 virtual void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) = 0;
203 * @brief Returns the natural size of the actor.
206 * @return The actor's natural size
208 virtual Vector3 GetNaturalSize() = 0;
211 * @brief Calculates the size for a child.
214 * @param[in] child The child actor to calculate the size for
215 * @param[in] dimension The dimension to calculate the size for. E.g. width or height
216 * @return Return the calculated size for the given dimension
218 virtual float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) = 0;
221 * @brief This method is called during size negotiation when a height is required for a given width.
223 * Derived classes should override this if they wish to customize the height returned.
226 * @param[in] width Width to use
227 * @return The height based on the width
229 virtual float GetHeightForWidth(float width) = 0;
232 * @brief This method is called during size negotiation when a width is required for a given height.
234 * Derived classes should override this if they wish to customize the width returned.
237 * @param[in] height Height to use
238 * @return The width based on the width
240 virtual float GetWidthForHeight(float height) = 0;
243 * @brief Determines if this actor is dependent on its children for relayout.
246 * @param[in] dimension The dimension(s) to check for
247 * @return Return if the actor is dependent on it's children
249 virtual bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) = 0;
252 * @brief Virtual method to notify deriving classes that relayout dependencies have been
253 * met and the size for this object is about to be calculated for the given dimension.
256 * @param[in] dimension The dimension that is about to be calculated
258 virtual void OnCalculateRelayoutSize(Dimension::Type dimension) = 0;
261 * @brief Virtual method to notify deriving classes that the size for a dimension
262 * has just been negotiated.
265 * @param[in] size The new size for the given dimension
266 * @param[in] dimension The dimension that was just negotiated
268 virtual void OnLayoutNegotiated(float size, Dimension::Type dimension) = 0;
271 * @brief Retrieves the extension for this control.
274 * @return The extension if available, NULL otherwise
276 virtual Extension* GetExtension()
281 protected: // For derived classes
283 * @brief Enumeration for the constructor flags.
288 ACTOR_BEHAVIOUR_DEFAULT = 0, ///< Use to provide default behaviour (size negotiation is on, event callbacks are not called). @SINCE_1_2_10
289 DISABLE_SIZE_NEGOTIATION = 1 << 0, ///< True if control does not need size negotiation, i.e. it can be skipped in the algorithm @SINCE_1_0.0
290 NOT_IN_USE_1 = 1 << 1,
291 NOT_IN_USE_2 = 1 << 2,
292 NOT_IN_USE_3 = 1 << 3,
294 LAST_ACTOR_FLAG ///< Special marker for last actor flag @SINCE_1_0.0
297 static constexpr int32_t ACTOR_FLAG_COUNT = Log<LAST_ACTOR_FLAG - 1>::value + 1; ///< Value for deriving classes to continue on the flag enum
300 * @brief Creates a CustomActorImpl.
302 * @param[in] flags Bitfield of ActorFlags to define behaviour
304 CustomActorImpl(ActorFlags flags);
306 // Size negotiation helpers
309 * @brief Requests a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene).
311 * This method can also be called from a derived class every time it needs a different size.
312 * At the end of event processing, the relayout process starts and
313 * all controls which requested Relayout will have their sizes (re)negotiated.
316 * @note RelayoutRequest() can be called multiple times; the size negotiation is still
317 * only performed once, i.e. there is no need to keep track of this in the calling side.
319 void RelayoutRequest();
322 * @brief Provides the Actor implementation of GetHeightForWidth.
324 * @param[in] width Width to use
325 * @return The height based on the width
327 float GetHeightForWidthBase(float width);
330 * @brief Provides the Actor implementation of GetWidthForHeight.
332 * @param[in] height Height to use
333 * @return The width based on the height
335 float GetWidthForHeightBase(float height);
338 * @brief Calculates the size for a child using the base actor object.
341 * @param[in] child The child actor to calculate the size for
342 * @param[in] dimension The dimension to calculate the size for. E.g. width or height
343 * @return Return the calculated size for the given dimension. If more than one dimension is requested, just return the first one found
345 float CalculateChildSizeBase(const Dali::Actor& child, Dimension::Type dimension);
348 * @brief Determines if this actor is dependent on its children for relayout from the base class.
351 * @param[in] dimension The dimension(s) to check for
352 * @return Return if the actor is dependent on it's children
354 bool RelayoutDependentOnChildrenBase(Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
356 public: // Not intended for application developers
358 * @brief Initializes a CustomActor.
360 * @param[in] owner The owning object
361 * @pre The CustomActorImpl is not already owned.
362 * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
364 void Initialize(Internal::CustomActor& owner);
367 * @brief Gets the owner.
369 * This method is needed when creating additional handle objects to existing objects.
370 * Owner is the Dali::Internal::CustomActor that owns the implementation of the custom actor
371 * inside core. Creation of a handle to Dali public API Actor requires this pointer.
373 * @return A pointer to the Actor implementation that owns this custom actor implementation
375 Internal::CustomActor* GetOwner() const;
378 * @brief Returns whether relayout is enabled.
380 * @return Return true if relayout is enabled on the custom actor
381 * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
383 bool IsRelayoutEnabled() const;
386 Internal::CustomActor* mOwner; ///< Internal owner of this custom actor implementation
387 ActorFlags mFlags; ///< ActorFlags flags to determine behaviour
395 #endif // DALI_CUSTOM_ACTOR_IMPL_H