1 #ifndef DALI_INTERNAL_ACTOR_RELAYOUTER_H
2 #define DALI_INTERNAL_ACTOR_RELAYOUTER_H
5 * Copyright (c) 2020 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/public-api/math/vector2.h>
23 #include <dali/public-api/math/vector3.h>
24 #include <dali/internal/event/actors/actor-impl.h>
33 * Struct to do some actor specific relayouting and store related variables
35 struct Actor::Relayouter
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;
46 /// Default Destructor
47 ~Relayouter() = default;
49 /// @copydoc Actor::GetResizePolicy
50 ResizePolicy::Type GetResizePolicy( Dimension::Type dimension ) const;
52 /// @copydoc Actor::SetPadding
53 void SetPadding( const Vector2& padding, Dimension::Type dimension );
55 /// @copydoc Actor::SetLayoutNegotiated
56 void SetLayoutNegotiated( bool negotiated, Dimension::Type dimension );
58 /// @copydoc Actor::IsLayoutNegotiated
59 bool IsLayoutNegotiated( Dimension::Type dimension ) const;
61 /// @copydoc Actor::ApplySizeSetPolicy
62 Vector2 ApplySizeSetPolicy( Internal::Actor& actor, const Vector2& size );
64 /// @copydoc Actor::SetUseAssignedSize
65 void SetUseAssignedSize( bool use, Dimension::Type dimension );
67 /// @copydoc Actor::GetUseAssignedSize
68 bool GetUseAssignedSize( Dimension::Type dimension ) const;
70 /// @copydoc Actor::SetMinimumSize
71 void SetMinimumSize( float size, Dimension::Type dimension );
73 /// @copydoc Actor::GetMinimumSize
74 float GetMinimumSize( Dimension::Type dimension ) const;
76 /// @copydoc Actor::SetMaximumSize
77 void SetMaximumSize( float size, Dimension::Type dimension );
79 /// @copydoc Actor::GetMaximumSize
80 float GetMaximumSize( Dimension::Type dimension ) const;
82 /// @copydoc Actor::SetResizePolicy
83 void SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension, Vector3& targetSize );
85 /// @copydoc Actor::SetDimensionDependency
86 void SetDimensionDependency( Dimension::Type dimension, Dimension::Type dependency );
88 /// @copydoc Actor::GetDimensionDependency
89 Dimension::Type GetDimensionDependency( Dimension::Type dimension ) const;
91 /// @copydoc Actor::SetLayoutDirty
92 void SetLayoutDirty( bool dirty, Dimension::Type dimension );
94 /// @copydoc Actor::IsLayoutDirty
95 bool IsLayoutDirty( Dimension::Type dimension ) const;
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 );
102 * @brief Clamp a dimension given the relayout constraints on given actor
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
109 static float ClampDimension( const Internal::Actor& actor, float size, Dimension::Type dimension );
112 * Negotiate size for a specific dimension
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.
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.
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
125 static void NegotiateDimension(Actor& actor, Dimension::Type dimension, const Vector2& allocatedSize, Actor::ActorDimensionStack& recursionStack);
128 * Negotiate sizes for a control in all dimensions
130 * @param[in] actor The actor whose dimensions we are negotiating
131 * @param[in] allocatedSize The size constraint that the control must respect
133 static void NegotiateDimensions(Actor& actor, const Vector2& allocatedSize);
136 * @brief Called by the RelayoutController to negotiate the size of an actor.
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.
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.
148 static void NegotiateSize(Actor& actor, const Vector2& allocatedSize, RelayoutContainer& container);
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
155 Dimension::Type dimensionDependencies[ Dimension::DIMENSION_COUNT ]; ///< A list of dimension dependencies
157 Vector2 dimensionPadding[ Dimension::DIMENSION_COUNT ]; ///< Padding for each dimension. X = start (e.g. left, bottom), y = end (e.g. right, top)
159 float negotiatedDimensions[ Dimension::DIMENSION_COUNT ]; ///< Storage for when a dimension is negotiated but before set on actor
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
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
167 Vector3 sizeModeFactor; ///< Factor of size used for certain SizeModes
169 Vector2 preferredSize; ///< The preferred size of the actor
171 SizeScalePolicy::Type sizeSetPolicy :3; ///< Policy to apply when setting size. Enough room for the enum
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
177 } // namespace Internal
181 #endif // DALI_INTERNAL_ACTOR_RELAYOUTER_H