Merge "Fixed the appearance of a bold text when setting underline property." into...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / flex-container / flex-container-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__
2 #define __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__
3
4 /*
5  * Copyright (c) 2017 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/weak-handle.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/flex-container/flex-container.h>
27 extern "C"
28 {
29 #include <dali-toolkit/third-party/facebook-flexbox/layout.h>
30 }
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 /**
42  * FlexContainer is a custom control for laying out actors in a flexbox layout
43  * @see Dali::Toolkit:FlexContainer for more details
44  */
45 class FlexContainer : public Control
46 {
47 public:
48
49   /**
50    * The structure to store the style properties and layout information of flex item
51    */
52   struct FlexItemNode
53   {
54     WeakHandle< Dali::Actor > actor;      ///< Actor handle of the flex item
55     css_node_t* node;                     ///< The style properties and layout information
56   };
57
58   typedef std::vector< FlexItemNode > FlexItemNodeContainer;
59
60 public:
61
62   /**
63    * Construct a new FlexContainer.
64    */
65   FlexContainer();
66
67   /**
68    * Create a new FlexContainer.
69    * @return A smart-pointer to the newly allocated FlexContainer.
70    */
71   static Toolkit::FlexContainer New();
72
73   /**
74    * @brief Set the primary direction in which content is ordered.
75    * @param[in] contentDirection The direction of the content.
76    */
77   void SetContentDirection(Toolkit::FlexContainer::ContentDirection contentDirection);
78
79   /**
80    * @brief Get the direction of the content.
81    * @return The direction of the content.
82    */
83   Toolkit::FlexContainer::ContentDirection GetContentDirection();
84
85   /**
86    * @brief Set the direction flex items are laid out.
87    * @param[in] flexDirection The direction flex items are laid out.
88    */
89   void SetFlexDirection(Toolkit::FlexContainer::FlexDirection flexDirection);
90
91   /**
92    * @brief Get the direction flex items are laid out.
93    * @return The direction flex items are laid out.
94    */
95   Toolkit::FlexContainer::FlexDirection GetFlexDirection();
96
97   /**
98    * @brief Set whether the flex items should wrap or not, if there
99    * is no enough room for them on one flex line.
100    * @param[in] flexWrap The wrap type.
101    */
102   void SetFlexWrap(Toolkit::FlexContainer::WrapType flexWrap);
103
104   /**
105    * @brief Get whether the flex items should wrap or not, if there
106    * is no enough room for them on one flex line.
107    * @return The wrap type.
108    */
109   Toolkit::FlexContainer::WrapType GetFlexWrap();
110
111   /**
112    * @brief Set the horizontal alignment of the flex items when the items
113    * do not use all available space on the main-axis.
114    * @param[in] justifyContent The horizontal alignment of flex items.
115    */
116   void SetJustifyContent(Toolkit::FlexContainer::Justification justifyContent);
117
118   /**
119    * @brief Get the horizontal alignment of the flex items when the items
120    * do not use all available space on the main-axis.
121    * @return The horizontal alignment of flex items.
122    */
123   Toolkit::FlexContainer::Justification GetJustifyContent();
124
125   /**
126    * @brief Set the vertical alignment of the flex items when the items
127    * do not use all available space on the cross-axis.
128    * @param[in] alignItems The vertical alignment of flex items.
129    */
130   void SetAlignItems(Toolkit::FlexContainer::Alignment alignItems);
131
132   /**
133    * @brief Get the vertical alignment of the flex items when the items
134    * do not use all available space on the cross-axis.
135    * @return The vertical alignment of flex items.
136    */
137   Toolkit::FlexContainer::Alignment GetAlignItems();
138
139   /**
140    * @brief Set the vertical alignment of the flex lines when the lines
141    * do not use all available space on the cross-axis.
142    * @param[in] alignItems The vertical alignment of flex lines.
143    */
144   void SetAlignContent(Toolkit::FlexContainer::Alignment alignContent);
145
146   /**
147    * @brief Get the vertical alignment of the flex lines when the lines
148    * do not use all available space on the cross-axis.
149    * @return The vertical alignment of flex lines.
150    */
151   Toolkit::FlexContainer::Alignment GetAlignContent();
152
153   // Properties
154
155   /**
156    * Called when a property of an object of this type is set.
157    * @param[in] object The object whose property is set.
158    * @param[in] index The property index.
159    * @param[in] value The new property value.
160    */
161   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
162
163   /**
164    * Called to retrieve a property of an object of this type.
165    * @param[in] object The object whose property is to be retrieved.
166    * @param[in] index The property index.
167    * @return The current value of the property.
168    */
169   static Property::Value GetProperty( BaseObject* object, Property::Index index );
170
171 private: // From Control
172
173   /**
174    * @copydoc Control::OnInitialize()
175    */
176   virtual void OnInitialize();
177
178   /**
179    * @copydoc Control::OnChildAdd(Actor& child)
180    */
181   virtual void OnChildAdd( Actor& child );
182
183   /**
184    * @copydoc Control::OnChildRemove(Actor& child)
185    */
186   virtual void OnChildRemove( Actor& child );
187
188   /**
189    * @copydoc Control::OnRelayout
190    */
191   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
192
193   /**
194    * @copydoc Control::RelayoutDependentOnChildren()
195    */
196   virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
197
198   /**
199    * @copydoc Control::GetNextKeyboardFocusableActor
200    */
201   virtual Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
202
203   /**
204    * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
205    */
206   virtual void OnSizeSet( const Vector3& size );
207
208   /**
209   * @copydoc OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type )
210   * @param[in] actor The actor whose layoutDirection is changed.
211   * @param[in] type  The layoutDirection.
212   */
213   void OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type );
214
215 private: // Implementation
216
217   /**
218    * Calculate the layout properties of all the children
219    */
220   void ComputeLayout();
221
222   /**
223    * Calculate the layout of the children and relayout them with their new size and position
224    */
225   void RelayoutChildren();
226
227   /**
228    * A reference counted object may only be deleted by calling Unreference()
229    */
230   virtual ~FlexContainer();
231
232 private:
233
234   // Undefined copy constructor and assignment operators
235   FlexContainer(const FlexContainer&);
236   FlexContainer& operator=(const FlexContainer& rhs);
237
238 private: // Data
239
240   FlexItemNode mRootNode;                    ///< Style properties and layout information of flex container
241   FlexItemNodeContainer mChildrenNodes;      ///< Style properties and layout information of flex items in the container
242
243   Toolkit::FlexContainer::ContentDirection mContentDirection;        ///< The content direction of the container
244   Toolkit::FlexContainer::FlexDirection mFlexDirection;              ///< The flex direction of the container
245   Toolkit::FlexContainer::WrapType mFlexWrap;                        ///< The wrap type of the container
246   Toolkit::FlexContainer::Justification mJustifyContent;             ///< The alignment of flex items in the container on the main-axis
247   Toolkit::FlexContainer::Alignment mAlignItems;                     ///< The alignment of flex items in the container on the cross-axis
248   Toolkit::FlexContainer::Alignment mAlignContent;                   ///< The alignment of flex lines in the container on the cross-axis
249 };
250
251 } // namespace Internal
252
253 // Helpers for public-api forwarding methods
254
255 inline Toolkit::Internal::FlexContainer& GetImpl( Toolkit::FlexContainer& flexContainer )
256 {
257   DALI_ASSERT_ALWAYS(flexContainer);
258
259   Dali::RefObject& handle = flexContainer.GetImplementation();
260
261   return static_cast<Toolkit::Internal::FlexContainer&>(handle);
262 }
263
264 inline const Toolkit::Internal::FlexContainer& GetImpl( const Toolkit::FlexContainer& flexContainer )
265 {
266   DALI_ASSERT_ALWAYS(flexContainer);
267
268   const Dali::RefObject& handle = flexContainer.GetImplementation();
269
270   return static_cast<const Toolkit::Internal::FlexContainer&>(handle);
271 }
272
273 } // namespace Toolkit
274
275 } // namespace Dali
276
277 #endif // __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__