1 #ifndef DALI_CUSTOM_ACTOR_IMPL_H
2 #define DALI_CUSTOM_ACTOR_IMPL_H
5 * Copyright (c) 2020 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.
108 * @param[in] depth The depth in the hierarchy for the actor
110 virtual void OnSceneConnection(int32_t depth) = 0;
113 * @brief Called after the actor has been disconnected from the Scene.
115 * If an actor is disconnected, it either has no parent or is parented to a disconnected actor.
118 * @note When the parent of a set of actors is disconnected to the scene, then all of the children
119 * will received this callback, starting with the leaf actors.
120 * For the following actor tree, the callback order will be D, E, B, F, C, and finally A.
132 virtual void OnSceneDisconnection() = 0;
135 * @brief Called after a child has been added to the owning actor.
138 * @param[in] child The child which has been added
140 virtual void OnChildAdd(Actor& child) = 0;
143 * @brief Called after the owning actor has attempted to remove a child (regardless of whether it succeeded or not).
146 * @param[in] child The child being removed
148 virtual void OnChildRemove(Actor& child) = 0;
151 * @brief Called when the owning actor property is set.
154 * @param[in] index The Property index that was set
155 * @param[in] propertyValue The value to set
157 virtual void OnPropertySet(Property::Index index, const Property::Value& propertyValue);
160 * @brief Called when the owning actor's size is set e.g. using Actor::SetSize().
163 * @param[in] targetSize The target size. Note that this target size may not match the size returned via @ref Actor::GetTargetSize
165 virtual void OnSizeSet(const Vector3& targetSize) = 0;
168 * @brief Called when the owning actor's size is animated e.g. using Animation::AnimateTo( Property( actor, Actor::Property::SIZE ), ... ).
171 * @param[in] animation The object which is animating the owning actor
172 * @param[in] targetSize The target size. Note that this target size may not match the size returned via @ref Actor::GetTargetSize
174 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) = 0;
177 * @brief Called after the size negotiation has been finished for this control.
179 * The control is expected to assign this given size to itself/its children.
181 * Should be overridden by derived classes if they need to layout
182 * actors differently after certain operations like add or remove
183 * actors, resize or after changing specific properties.
186 * @param[in] size The allocated size
187 * @param[in,out] container The control should add actors to this container that it is not able
188 * to allocate a size for
189 * @note As this function is called from inside the size negotiation algorithm, you cannot
190 * call RequestRelayout (the call would just be ignored).
192 virtual void OnRelayout(const Vector2& size, RelayoutContainer& container) = 0;
195 * @brief Notification for deriving classes.
198 * @param[in] policy The policy being set
199 * @param[in] dimension The dimension the policy is being set for
201 virtual void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) = 0;
204 * @brief Returns the natural size of the actor.
207 * @return The actor's natural size
209 virtual Vector3 GetNaturalSize() = 0;
212 * @brief Calculates the size for a child.
215 * @param[in] child The child actor to calculate the size for
216 * @param[in] dimension The dimension to calculate the size for. E.g. width or height
217 * @return Return the calculated size for the given dimension
219 virtual float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) = 0;
222 * @brief This method is called during size negotiation when a height is required for a given width.
224 * Derived classes should override this if they wish to customize the height returned.
227 * @param[in] width Width to use
228 * @return The height based on the width
230 virtual float GetHeightForWidth(float width) = 0;
233 * @brief This method is called during size negotiation when a width is required for a given height.
235 * Derived classes should override this if they wish to customize the width returned.
238 * @param[in] height Height to use
239 * @return The width based on the width
241 virtual float GetWidthForHeight(float height) = 0;
244 * @brief Determines if this actor is dependent on its children for relayout.
247 * @param[in] dimension The dimension(s) to check for
248 * @return Return if the actor is dependent on it's children
250 virtual bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) = 0;
253 * @brief Virtual method to notify deriving classes that relayout dependencies have been
254 * met and the size for this object is about to be calculated for the given dimension.
257 * @param[in] dimension The dimension that is about to be calculated
259 virtual void OnCalculateRelayoutSize(Dimension::Type dimension) = 0;
262 * @brief Virtual method to notify deriving classes that the size for a dimension
263 * has just been negotiated.
266 * @param[in] size The new size for the given dimension
267 * @param[in] dimension The dimension that was just negotiated
269 virtual void OnLayoutNegotiated(float size, Dimension::Type dimension) = 0;
272 * @brief Retrieves the extension for this control.
275 * @return The extension if available, NULL otherwise
277 virtual Extension* GetExtension()
282 protected: // For derived classes
284 * @brief Enumeration for the constructor flags.
289 ACTOR_BEHAVIOUR_DEFAULT = 0, ///< Use to provide default behaviour (size negotiation is on, event callbacks are not called). @SINCE_1_2_10
290 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
292 LAST_ACTOR_FLAG ///< Special marker for last actor flag @SINCE_1_0.0
295 static constexpr int32_t ACTOR_FLAG_COUNT = Log<LAST_ACTOR_FLAG - 1>::value + 1; ///< Value for deriving classes to continue on the flag enum
298 * @brief Creates a CustomActorImpl.
300 * @param[in] flags Bitfield of ActorFlags to define behaviour
302 CustomActorImpl(ActorFlags flags);
304 // Size negotiation helpers
307 * @brief Requests a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene).
309 * This method can also be called from a derived class every time it needs a different size.
310 * At the end of event processing, the relayout process starts and
311 * all controls which requested Relayout will have their sizes (re)negotiated.
314 * @note RelayoutRequest() can be called multiple times; the size negotiation is still
315 * only performed once, i.e. there is no need to keep track of this in the calling side.
317 void RelayoutRequest();
320 * @brief Provides the Actor implementation of GetHeightForWidth.
322 * @param[in] width Width to use
323 * @return The height based on the width
325 float GetHeightForWidthBase(float width);
328 * @brief Provides the Actor implementation of GetWidthForHeight.
330 * @param[in] height Height to use
331 * @return The width based on the height
333 float GetWidthForHeightBase(float height);
336 * @brief Calculates the size for a child using the base actor object.
339 * @param[in] child The child actor to calculate the size for
340 * @param[in] dimension The dimension to calculate the size for. E.g. width or height
341 * @return Return the calculated size for the given dimension. If more than one dimension is requested, just return the first one found
343 float CalculateChildSizeBase(const Dali::Actor& child, Dimension::Type dimension);
346 * @brief Determines if this actor is dependent on its children for relayout from the base class.
349 * @param[in] dimension The dimension(s) to check for
350 * @return Return if the actor is dependent on it's children
352 bool RelayoutDependentOnChildrenBase(Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
354 public: // Not intended for application developers
356 * @brief Initializes a CustomActor.
358 * @param[in] owner The owning object
359 * @pre The CustomActorImpl is not already owned.
360 * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
362 void Initialize(Internal::CustomActor& owner);
365 * @brief Gets the owner.
367 * This method is needed when creating additional handle objects to existing objects.
368 * Owner is the Dali::Internal::CustomActor that owns the implementation of the custom actor
369 * inside core. Creation of a handle to Dali public API Actor requires this pointer.
371 * @return A pointer to the Actor implementation that owns this custom actor implementation
373 Internal::CustomActor* GetOwner() const;
376 * @brief Returns whether relayout is enabled.
378 * @return Return true if relayout is enabled on the custom actor
379 * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
381 bool IsRelayoutEnabled() const;
384 Internal::CustomActor* mOwner; ///< Internal owner of this custom actor implementation
385 ActorFlags mFlags; ///< ActorFlags flags to determine behaviour
393 #endif // DALI_CUSTOM_ACTOR_IMPL_H