f1ade33c077bf5d793b45951a2a6058113fb7834
[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) 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-impl.h>
23
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/math/vector3.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 /**
32  * Struct to do some actor specific relayouting and store related variables
33  */
34 struct ActorSizer::Relayouter
35 {
36   // Defaults
37   static constexpr Vector3               DEFAULT_SIZE_MODE_FACTOR{1.0f, 1.0f, 1.0f};
38   static constexpr Vector2               DEFAULT_PREFERRED_SIZE{0.0f, 0.0f};
39   static constexpr Vector2               DEFAULT_DIMENSION_PADDING{0.0f, 0.0f};
40   static constexpr SizeScalePolicy::Type DEFAULT_SIZE_SCALE_POLICY = SizeScalePolicy::USE_SIZE_SET;
41
42   /// Constructor
43   Relayouter();
44
45   /// Default Destructor
46   ~Relayouter() = default;
47
48   /// @copydoc Actor::GetResizePolicy
49   ResizePolicy::Type GetResizePolicy(Dimension::Type dimension) const;
50
51   /// @copydoc Actor::ApplySizeSetPolicy
52   Vector2 ApplySizeSetPolicy(Internal::Actor& actor, const Vector2& size);
53
54   /// @copydoc Actor::SetUseAssignedSize
55   void SetUseAssignedSize(bool use, Dimension::Type dimension);
56
57   /// @copydoc Actor::GetUseAssignedSize
58   bool GetUseAssignedSize(Dimension::Type dimension) const;
59
60   /// @copydoc Actor::SetMinimumSize
61   void SetMinimumSize(float size, Dimension::Type dimension);
62
63   /// @copydoc Actor::GetMinimumSize
64   float GetMinimumSize(Dimension::Type dimension) const;
65
66   /// @copydoc Actor::SetMaximumSize
67   void SetMaximumSize(float size, Dimension::Type dimension);
68
69   /// @copydoc Actor::GetMaximumSize
70   float GetMaximumSize(Dimension::Type dimension) const;
71
72   /// @copydoc Actor::SetResizePolicy
73   void SetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension, Vector3& targetSize);
74
75   /// @copydoc Actor::GetRelayoutDependentOnParent
76   bool GetRelayoutDependentOnParent(Dimension::Type dimension);
77
78   /// @copydoc Actor::GetRelayoutDependentOnChildren
79   bool GetRelayoutDependentOnChildren(Dimension::Type dimension);
80
81   /// @copydoc Actor::GetRelayoutDependentOnDimension
82   bool GetRelayoutDependentOnDimension(Dimension::Type dimension, Dimension::Type dependency);
83
84   /// @copydoc Actor::SetDimensionDependency
85   void SetDimensionDependency(Dimension::Type dimension, Dimension::Type dependency);
86
87   /// @copydoc Actor::GetDimensionDependency
88   Dimension::Type GetDimensionDependency(Dimension::Type dimension) const;
89
90   /// @copydoc Actor::SetLayoutDirty
91   void SetLayoutDirty(bool dirty, Dimension::Type dimension);
92
93   /// @copydoc Actor::IsLayoutDirty
94   bool IsLayoutDirty(Dimension::Type dimension) const;
95
96   /// @copydoc Actor::SetNegotiatedDimension
97   void SetNegotiatedDimension(float negotiatedDimension, Dimension::Type dimension);
98
99   /// @copydoc Actor::GetNegotiatedDimension
100   float GetNegotiatedDimension(Dimension::Type dimension);
101
102   /// @copydoc Actor::SetPadding
103   void SetPadding(const Vector2& padding, Dimension::Type dimension);
104
105   /// @copydoc Actor::GetPadding
106   Vector2 GetPadding(Dimension::Type dimension);
107
108   /// @copydoc Actor::SetLayoutNegotiated
109   void SetLayoutNegotiated(bool negotiated, Dimension::Type dimension);
110
111   /// @copydoc Actor::IsLayoutNegotiated
112   bool IsLayoutNegotiated(Dimension::Type dimension) const;
113
114 public:
115   ResizePolicy::Type resizePolicies[Dimension::DIMENSION_COUNT];  ///< Resize policies
116   bool               useAssignedSize[Dimension::DIMENSION_COUNT]; ///< The flag to specify whether the size should be assigned to the actor
117
118   Dimension::Type dimensionDependencies[Dimension::DIMENSION_COUNT]; ///< A list of dimension dependencies
119
120   Vector2 dimensionPadding[Dimension::DIMENSION_COUNT]; ///< Padding for each dimension. X = start (e.g. left, bottom), y = end (e.g. right, top)
121
122   float negotiatedDimensions[Dimension::DIMENSION_COUNT]; ///< Storage for when a dimension is negotiated but before set on actor
123
124   float minimumSize[Dimension::DIMENSION_COUNT]; ///< The minimum size an actor can be
125   float maximumSize[Dimension::DIMENSION_COUNT]; ///< The maximum size an actor can be
126
127   bool dimensionNegotiated[Dimension::DIMENSION_COUNT]; ///< Has the dimension been negotiated
128   bool dimensionDirty[Dimension::DIMENSION_COUNT];      ///< Flags indicating whether the layout dimension is dirty or not
129
130   Vector3 sizeModeFactor; ///< Factor of size used for certain SizeModes
131
132   Vector2 preferredSize; ///< The preferred size of the actor
133
134   SizeScalePolicy::Type sizeSetPolicy : 3; ///< Policy to apply when setting size. Enough room for the enum
135
136   bool relayoutEnabled : 1;   ///< Flag to specify if this actor should be included in size negotiation or not (defaults to true)
137   bool insideRelayout : 1;    ///< Locking flag to prevent recursive relayouts on size set
138   bool relayoutRequested : 1; ///< Whether the relayout is requested.
139 };
140
141 } // namespace Internal
142
143 } // namespace Dali
144
145 #endif // DALI_INTERNAL_ACTOR_RELAYOUTER_H