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::SetLayoutNegotiated
54 void SetLayoutNegotiated(bool negotiated, Dimension::Type dimension);
56 /// @copydoc Actor::IsLayoutNegotiated
57 bool IsLayoutNegotiated(Dimension::Type dimension) const;
59 /// @copydoc Actor::ApplySizeSetPolicy
60 Vector2 ApplySizeSetPolicy(Internal::Actor& actor, const Vector2& size);
62 /// @copydoc Actor::SetUseAssignedSize
63 void SetUseAssignedSize(bool use, Dimension::Type dimension);
65 /// @copydoc Actor::GetUseAssignedSize
66 bool GetUseAssignedSize(Dimension::Type dimension) const;
68 /// @copydoc Actor::SetMinimumSize
69 void SetMinimumSize(float size, Dimension::Type dimension);
71 /// @copydoc Actor::GetMinimumSize
72 float GetMinimumSize(Dimension::Type dimension) const;
74 /// @copydoc Actor::SetMaximumSize
75 void SetMaximumSize(float size, Dimension::Type dimension);
77 /// @copydoc Actor::GetMaximumSize
78 float GetMaximumSize(Dimension::Type dimension) const;
80 /// @copydoc Actor::SetResizePolicy
81 void SetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension, Vector3& targetSize);
83 /// @copydoc Actor::SetDimensionDependency
84 void SetDimensionDependency(Dimension::Type dimension, Dimension::Type dependency);
86 /// @copydoc Actor::GetDimensionDependency
87 Dimension::Type GetDimensionDependency(Dimension::Type dimension) const;
89 /// @copydoc Actor::SetLayoutDirty
90 void SetLayoutDirty(bool dirty, Dimension::Type dimension);
92 /// @copydoc Actor::IsLayoutDirty
93 bool IsLayoutDirty(Dimension::Type dimension) const;
95 /// @copydoc Actor::SetPreferredSize
96 /// @actor[in] actor The Actor whose preferred size we wish to set
97 void SetPreferredSize(Actor& actor, const Vector2& size);
100 * @brief Clamp a dimension given the relayout constraints on given actor
102 * @param[in] actor The actor to clamp
103 * @param[in] size The size to constrain
104 * @param[in] dimension The dimension the size exists in
105 * @return Return the clamped size
107 static float ClampDimension(const Internal::Actor& actor, float size, Dimension::Type dimension);
110 * Negotiate size for a specific dimension
112 * The algorithm adopts a recursive dependency checking approach. Meaning, that wherever dependencies
113 * are found, e.g. an actor dependent on its parent, the dependency will be calculated first with NegotiatedDimension and
114 * LayoutDimensionNegotiated flags being filled in on the actor.
116 * @post All actors that exist in the dependency chain connected to the given actor will have had their NegotiatedDimensions
117 * calculated and set as well as the LayoutDimensionNegotiated flags.
119 * @param[in] actor The actor whose dimension we are negotiating
120 * @param[in] dimension The dimension to negotiate on
121 * @param[in] allocatedSize The size constraint that the actor must respect
123 static void NegotiateDimension(Actor& actor, Dimension::Type dimension, const Vector2& allocatedSize, Actor::ActorDimensionStack& recursionStack);
126 * Negotiate sizes for a control in all dimensions
128 * @param[in] actor The actor whose dimensions we are negotiating
129 * @param[in] allocatedSize The size constraint that the control must respect
131 static void NegotiateDimensions(Actor& actor, const Vector2& allocatedSize);
134 * @brief Called by the RelayoutController to negotiate the size of an actor.
136 * The size allocated by the the algorithm is passed in which the
137 * actor must adhere to. A container is passed in as well which
138 * the actor should populate with actors it has not / or does not
139 * need to handle in its size negotiation.
141 * @param[in] actor The actor whose size we are negotiating
142 * @param[in] size The allocated size.
143 * @param[in,out] container The container that holds actors that are fed back into the
144 * RelayoutController algorithm.
146 static void NegotiateSize(Actor& actor, const Vector2& allocatedSize, RelayoutContainer& container);
149 ResizePolicy::Type resizePolicies[Dimension::DIMENSION_COUNT]; ///< Resize policies
150 bool useAssignedSize[Dimension::DIMENSION_COUNT]; ///< The flag to specify whether the size should be assigned to the actor
152 Dimension::Type dimensionDependencies[Dimension::DIMENSION_COUNT]; ///< A list of dimension dependencies
154 Vector2 dimensionPadding[Dimension::DIMENSION_COUNT]; ///< Padding for each dimension. X = start (e.g. left, bottom), y = end (e.g. right, top)
156 float negotiatedDimensions[Dimension::DIMENSION_COUNT]; ///< Storage for when a dimension is negotiated but before set on actor
158 float minimumSize[Dimension::DIMENSION_COUNT]; ///< The minimum size an actor can be
159 float maximumSize[Dimension::DIMENSION_COUNT]; ///< The maximum size an actor can be
161 bool dimensionNegotiated[Dimension::DIMENSION_COUNT]; ///< Has the dimension been negotiated
162 bool dimensionDirty[Dimension::DIMENSION_COUNT]; ///< Flags indicating whether the layout dimension is dirty or not
164 Vector3 sizeModeFactor; ///< Factor of size used for certain SizeModes
166 Vector2 preferredSize; ///< The preferred size of the actor
168 SizeScalePolicy::Type sizeSetPolicy : 3; ///< Policy to apply when setting size. Enough room for the enum
170 bool relayoutEnabled : 1; ///< Flag to specify if this actor should be included in size negotiation or not (defaults to true)
171 bool insideRelayout : 1; ///< Locking flag to prevent recursive relayouts on size set
172 bool relayoutRequested : 1; ///< Whether the relayout is requested.
175 } // namespace Internal
179 #endif // DALI_INTERNAL_ACTOR_RELAYOUTER_H