Purge underscored header file barriers
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / flex-container / flex-container.h
1 #ifndef DALI_TOOLKIT_FLEX_CONTAINER_H
2 #define DALI_TOOLKIT_FLEX_CONTAINER_H
3
4 /*
5  * Copyright (c) 2019 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-toolkit/public-api/controls/control.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal DALI_INTERNAL
31 {
32 class FlexContainer;
33 }
34
35 /**
36  * @addtogroup dali_toolkit_controls_flex_container
37  * @{
38  */
39
40 /**
41  * @brief FlexContainer implements a subset of the flexbox spec (defined by W3C):
42  *
43  * https://www.w3.org/TR/css3-flexbox/
44  *
45  * It aims at providing a more efficient way to lay out, align and distribute space among
46  * items in the container, even when their size is unknown or dynamic.
47  *
48  * FlexContainer has the ability to alter the width and height of its children (i.e. flex
49  * items) to fill the available space in the best possible way on different screen sizes.
50  * FlexContainer can expand items to fill available free space, or shrink them to prevent
51  * overflow.
52  *
53  * Below is an illustration of the various directions and terms as applied to a flex
54  * container with the "flex direction" defined as "row".
55  *
56  * @code
57  *     flex container
58  *    --------------------------------------------------------------- cross start
59  *    | ------------------ --------|--------------------------- |
60  *    | |                | |       |                          | |
61  *    | |                | |       |                          | |
62  *    | |  flex item 1   | |       |    flex item 2           | | main axis
63  *    |-|----------------|-|-------|--------------------------|-|------------>
64  *    | |                | |       |                          | |
65  *    | |                | |       |                          | |
66  *    | |                | |       |                          | |
67  *    | ------------------ --------|--------------------------- |
68  *    -----------------------------|--------------------------------- cross end
69  *    |                            |                            |
70  *    | main start                 | cross axis                 | main end
71  *    |                            |                            |
72  *                                 v
73  * @endcode
74  *
75  * @nosubgrouping
76  * <h3>Per-child Custom properties for script supporting:</h3>
77  *
78  * The following custom properties of the actor are checked to decide how to lay out the
79  * actor inside the flex container.
80  *
81  * These properties are registered dynamically to the child and are non-animatable.
82  *
83  * | %Property Name          | Type        |
84  * |-------------------------|-------------|
85  * | flex                    | float       |
86  * | alignSelf               | integer     |
87  * | flexMargin              | Vector4     |
88  *
89  * The available values for alignSelf are: ALIGN_AUTO, ALIGN_FLEX_START, ALIGN_CENTER, ALIGN_FLEX_END, ALIGN_STRETCH
90  *
91  * @code
92  * "name":"icon",
93  * "type":"ImageView",
94  * "image":"image.png",
95  *   "properties": {
96  *     "flex":1,                        // Property to make the item to receive the specified proportion of the free space in the container.
97  *     "alignSelf":"flexStart",         // Property to specify how the item will align along the cross axis.
98  *     "flexMargin":[10, 10, 10, 10]    // Property to specify the space around the item.
99  *   }
100  * @endcode
101  * @SINCE_1_1.35
102  */
103
104 class DALI_TOOLKIT_API FlexContainer : public Control
105 {
106 public:
107
108   /**
109    * @brief Enumeration for the direction of the main axis in the flex container. This determines
110    * the direction that flex items are laid out in the flex container.
111    * @SINCE_1_1.35
112    */
113   enum FlexDirection
114   {
115     COLUMN,                  ///< The flexible items are displayed vertically as a column @SINCE_1_1.35
116     COLUMN_REVERSE,          ///< The flexible items are displayed vertically as a column, but in reverse order @SINCE_1_1.35
117     ROW,                     ///< The flexible items are displayed horizontally as a row @SINCE_1_1.35
118     ROW_REVERSE              ///< The flexible items are displayed horizontally as a row, but in reverse order @SINCE_1_1.35
119   };
120
121   /**
122    * @brief Enumeration for the primary direction in which content is ordered in the flex container
123    * and on which sides the “start” and “end” are.
124    * @SINCE_1_1.35
125    */
126   enum ContentDirection
127   {
128     INHERIT,                 ///< Inherits the same direction from the parent @SINCE_1_1.35
129     LTR,                     ///< From left to right @SINCE_1_1.35
130     RTL                      ///< From right to left @SINCE_1_1.35
131   };
132
133   /**
134    * @brief Enumeration for the alignment of the flex items when the items do not use all available
135    * space on the main-axis.
136    * @SINCE_1_1.35
137    */
138   enum Justification
139   {
140     JUSTIFY_FLEX_START,      ///< Items are positioned at the beginning of the container @SINCE_1_1.35
141     JUSTIFY_CENTER,          ///< Items are positioned at the center of the container @SINCE_1_1.35
142     JUSTIFY_FLEX_END,        ///< Items are positioned at the end of the container @SINCE_1_1.35
143     JUSTIFY_SPACE_BETWEEN,   ///< Items are positioned with equal space between the lines @SINCE_1_1.35
144     JUSTIFY_SPACE_AROUND     ///< Items are positioned with equal space before, between, and after the lines @SINCE_1_1.35
145   };
146
147   /**
148    * @brief Enumeration for the alignment of the flex items or lines when the items or lines do not
149    * use all the available space on the cross-axis.
150    * @SINCE_1_1.35
151    */
152   enum Alignment
153   {
154     ALIGN_AUTO,              ///< Inherits the same alignment from the parent (only valid for "alignSelf" property) @SINCE_1_1.35
155     ALIGN_FLEX_START,        ///< At the beginning of the container @SINCE_1_1.35
156     ALIGN_CENTER,            ///< At the center of the container @SINCE_1_1.35
157     ALIGN_FLEX_END,          ///< At the end of the container @SINCE_1_1.35
158     ALIGN_STRETCH            ///< Stretch to fit the container @SINCE_1_1.35
159   };
160
161   /**
162    * @brief Enumeration for the wrap type of the flex container when there is no enough room for
163    * all the items on one flex line.
164    * @SINCE_1_1.35
165    */
166   enum WrapType
167   {
168     NO_WRAP,                 ///< Flex items laid out in single line (shrunk to fit the flex container along the main axis) @SINCE_1_1.35
169     WRAP                     ///< Flex items laid out in multiple lines if needed @SINCE_1_1.35
170   };
171
172 public:
173
174   /**
175    * @brief Enumeration for the start and end property ranges for this control.
176    * @SINCE_1_1.35
177    */
178   enum PropertyRange
179   {
180     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,               ///< @SINCE_1_1.35
181     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000,                           ///< Reserve property indices @SINCE_1_1.35
182
183     CHILD_PROPERTY_START_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX,         ///< @SINCE_1_1.35
184     CHILD_PROPERTY_END_INDEX =   CHILD_PROPERTY_REGISTRATION_START_INDEX + 1000   ///< Reserve child property indices @SINCE_1_1.35
185   };
186
187   /**
188    * @brief Enumeration for the instance of properties belonging to the FlexContainer class.
189    * @SINCE_1_1.35
190    */
191   struct Property
192   {
193     /**
194      * @brief Enumeration for the instance of properties belonging to the FlexContainer class.
195      * @SINCE_1_1.35
196      */
197     enum
198     {
199       // Event side properties
200       CONTENT_DIRECTION = PROPERTY_START_INDEX, ///< name "contentDirection",   The primary direction in which content is ordered,                                                 @see FlexContainer::ContentDirection,  type INTEGER @SINCE_1_1.35
201       FLEX_DIRECTION,                           ///< name "flexDirection",      The direction of the main-axis which determines the direction that flex items are laid out,        @see FlexContainer::FlexDirection,     type INTEGER @SINCE_1_1.35
202       FLEX_WRAP,                                ///< name "flexWrap",           Whether the flex items should wrap or not if there is no enough room for them on one flex line,    @see FlexContainer::WrapType,          type INTEGER @SINCE_1_1.35
203       JUSTIFY_CONTENT,                          ///< name "justifyContent",     The alignment of flex items when the items do not use all available space on the main-axis,        @see FlexContainer::Justification,     type INTEGER @SINCE_1_1.35
204       ALIGN_ITEMS,                              ///< name "alignItems",         The alignment of flex items when the items do not use all available space on the cross-axis,       @see FlexContainer::Alignment,         type INTEGER @SINCE_1_1.35
205       ALIGN_CONTENT                             ///< name "alignContent",       Similar to "alignItems", but it aligns flex lines, so only works when there are multiple lines,    @see FlexContainer::Alignment,         type INTEGER @SINCE_1_1.35
206     };
207   };
208
209   /**
210    * @brief Enumeration for the instance of child properties belonging to the FlexContainer class.
211    * @SINCE_1_1.35
212    */
213   struct ChildProperty
214   {
215     /**
216      * @brief Enumeration for the instance of child properties belonging to the FlexContainer class.
217      * @SINCE_1_1.35
218      */
219     enum
220     {
221       // Event side child properties
222       FLEX = CHILD_PROPERTY_START_INDEX,        ///< name "flex",               The proportion of the free space in the container the flex item will receive. If all items in the container set this property, their sizes will be proportional to the specified flex factor,  type FLOAT @SINCE_1_1.35
223       ALIGN_SELF,                               ///< name "alignSelf",          The alignment of the flex item along the cross axis, which, if set, overrides the default alignment for all items in the container,                         @see FlexContainer::Alignment,     type INTEGER @SINCE_1_1.35
224       FLEX_MARGIN                               ///< name "flexMargin",         The space around the flex item,                                                                                                                                                                type VECTOR4 @SINCE_1_1.35
225     };
226   };
227
228   /**
229    * @brief Creates a FlexContainer handle; this can be initialized with FlexContainer::New()
230    * Calling member functions with an uninitialized handle is not allowed.
231    * @SINCE_1_1.35
232    */
233   FlexContainer();
234
235   /**
236    * @brief Copy constructor. Creates another handle that points to the same real object.
237    * @SINCE_1_1.35
238    *
239    * @param[in] handle The handle to copy from
240    */
241   FlexContainer( const FlexContainer& handle );
242
243   /**
244    * @brief Assignment operator. Changes this handle to point to another real object.
245    * @SINCE_1_1.35
246    * @param[in] handle Handle to an object
247    * @return A reference to this
248    */
249   FlexContainer& operator=( const FlexContainer& handle );
250
251   /**
252    * @brief Destructor.
253    *
254    * @details This is non-virtual since derived Handle types must not contain data or virtual methods.
255    *
256    * @SINCE_1_1.35
257    */
258   ~FlexContainer();
259
260   /**
261    * @brief Creates the FlexContainer control.
262    * @SINCE_1_1.35
263    *
264    * @return A handle to the FlexContainer control
265    */
266   static FlexContainer New();
267
268   /**
269    * @brief Downcasts an Object handle to FlexContainer.
270    *
271    * @details If handle points to a FlexContainer, the downcast produces valid handle.
272    * If not, the returned handle is left uninitialized.
273    *
274    * @SINCE_1_1.35
275    *
276    * @param[in] handle Handle to an object
277    * @return Handle to a FlexContainer or an uninitialized handle
278    */
279   static FlexContainer DownCast( BaseHandle handle );
280
281
282 public: // Not intended for application developers
283
284   /// @cond internal
285   /**
286    * @brief Creates a handle using the Toolkit::Internal implementation.
287    * @SINCE_1_1.35
288    *
289    * @param[in] implementation The Control implementation
290    */
291   DALI_INTERNAL FlexContainer( Internal::FlexContainer& implementation );
292
293   /**
294    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
295    * @SINCE_1_1.35
296    *
297    * @param[in] internal A pointer to the internal CustomActor
298    */
299   explicit DALI_INTERNAL FlexContainer( Dali::Internal::CustomActor* internal );
300   /// @endcond
301 };
302
303 /**
304  * @}
305  */
306 } // namespace Toolkit
307
308 } // namespace Dali
309
310 #endif // DALI_TOOLKIT_FLEX_CONTAINER_H