1 #ifndef __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__
2 #define __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__
5 * Copyright (c) 2017 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/devel-api/object/weak-handle.h>
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/flex-container/flex-container.h>
29 #include <dali-toolkit/third-party/facebook-flexbox/layout.h>
42 * FlexContainer is a custom control for laying out actors in a flexbox layout
43 * @see Dali::Toolkit:FlexContainer for more details
45 class FlexContainer : public Control
50 * The structure to store the style properties and layout information of flex item
54 WeakHandle< Dali::Actor > actor; ///< Actor handle of the flex item
55 css_node_t* node; ///< The style properties and layout information
58 typedef std::vector< FlexItemNode > FlexItemNodeContainer;
63 * Construct a new FlexContainer.
68 * Create a new FlexContainer.
69 * @return A smart-pointer to the newly allocated FlexContainer.
71 static Toolkit::FlexContainer New();
74 * @brief Set the primary direction in which content is ordered.
75 * @param[in] contentDirection The direction of the content.
77 void SetContentDirection(Toolkit::FlexContainer::ContentDirection contentDirection);
80 * @brief Get the direction of the content.
81 * @return The direction of the content.
83 Toolkit::FlexContainer::ContentDirection GetContentDirection();
86 * @brief Set the direction flex items are laid out.
87 * @param[in] flexDirection The direction flex items are laid out.
89 void SetFlexDirection(Toolkit::FlexContainer::FlexDirection flexDirection);
92 * @brief Get the direction flex items are laid out.
93 * @return The direction flex items are laid out.
95 Toolkit::FlexContainer::FlexDirection GetFlexDirection();
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.
102 void SetFlexWrap(Toolkit::FlexContainer::WrapType flexWrap);
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.
109 Toolkit::FlexContainer::WrapType GetFlexWrap();
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.
116 void SetJustifyContent(Toolkit::FlexContainer::Justification justifyContent);
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.
123 Toolkit::FlexContainer::Justification GetJustifyContent();
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.
130 void SetAlignItems(Toolkit::FlexContainer::Alignment alignItems);
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.
137 Toolkit::FlexContainer::Alignment GetAlignItems();
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.
144 void SetAlignContent(Toolkit::FlexContainer::Alignment alignContent);
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.
151 Toolkit::FlexContainer::Alignment GetAlignContent();
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.
161 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
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.
169 static Property::Value GetProperty( BaseObject* object, Property::Index index );
171 private: // From Control
174 * @copydoc Control::OnInitialize()
176 virtual void OnInitialize();
179 * @copydoc Control::OnChildAdd(Actor& child)
181 virtual void OnChildAdd( Actor& child );
184 * @copydoc Control::OnChildRemove(Actor& child)
186 virtual void OnChildRemove( Actor& child );
189 * @copydoc Control::OnRelayout
191 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
194 * @copydoc Control::RelayoutDependentOnChildren()
196 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
199 * @copydoc Control::GetNextKeyboardFocusableActor
201 virtual Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
204 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
206 virtual void OnSizeSet( const Vector3& size );
208 private: // Implementation
211 * Calculate the layout properties of all the children
213 void ComputeLayout();
216 * Calculate the layout of the children and relayout them with their new size and position
218 void RelayoutChildren();
221 * A reference counted object may only be deleted by calling Unreference()
223 virtual ~FlexContainer();
227 // Undefined copy constructor and assignment operators
228 FlexContainer(const FlexContainer&);
229 FlexContainer& operator=(const FlexContainer& rhs);
233 FlexItemNode mRootNode; ///< Style properties and layout information of flex container
234 FlexItemNodeContainer mChildrenNodes; ///< Style properties and layout information of flex items in the container
236 Toolkit::FlexContainer::ContentDirection mContentDirection; ///< The content direction of the container
237 Toolkit::FlexContainer::FlexDirection mFlexDirection; ///< The flex direction of the container
238 Toolkit::FlexContainer::WrapType mFlexWrap; ///< The wrap type of the container
239 Toolkit::FlexContainer::Justification mJustifyContent; ///< The alignment of flex items in the container on the main-axis
240 Toolkit::FlexContainer::Alignment mAlignItems; ///< The alignment of flex items in the container on the cross-axis
241 Toolkit::FlexContainer::Alignment mAlignContent; ///< The alignment of flex lines in the container on the cross-axis
244 } // namespace Internal
246 // Helpers for public-api forwarding methods
248 inline Toolkit::Internal::FlexContainer& GetImpl( Toolkit::FlexContainer& flexContainer )
250 DALI_ASSERT_ALWAYS(flexContainer);
252 Dali::RefObject& handle = flexContainer.GetImplementation();
254 return static_cast<Toolkit::Internal::FlexContainer&>(handle);
257 inline const Toolkit::Internal::FlexContainer& GetImpl( const Toolkit::FlexContainer& flexContainer )
259 DALI_ASSERT_ALWAYS(flexContainer);
261 const Dali::RefObject& handle = flexContainer.GetImplementation();
263 return static_cast<const Toolkit::Internal::FlexContainer&>(handle);
266 } // namespace Toolkit
270 #endif // __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__