1 #ifndef DALI_ALIGNMENT_H
2 #define DALI_ALIGNMENT_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-toolkit/public-api/controls/control.h>
28 namespace Internal DALI_INTERNAL
33 * @addtogroup dali_toolkit_controls_alignment
38 * @brief Alignment is a container which provides an easy way to align other actors inside its boundary.
40 * Additionally, it provides a scaling property to resize the contained actors @see Scaling.
42 * @note The use of scaling property will override all constraints applied to actors.
44 * All actors added to an alignment are going to be set with the same anchor point and parent origin. And if the scaling property is set to a value
45 * different than SCALE_NONE, constraints as well.
47 class DALI_TOOLKIT_API Alignment : public Control
51 * @brief Enumeration for different types of alignment.
56 HORIZONTAL_LEFT = 1, ///< HORIZONTAL left alignment @SINCE_1_9.28
57 HORIZONTAL_CENTER = 2, ///< HORIZONTAL center alignment @SINCE_1_9.28
58 HORIZONTAL_RIGHT = 4, ///< HORIZONTAL right alignment @SINCE_1_9.28
59 VERTICAL_TOP = 8, ///< VERTICAL top alignment @SINCE_1_9.28
60 VERTICAL_CENTER = 16, ///< VERTICAL center alignment @SINCE_1_9.28
61 VERTICAL_BOTTOM = 32 ///< VERTICAL bottom alignment @SINCE_1_9.28
65 * @brief Scaling determines how actors are scaled to match the alignment's boundary.
70 SCALE_NONE, ///< The original size is kept. @SINCE_1_9.28
71 SCALE_TO_FILL, ///< Scale added actors to fill alignment's boundary. Aspect ratio is not maintained. @SINCE_1_9.28
72 SCALE_TO_FIT_KEEP_ASPECT, ///< Scale added actors to fit within the alignment's boundary. Aspect ratio is maintained. @SINCE_1_9.28
73 SCALE_TO_FILL_KEEP_ASPECT, ///< Scale added actors to fill the alignment's boundary. Aspect ratio is maintained, and the actor may exceed the alignment's boundary. @SINCE_1_9.28
74 SHRINK_TO_FIT, ///< If added actors are larger than the alignment's boundary it will be shrunk down to fit. Aspect ratio is not maintained @SINCE_1_9.28
75 SHRINK_TO_FIT_KEEP_ASPECT, ///< If added actors are larger than the alignment's boundary it will be shrunk down to fit. Aspect ratio is maintained @SINCE_1_9.28
79 * @brief Structure describing the padding values.
100 * @param[in] l Left padding
101 * @param[in] r Right padding
102 * @param[in] t Top padding
103 * @param[in] b Bottom padding
105 Padding(float l, float r, float t, float b)
113 float left; ///< The left padding
114 float right; ///< The right padding
115 float top; ///< The top padding
116 float bottom; ///< The bottom padding
120 * @brief Creates an Alignment handle; this can be initialized with Alignment::New().
122 * Calling member functions with an uninitialized handle is not allowed.
128 * @brief Creates an alignment control.
131 * @param[in] horizontal Specifies how to align actors horizontally. Could be HORIZONTAL_LEFT, HORIZONTAL_CENTER or HORIZONTAL_RIGHT. By default, HORIZONTAL_CENTER
132 * @param[in] vertical Specifies how to align actors vertically. Could be VERTICAL_TOP, VERTICAL_CENTER or VERTICAL_BOTTOM. By default, VERTICAL_CENTER
133 * @return A handle to the Alignment control
135 static Alignment New(Type horizontal = HORIZONTAL_CENTER, Type vertical = VERTICAL_CENTER);
138 * @brief Copy constructor. Creates another handle that points to the same real object.
141 * @param[in] alignment Object to copy
143 Alignment(const Alignment& alignment);
148 * This is non-virtual since derived Handle types must not contain data or virtual methods.
154 * @brief Downcasts a handle to Alignment handle.
156 * If handle points to an Alignment, the downcast produces valid handle.
157 * If not, the returned handle is left uninitialized.
160 * @param[in] handle Handle to an object
161 * @return A handle to a Alignment or an uninitialized handle
163 static Alignment DownCast(BaseHandle handle);
166 * @brief Sets the new alignment. By default, ( HORIZONTAL_CENTER | VERTICAL_CENTER ).
169 * @param[in] type The new alignment option
170 * @note There should only be one horizontal and one vertical policy.
172 void SetAlignmentType(Type type);
175 * @brief Gets the current alignment combined into a single value.
177 * The values can be tested by using the & operator and the desired
180 * if (GetAlignmentType() & HorizontalCentre)
187 * @return the alignment value
189 Type GetAlignmentType() const;
192 * @brief Sets how added actors scale to fit the alignment's boundary.
195 * @param[in] scaling The scaling property
198 void SetScaling(Scaling scaling);
201 * @brief Retrieves the scaling property.
204 * @return The scaling
207 Scaling GetScaling() const;
210 * @brief Sets a padding value.
213 * @param[in] padding The left, right, top, bottom padding values
215 void SetPadding(const Padding& padding);
218 * @brief Gets the padding values.
221 * @return The left, right, top, bottom padding values
223 const Padding& GetPadding() const;
226 * @brief Assignment operator.
228 * Changes this handle to point to another real object.
230 * @param[in] alignment Object to copy
231 * @return A reference to this
233 Alignment& operator=(const Alignment& alignment);
235 public: // Not intended for application developers
238 * @brief Creates a handle using the Toolkit::Internal implementation.
241 * @param[in] implementation The Control implementation
243 DALI_INTERNAL Alignment(Internal::Alignment& implementation);
246 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
249 * @param[in] internal A pointer to the internal CustomActor
251 explicit DALI_INTERNAL Alignment(Dali::Internal::CustomActor* internal);
259 } // namespace Toolkit
263 #endif // DALI_ALIGNMENT_H