[dali_1.9.31] Merge branch '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   /**
98    * @brief Clamp a dimension given the relayout constraints on given actor
99    *
100    * @param[in] actor The actor to clamp
101    * @param[in] size The size to constrain
102    * @param[in] dimension The dimension the size exists in
103    * @return Return the clamped size
104    */
105   static float ClampDimension( const Internal::Actor& actor, float size, Dimension::Type dimension );
106
107 public:
108
109   ResizePolicy::Type resizePolicies[ Dimension::DIMENSION_COUNT ];      ///< Resize policies
110   bool useAssignedSize[ Dimension::DIMENSION_COUNT ];                   ///< The flag to specify whether the size should be assigned to the actor
111
112   Dimension::Type dimensionDependencies[ Dimension::DIMENSION_COUNT ];  ///< A list of dimension dependencies
113
114   Vector2 dimensionPadding[ Dimension::DIMENSION_COUNT ];         ///< Padding for each dimension. X = start (e.g. left, bottom), y = end (e.g. right, top)
115
116   float negotiatedDimensions[ Dimension::DIMENSION_COUNT ];       ///< Storage for when a dimension is negotiated but before set on actor
117
118   float minimumSize[ Dimension::DIMENSION_COUNT ];                ///< The minimum size an actor can be
119   float maximumSize[ Dimension::DIMENSION_COUNT ];                ///< The maximum size an actor can be
120
121   bool dimensionNegotiated[ Dimension::DIMENSION_COUNT ];         ///< Has the dimension been negotiated
122   bool dimensionDirty[ Dimension::DIMENSION_COUNT ];              ///< Flags indicating whether the layout dimension is dirty or not
123
124   Vector3 sizeModeFactor;                              ///< Factor of size used for certain SizeModes
125
126   Vector2 preferredSize;                               ///< The preferred size of the actor
127
128   SizeScalePolicy::Type sizeSetPolicy :3;            ///< Policy to apply when setting size. Enough room for the enum
129
130   bool relayoutEnabled :1;                   ///< Flag to specify if this actor should be included in size negotiation or not (defaults to true)
131   bool insideRelayout :1;                    ///< Locking flag to prevent recursive relayouts on size set
132 };
133
134 } // namespace Internal
135
136 } // namespace Dali
137
138 #endif // DALI_INTERNAL_ACTOR_RELAYOUTER_H