1 #ifndef DALI_INTERNAL_ACTOR_RELAYOUTER_H
2 #define DALI_INTERNAL_ACTOR_RELAYOUTER_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 <dali/internal/event/actors/actor-impl.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/math/vector3.h>
31 * Struct to do some actor specific relayouting and store related variables
33 struct Actor::Relayouter
36 static constexpr Vector3 DEFAULT_SIZE_MODE_FACTOR{1.0f, 1.0f, 1.0f};
37 static constexpr Vector2 DEFAULT_PREFERRED_SIZE{0.0f, 0.0f};
38 static constexpr Vector2 DEFAULT_DIMENSION_PADDING{0.0f, 0.0f};
39 static constexpr SizeScalePolicy::Type DEFAULT_SIZE_SCALE_POLICY = SizeScalePolicy::USE_SIZE_SET;
44 /// Default Destructor
45 ~Relayouter() = default;
47 /// @copydoc Actor::GetResizePolicy
48 ResizePolicy::Type GetResizePolicy(Dimension::Type dimension) const;
50 /// @copydoc Actor::SetPadding
51 void SetPadding(const Vector2& padding, Dimension::Type dimension);
53 /// @copydoc Actor::GetPadding
54 Vector2 GetPadding(Dimension::Type dimension);
56 /// @copydoc Actor::SetLayoutNegotiated
57 void SetLayoutNegotiated(bool negotiated, Dimension::Type dimension);
59 /// @copydoc Actor::IsLayoutNegotiated
60 bool IsLayoutNegotiated(Dimension::Type dimension) const;
62 /// @copydoc Actor::ApplySizeSetPolicy
63 Vector2 ApplySizeSetPolicy(Internal::Actor& actor, const Vector2& size);
65 /// @copydoc Actor::SetUseAssignedSize
66 void SetUseAssignedSize(bool use, Dimension::Type dimension);
68 /// @copydoc Actor::GetUseAssignedSize
69 bool GetUseAssignedSize(Dimension::Type dimension) const;
71 /// @copydoc Actor::SetMinimumSize
72 void SetMinimumSize(float size, Dimension::Type dimension);
74 /// @copydoc Actor::GetMinimumSize
75 float GetMinimumSize(Dimension::Type dimension) const;
77 /// @copydoc Actor::SetMaximumSize
78 void SetMaximumSize(float size, Dimension::Type dimension);
80 /// @copydoc Actor::GetMaximumSize
81 float GetMaximumSize(Dimension::Type dimension) const;
83 /// @copydoc Actor::SetResizePolicy
84 void SetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension, Vector3& targetSize);
86 /// @copydoc Actor::GetRelayoutDependentOnParent
87 bool GetRelayoutDependentOnParent(Dimension::Type dimension);
89 /// @copydoc Actor::GetRelayoutDependentOnChildren
90 bool GetRelayoutDependentOnChildren(Dimension::Type dimension);
92 /// @copydoc Actor::GetRelayoutDependentOnDimension
93 bool GetRelayoutDependentOnDimension(Dimension::Type dimension, Dimension::Type dependency);
95 /// @copydoc Actor::SetDimensionDependency
96 void SetDimensionDependency(Dimension::Type dimension, Dimension::Type dependency);
98 /// @copydoc Actor::GetDimensionDependency
99 Dimension::Type GetDimensionDependency(Dimension::Type dimension) const;
101 /// @copydoc Actor::SetLayoutDirty
102 void SetLayoutDirty(bool dirty, Dimension::Type dimension);
104 /// @copydoc Actor::IsLayoutDirty
105 bool IsLayoutDirty(Dimension::Type dimension) const;
107 /// @copydoc Actor::SetPreferredSize
108 /// @actor[in] actor The Actor whose preferred size we wish to set
109 void SetPreferredSize(Actor& actor, const Vector2& size);
112 * @brief Clamp a dimension given the relayout constraints on given actor
114 * @param[in] actor The actor to clamp
115 * @param[in] size The size to constrain
116 * @param[in] dimension The dimension the size exists in
117 * @return Return the clamped size
119 static float ClampDimension(const Internal::Actor& actor, float size, Dimension::Type dimension);
121 /// @copydoc Actor::SetNegotiatedDimension
122 void SetNegotiatedDimension(float negotiatedDimension, Dimension::Type dimension);
124 /// @copydoc Actor::GetNegotiatedDimension
125 float GetNegotiatedDimension(Dimension::Type dimension);
128 * Negotiate size for a specific dimension
130 * The algorithm adopts a recursive dependency checking approach. Meaning, that wherever dependencies
131 * are found, e.g. an actor dependent on its parent, the dependency will be calculated first with NegotiatedDimension and
132 * LayoutDimensionNegotiated flags being filled in on the actor.
134 * @post All actors that exist in the dependency chain connected to the given actor will have had their NegotiatedDimensions
135 * calculated and set as well as the LayoutDimensionNegotiated flags.
137 * @param[in] actor The actor whose dimension we are negotiating
138 * @param[in] dimension The dimension to negotiate on
139 * @param[in] allocatedSize The size constraint that the actor must respect
141 static void NegotiateDimension(Actor& actor, Dimension::Type dimension, const Vector2& allocatedSize, Actor::ActorDimensionStack& recursionStack);
144 * Negotiate sizes for a control in all dimensions
146 * @param[in] actor The actor whose dimensions we are negotiating
147 * @param[in] allocatedSize The size constraint that the control must respect
149 static void NegotiateDimensions(Actor& actor, const Vector2& allocatedSize);
152 * @brief Called by the RelayoutController to negotiate the size of an actor.
154 * The size allocated by the the algorithm is passed in which the
155 * actor must adhere to. A container is passed in as well which
156 * the actor should populate with actors it has not / or does not
157 * need to handle in its size negotiation.
159 * @param[in] actor The actor whose size we are negotiating
160 * @param[in] size The allocated size.
161 * @param[in,out] container The container that holds actors that are fed back into the
162 * RelayoutController algorithm.
164 static void NegotiateSize(Actor& actor, const Vector2& allocatedSize, RelayoutContainer& container);
167 ResizePolicy::Type resizePolicies[Dimension::DIMENSION_COUNT]; ///< Resize policies
168 bool useAssignedSize[Dimension::DIMENSION_COUNT]; ///< The flag to specify whether the size should be assigned to the actor
170 Dimension::Type dimensionDependencies[Dimension::DIMENSION_COUNT]; ///< A list of dimension dependencies
172 Vector2 dimensionPadding[Dimension::DIMENSION_COUNT]; ///< Padding for each dimension. X = start (e.g. left, bottom), y = end (e.g. right, top)
174 float negotiatedDimensions[Dimension::DIMENSION_COUNT]; ///< Storage for when a dimension is negotiated but before set on actor
176 float minimumSize[Dimension::DIMENSION_COUNT]; ///< The minimum size an actor can be
177 float maximumSize[Dimension::DIMENSION_COUNT]; ///< The maximum size an actor can be
179 bool dimensionNegotiated[Dimension::DIMENSION_COUNT]; ///< Has the dimension been negotiated
180 bool dimensionDirty[Dimension::DIMENSION_COUNT]; ///< Flags indicating whether the layout dimension is dirty or not
182 Vector3 sizeModeFactor; ///< Factor of size used for certain SizeModes
184 Vector2 preferredSize; ///< The preferred size of the actor
186 SizeScalePolicy::Type sizeSetPolicy : 3; ///< Policy to apply when setting size. Enough room for the enum
188 bool relayoutEnabled : 1; ///< Flag to specify if this actor should be included in size negotiation or not (defaults to true)
189 bool insideRelayout : 1; ///< Locking flag to prevent recursive relayouts on size set
190 bool relayoutRequested : 1; ///< Whether the relayout is requested.
193 } // namespace Internal
197 #endif // DALI_INTERNAL_ACTOR_RELAYOUTER_H