Merge "Optimize Orphan animator Cleanup." into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-relayouter.h
1 #ifndef DALI_INTERNAL_ACTOR_RELAYOUTER_H
2 #define DALI_INTERNAL_ACTOR_RELAYOUTER_H
3
4 /*
5  * Copyright (c) 2020 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/public-api/math/vector2.h>
23 #include <dali/public-api/math/vector3.h>
24 #include <dali/internal/event/actors/actor-impl.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 /**
33  * Struct to do some actor specific relayouting and store related variables
34  */
35 struct Actor::Relayouter
36 {
37   // Defaults
38   static constexpr Vector3 DEFAULT_SIZE_MODE_FACTOR{1.0f, 1.0f, 1.0f};
39   static constexpr Vector2 DEFAULT_PREFERRED_SIZE{0.0f, 0.0f};
40   static constexpr Vector2 DEFAULT_DIMENSION_PADDING{0.0f, 0.0f};
41   static constexpr SizeScalePolicy::Type DEFAULT_SIZE_SCALE_POLICY = SizeScalePolicy::USE_SIZE_SET;
42
43   /// Constructor
44   Relayouter();
45
46   /// Default Destructor
47   ~Relayouter() = default;
48
49   /// @copydoc Actor::GetResizePolicy
50   ResizePolicy::Type GetResizePolicy( Dimension::Type dimension ) const;
51
52   /// @copydoc Actor::SetPadding
53   void SetPadding( const Vector2& padding, Dimension::Type dimension );
54
55   /// @copydoc Actor::SetLayoutNegotiated
56   void SetLayoutNegotiated( bool negotiated, Dimension::Type dimension );
57
58   /// @copydoc Actor::IsLayoutNegotiated
59   bool IsLayoutNegotiated( Dimension::Type dimension ) const;
60
61   /// @copydoc Actor::ApplySizeSetPolicy
62   Vector2 ApplySizeSetPolicy( Internal::Actor& actor, const Vector2& size );
63
64   /// @copydoc Actor::SetUseAssignedSize
65   void SetUseAssignedSize( bool use, Dimension::Type dimension );
66
67   /// @copydoc Actor::GetUseAssignedSize
68   bool GetUseAssignedSize( Dimension::Type dimension ) const;
69
70   /// @copydoc Actor::SetMinimumSize
71   void SetMinimumSize( float size, Dimension::Type dimension );
72
73   /// @copydoc Actor::GetMinimumSize
74   float GetMinimumSize( Dimension::Type dimension ) const;
75
76   /// @copydoc Actor::SetMaximumSize
77   void SetMaximumSize( float size, Dimension::Type dimension );
78
79   /// @copydoc Actor::GetMaximumSize
80   float GetMaximumSize( Dimension::Type dimension ) const;
81
82   /// @copydoc Actor::SetResizePolicy
83   void SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension, Vector3& targetSize );
84
85   /// @copydoc Actor::SetDimensionDependency
86   void SetDimensionDependency( Dimension::Type dimension, Dimension::Type dependency );
87
88   /// @copydoc Actor::GetDimensionDependency
89   Dimension::Type GetDimensionDependency( Dimension::Type dimension ) const;
90
91   /// @copydoc Actor::SetLayoutDirty
92   void SetLayoutDirty( bool dirty, Dimension::Type dimension );
93
94   /// @copydoc Actor::IsLayoutDirty
95   bool IsLayoutDirty( Dimension::Type dimension ) const;
96
97   /// @copydoc Actor::SetPreferredSize
98   /// @actor[in] actor The Actor whose preferred size we wish to set
99   void SetPreferredSize( Actor& actor, const Vector2& size );
100
101   /**
102    * @brief Clamp a dimension given the relayout constraints on given actor
103    *
104    * @param[in] actor The actor to clamp
105    * @param[in] size The size to constrain
106    * @param[in] dimension The dimension the size exists in
107    * @return Return the clamped size
108    */
109   static float ClampDimension( const Internal::Actor& actor, float size, Dimension::Type dimension );
110
111   /**
112    * Negotiate size for a specific dimension
113    *
114    * The algorithm adopts a recursive dependency checking approach. Meaning, that wherever dependencies
115    * are found, e.g. an actor dependent on its parent, the dependency will be calculated first with NegotiatedDimension and
116    * LayoutDimensionNegotiated flags being filled in on the actor.
117    *
118    * @post All actors that exist in the dependency chain connected to the given actor will have had their NegotiatedDimensions
119    * calculated and set as well as the LayoutDimensionNegotiated flags.
120    *
121    * @param[in] actor The actor whose dimension we are negotiating
122    * @param[in] dimension The dimension to negotiate on
123    * @param[in] allocatedSize The size constraint that the actor must respect
124    */
125   static void NegotiateDimension(Actor& actor, Dimension::Type dimension, const Vector2& allocatedSize, Actor::ActorDimensionStack& recursionStack);
126
127   /**
128    * Negotiate sizes for a control in all dimensions
129    *
130    * @param[in] actor The actor whose dimensions we are negotiating
131    * @param[in] allocatedSize The size constraint that the control must respect
132    */
133   static void NegotiateDimensions(Actor& actor, const Vector2& allocatedSize);
134
135   /**
136    * @brief Called by the RelayoutController to negotiate the size of an actor.
137    *
138    * The size allocated by the the algorithm is passed in which the
139    * actor must adhere to.  A container is passed in as well which
140    * the actor should populate with actors it has not / or does not
141    * need to handle in its size negotiation.
142    *
143    * @param[in] actor The actor whose size we are negotiating
144    * @param[in]      size       The allocated size.
145    * @param[in,out]  container  The container that holds actors that are fed back into the
146    *                            RelayoutController algorithm.
147    */
148   static void NegotiateSize(Actor& actor, const Vector2& allocatedSize, RelayoutContainer& container);
149
150 public:
151
152   ResizePolicy::Type resizePolicies[ Dimension::DIMENSION_COUNT ];      ///< Resize policies
153   bool useAssignedSize[ Dimension::DIMENSION_COUNT ];                   ///< The flag to specify whether the size should be assigned to the actor
154
155   Dimension::Type dimensionDependencies[ Dimension::DIMENSION_COUNT ];  ///< A list of dimension dependencies
156
157   Vector2 dimensionPadding[ Dimension::DIMENSION_COUNT ];         ///< Padding for each dimension. X = start (e.g. left, bottom), y = end (e.g. right, top)
158
159   float negotiatedDimensions[ Dimension::DIMENSION_COUNT ];       ///< Storage for when a dimension is negotiated but before set on actor
160
161   float minimumSize[ Dimension::DIMENSION_COUNT ];                ///< The minimum size an actor can be
162   float maximumSize[ Dimension::DIMENSION_COUNT ];                ///< The maximum size an actor can be
163
164   bool dimensionNegotiated[ Dimension::DIMENSION_COUNT ];         ///< Has the dimension been negotiated
165   bool dimensionDirty[ Dimension::DIMENSION_COUNT ];              ///< Flags indicating whether the layout dimension is dirty or not
166
167   Vector3 sizeModeFactor;                              ///< Factor of size used for certain SizeModes
168
169   Vector2 preferredSize;                               ///< The preferred size of the actor
170
171   SizeScalePolicy::Type sizeSetPolicy :3;            ///< Policy to apply when setting size. Enough room for the enum
172
173   bool relayoutEnabled :1;                   ///< Flag to specify if this actor should be included in size negotiation or not (defaults to true)
174   bool insideRelayout :1;                    ///< Locking flag to prevent recursive relayouts on size set
175 };
176
177 } // namespace Internal
178
179 } // namespace Dali
180
181 #endif // DALI_INTERNAL_ACTOR_RELAYOUTER_H