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/public-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>
27 #include <dali-toolkit/third-party/yoga/Yoga.h>
39 * FlexContainer is a custom control for laying out actors in a flexbox layout
40 * @see Dali::Toolkit:FlexContainer for more details
42 class FlexContainer : public Control
47 * The structure to store the style properties and layout information of flex item
51 WeakHandle< Dali::Actor > actor; ///< Actor handle of the flex item
52 YGNodeRef node; ///< The style properties and layout information
55 typedef std::vector< FlexItemNode > FlexItemNodeContainer;
60 * Construct a new FlexContainer.
65 * Create a new FlexContainer.
66 * @return A smart-pointer to the newly allocated FlexContainer.
68 static Toolkit::FlexContainer New();
71 * @brief Set the primary direction in which content is ordered.
72 * @param[in] contentDirection The direction of the content.
74 void SetContentDirection(Toolkit::FlexContainer::ContentDirection contentDirection);
77 * @brief Get the direction of the content.
78 * @return The direction of the content.
80 Toolkit::FlexContainer::ContentDirection GetContentDirection();
83 * @brief Set the direction flex items are laid out.
84 * @param[in] flexDirection The direction flex items are laid out.
86 void SetFlexDirection(Toolkit::FlexContainer::FlexDirection flexDirection);
89 * @brief Get the direction flex items are laid out.
90 * @return The direction flex items are laid out.
92 Toolkit::FlexContainer::FlexDirection GetFlexDirection();
95 * @brief Set whether the flex items should wrap or not, if there
96 * is no enough room for them on one flex line.
97 * @param[in] flexWrap The wrap type.
99 void SetFlexWrap(Toolkit::FlexContainer::WrapType flexWrap);
102 * @brief Get whether the flex items should wrap or not, if there
103 * is no enough room for them on one flex line.
104 * @return The wrap type.
106 Toolkit::FlexContainer::WrapType GetFlexWrap();
109 * @brief Set the horizontal alignment of the flex items when the items
110 * do not use all available space on the main-axis.
111 * @param[in] justifyContent The horizontal alignment of flex items.
113 void SetJustifyContent(Toolkit::FlexContainer::Justification justifyContent);
116 * @brief Get the horizontal alignment of the flex items when the items
117 * do not use all available space on the main-axis.
118 * @return The horizontal alignment of flex items.
120 Toolkit::FlexContainer::Justification GetJustifyContent();
123 * @brief Set the vertical alignment of the flex items when the items
124 * do not use all available space on the cross-axis.
125 * @param[in] alignItems The vertical alignment of flex items.
127 void SetAlignItems(Toolkit::FlexContainer::Alignment alignItems);
130 * @brief Get the vertical alignment of the flex items when the items
131 * do not use all available space on the cross-axis.
132 * @return The vertical alignment of flex items.
134 Toolkit::FlexContainer::Alignment GetAlignItems();
137 * @brief Set the vertical alignment of the flex lines when the lines
138 * do not use all available space on the cross-axis.
139 * @param[in] alignItems The vertical alignment of flex lines.
141 void SetAlignContent(Toolkit::FlexContainer::Alignment alignContent);
144 * @brief Get the vertical alignment of the flex lines when the lines
145 * do not use all available space on the cross-axis.
146 * @return The vertical alignment of flex lines.
148 Toolkit::FlexContainer::Alignment GetAlignContent();
153 * Called when a property of an object of this type is set.
154 * @param[in] object The object whose property is set.
155 * @param[in] index The property index.
156 * @param[in] value The new property value.
158 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
161 * Called to retrieve a property of an object of this type.
162 * @param[in] object The object whose property is to be retrieved.
163 * @param[in] index The property index.
164 * @return The current value of the property.
166 static Property::Value GetProperty( BaseObject* object, Property::Index index );
168 private: // From Control
171 * @copydoc Control::OnInitialize()
173 virtual void OnInitialize();
176 * @copydoc Control::OnChildAdd(Actor& child)
178 virtual void OnChildAdd( Actor& child );
181 * @copydoc Control::OnChildRemove(Actor& child)
183 virtual void OnChildRemove( Actor& child );
186 * @copydoc Control::OnRelayout
188 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
191 * @copydoc Control::RelayoutDependentOnChildren()
193 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
196 * @copydoc Control::GetNextKeyboardFocusableActor
198 virtual Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
201 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
203 virtual void OnSizeSet( const Vector3& size );
206 * @copydoc OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type )
207 * @param[in] actor The actor whose layoutDirection is changed.
208 * @param[in] type The layoutDirection.
210 void OnLayoutDirectionChanged( Dali::Actor actor, Dali::LayoutDirection::Type type );
212 private: // Implementation
215 * Calculate the layout properties of all the children
217 void ComputeLayout();
220 * Calculate the layout of the children and relayout them with their new size and position
222 void RelayoutChildren();
225 * A reference counted object may only be deleted by calling Unreference()
227 virtual ~FlexContainer();
231 // Undefined copy constructor and assignment operators
232 FlexContainer(const FlexContainer&);
233 FlexContainer& operator=(const FlexContainer& rhs);
237 FlexItemNode mRootNode; ///< Style properties and layout information of flex container
238 FlexItemNodeContainer mChildrenNodes; ///< Style properties and layout information of flex items in the container
240 Toolkit::FlexContainer::ContentDirection mContentDirection; ///< The content direction of the container
241 Toolkit::FlexContainer::FlexDirection mFlexDirection; ///< The flex direction of the container
242 Toolkit::FlexContainer::WrapType mFlexWrap; ///< The wrap type of the container
243 Toolkit::FlexContainer::Justification mJustifyContent; ///< The alignment of flex items in the container on the main-axis
244 Toolkit::FlexContainer::Alignment mAlignItems; ///< The alignment of flex items in the container on the cross-axis
245 Toolkit::FlexContainer::Alignment mAlignContent; ///< The alignment of flex lines in the container on the cross-axis
248 } // namespace Internal
250 // Helpers for public-api forwarding methods
252 inline Toolkit::Internal::FlexContainer& GetImpl( Toolkit::FlexContainer& flexContainer )
254 DALI_ASSERT_ALWAYS(flexContainer);
256 Dali::RefObject& handle = flexContainer.GetImplementation();
258 return static_cast<Toolkit::Internal::FlexContainer&>(handle);
261 inline const Toolkit::Internal::FlexContainer& GetImpl( const Toolkit::FlexContainer& flexContainer )
263 DALI_ASSERT_ALWAYS(flexContainer);
265 const Dali::RefObject& handle = flexContainer.GetImplementation();
267 return static_cast<const Toolkit::Internal::FlexContainer&>(handle);
270 } // namespace Toolkit
274 #endif // __DALI_TOOLKIT_INTERNAL_FLEX_CONTAINER_H__