b8540e93e250bbbd802030d7abed1bc17da16af1
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-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) 2016 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  *     flex container
57  *    --------------------------------------------------------------- cross start
58  *    | ------------------ --------|--------------------------- |
59  *    | |                | |       |                          | |
60  *    | |                | |       |                          | |
61  *    | |  flex item 1   | |       |    flex item 2           | |  main axis
62  *    |-|----------------|-|-------|--------------------------|-|------------>
63  *    | |                | |       |                          | |
64  *    | |                | |       |                          | |
65  *    | |                | |       |                          | |
66  *    | ------------------ --------|--------------------------- |
67  *    -----------------------------|--------------------------------- cross end
68  *    |                            |                            |
69  *    | main start                 | cross axis                 | main end
70  *    |                            |                            |
71  *                                 v
72  *
73  * @nosubgrouping
74  * <h3>Per-child Custom properties for script supporting:</h3>
75  *
76  * The following custom properties of the actor are checked to decide how to lay out the
77  * actor inside the flex container.
78  *
79  * These properties are registered dynamically to the child and are non-animatable.
80  *
81  * | %Property Name          | Type        |
82  * |-------------------------|-------------|
83  * | flex                    | float       |
84  * | alignSelf               | integer     |
85  * | flexPadding             | Vector4     |
86  * | flexBorder              | Vector4     |
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  *   "customProperties": {
96  *     "flex":1,                        // property to make the item to receive the specified proportion of the free space in the container. If all items in the container use this pattern, their sizes will be proportional to the specified flex factor.
97  *     "alignSelf":"flexStart",         // property to specify how the item will align along the cross axis, if set, this overides the default alignment for all items in the container
98  *     "flexPadding":[10, 10, 10, 10],  // property to specify the space around the content (inside the flex border) of the item, if not set, default value is [0, 0, 0, 0]
99  *     "flexBorder":[5, 5, 5, 5],       // property to specify the border that goes around the flex padding and the content of the item, if not set, default value is [0, 0, 0, 0]
100  *     "flexMargin":[10, 10, 10, 10]    // property to specify the space outside the flex border, if not set, default value is [0, 0, 0, 0]
101  *   }
102  * @endcode
103  */
104
105 class DALI_IMPORT_API FlexContainer : public Control
106 {
107 public:
108
109   /**
110    * @brief The direction of the main axis in the flex container. This determines
111    * the direction that flex items are laid out in the flex container.
112    */
113   enum FlexDirection
114   {
115     COLUMN,                  ///< The flexible items are displayed vertically as a column
116     COLUMN_REVERSE,          ///< The flexible items are displayed vertically as a column, but in reverse order
117     ROW,                     ///< The flexible items are displayed horizontally as a row
118     ROW_REVERSE              ///< The flexible items are displayed horizontally as a row, but in reverse order
119   };
120
121   /**
122    * @brief The primary direction in which content is ordered in the flex container
123    * and on which sides the “start” and “end” are.
124    */
125   enum ContentDirection
126   {
127     INHERIT,                 ///< Inherits the same direction from the parent
128     LTR,                     ///< From left to right
129     RTL                      ///< From right to left
130   };
131
132   /**
133    * @brief Alignment of the flex items when the items do not use all available
134    * space on the main-axis.
135    */
136   enum Justification
137   {
138     JUSTIFY_FLEX_START,      ///< Items are positioned at the beginning of the container
139     JUSTIFY_CENTER,          ///< Items are positioned at the center of the container
140     JUSTIFY_FLEX_END,        ///< Items are positioned at the end of the container
141     JUSTIFY_SPACE_BETWEEN,   ///< Items are positioned with equal space between the lines
142     JUSTIFY_SPACE_AROUND     ///< Items are positioned with equal space before, between, and after the lines
143   };
144
145   /**
146    * @brief Alignment of the flex items or lines when the items or lines do not
147    * use all available space on the cross-axis.
148    */
149   enum Alignment
150   {
151     ALIGN_AUTO,              ///< Inherits the same alignment from the parent (only valid for "alignSelf" property)
152     ALIGN_FLEX_START,        ///< At the beginning of the container
153     ALIGN_CENTER,            ///< At the center of the container
154     ALIGN_FLEX_END,          ///< At the end of the container
155     ALIGN_STRETCH            ///< Stretch to fit the container
156   };
157
158   /**
159    * @brief The wrap type of the flex container when there is no enough room for
160    * all the items on one flex line.
161    */
162   enum WrapType
163   {
164     NO_WRAP,                 ///< Flex items laid out in single line (shrunk to fit the flex container along the main axis)
165     WRAP                     ///< Flex items laid out in multiple lines if needed
166   };
167
168 public:
169
170   /**
171    * @brief The start and end property ranges for this control.
172    */
173   enum PropertyRange
174   {
175     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
176     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000              ///< Reserve property indices
177   };
178
179   /**
180    * @brief An enumeration of properties belonging to the FlexContainer class.
181    */
182   struct Property
183   {
184     enum
185     {
186       CONTENT_DIRECTION = PROPERTY_START_INDEX, ///< name "contentDirection",   The primary direction in which content is ordered,                                                 @see FlexContainer::ContentDirection,  type INTEGER
187       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
188       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
189       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
190       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
191       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
192     };
193   };
194
195   /**
196    * Create a FlexContainer handle; this can be initialised with FlexContainer::New()
197    * Calling member functions with an uninitialised handle is not allowed.
198    */
199   FlexContainer();
200
201   /**
202    * Copy constructor. Creates another handle that points to the same real object
203    * @param handle to copy from
204    */
205   FlexContainer( const FlexContainer& handle );
206
207   /**
208    * Assignment operator. Changes this handle to point to another real object
209    */
210   FlexContainer& operator=( const FlexContainer& handle );
211
212   /**
213    * @brief Destructor
214    *
215    * This is non-virtual since derived Handle types must not contain data or virtual methods.
216    */
217   ~FlexContainer();
218
219   /**
220    * Create the FlexContainer control.
221    * @return A handle to the FlexContainer control.
222    */
223   static FlexContainer New();
224
225   /**
226    * Downcast an Object handle to FlexContainer. If handle points to a FlexContainer the
227    * downcast produces valid handle. If not the returned handle is left uninitialized.
228    * @param[in] handle Handle to an object
229    * @return handle to a FlexContainer or an uninitialized handle
230    */
231   static FlexContainer DownCast( BaseHandle handle );
232
233
234 public: // Not intended for application developers
235
236   /**
237    * @brief Creates a handle using the Toolkit::Internal implementation.
238    *
239    * @param[in] implementation The Control implementation.
240    */
241   DALI_INTERNAL FlexContainer( Internal::FlexContainer& implementation );
242
243   /**
244    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
245    *
246    * @param[in] internal A pointer to the internal CustomActor.
247    */
248   explicit DALI_INTERNAL FlexContainer( Dali::Internal::CustomActor* internal );
249 };
250
251 /**
252  * @}
253  */
254 } // namespace Toolkit
255
256 } // namespace Dali
257
258 #endif // __DALI_TOOLKIT_FLEX_CONTAINER_H__