1 #ifndef DALI_TOOLKIT_LAYOUTING_FLEX_LAYOUT_H
2 #define DALI_TOOLKIT_LAYOUTING_FLEX_LAYOUT_H
5 * Copyright (c) 2018 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.
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/object/base-handle.h>
22 #include <dali-toolkit/public-api/dali-toolkit-common.h>
23 #include <dali-toolkit/devel-api/layouting/layout-group.h>
24 #include <dali-toolkit/devel-api/layouting/layout-size.h>
31 namespace Internal DALI_INTERNAL
37 * This class implements a flex layout.
39 * The flex layout implementation is based on open source Facebook Yoga layout engine.
40 * For more information about the flex layout API and how to use it please refer to
41 * https://yogalayout.com/docs/
42 * We implement the subset of the API in the class below.
44 class DALI_TOOLKIT_API FlexLayout : public LayoutGroup
50 CHILD_PROPERTY_START_INDEX = FLEX_LAYOUT_CHILD_PROPERTY_START_INDEX,
51 CHILD_PROPERTY_END_INDEX = FLEX_LAYOUT_CHILD_PROPERTY_END_INDEX
55 * @brief Enumeration for the direction of the main axis in the flex container. This determines
56 * the direction that flex items are laid out in the flex container.
58 enum class FlexDirection
60 COLUMN, ///< The flexible items are displayed vertically as a column
61 COLUMN_REVERSE, ///< The flexible items are displayed vertically as a column, but in reverse order
62 ROW, ///< The flexible items are displayed horizontally as a row
63 ROW_REVERSE ///< The flexible items are displayed horizontally as a row, but in reverse order
67 * @brief Enumeration for the alignment of the flex items when the items do not use all available
68 * space on the main-axis.
70 enum class Justification
72 FLEX_START, ///< Items are positioned at the beginning of the container
73 CENTER, ///< Items are positioned at the center of the container
74 FLEX_END, ///< Items are positioned at the end of the container
75 SPACE_BETWEEN, ///< Items are positioned with equal space between the lines
76 SPACE_AROUND ///< Items are positioned with equal space before, between, and after the lines
80 * @brief Enumeration for the alignment of the flex items or lines when the items or lines do not
81 * use all the available space on the cross-axis.
87 AUTO, ///< Inherits the same alignment from the parent (only valid for "alignSelf" property)
88 FLEX_START, ///< At the beginning of the container
89 CENTER, ///< At the center of the container
90 FLEX_END, ///< At the end of the container
91 STRETCH ///< Stretch to fit the container
96 * @brief Enumeration for the wrap type of the flex container when there is no enough room for
97 * all the items on one flex line.
101 NO_WRAP, ///< Flex items laid out in single line (shrunk to fit the flex container along the main axis)
102 WRAP ///< Flex items laid out in multiple lines if needed
109 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
110 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, type INTEGER
115 * @brief Creates an uninitialized FlexLayout handle.
117 * Initialize it using FlexLayout::New().
118 * Calling member functions with an uninitialized handle is not allowed.
123 * @brief Creates a FlexLayout object.
125 static FlexLayout New();
128 * @brief Downcasts a handle to a FlexLayout handle.
130 * If handle points to a FlexLayout, the downcast produces a valid handle.
131 * If not, the returned handle is left uninitialized.
133 * @param[in] handle to an object
134 * @return Handle to a FlexLayout or an uninitialized handle
136 static FlexLayout DownCast( BaseHandle handle );
139 * @brief Copy constructor
141 FlexLayout( const FlexLayout& other );
144 * @brief Assigment operator
146 FlexLayout& operator=( const FlexLayout& other );
149 * @brief Default destructor.
151 * This is non-virtual, since derived Handle types must not contain data or virtual methods
153 ~FlexLayout()=default;
156 * @brief Set the flex direction in the layout.
157 * The direction of the main-axis which determines the direction that flex items are laid out.
159 * @param[in] flexDirection The flex direction.
161 void SetFlexDirection( FlexDirection flexDirection );
164 * @brief Get the flex direction in the layout.
166 * @return The flex direction.
168 FlexDirection GetFlexDirection() const;
171 * @brief Set the justification in the layout.
173 * @param[in] flexJustification The flex justification.
175 void SetFlexJustification( Justification flexJustification );
178 * @brief Get the flex justification in the layout.
180 * @return The flex justification.
182 Justification GetFlexJustification() const;
185 * @brief Set the wrap in the layout.
187 * @param[in] flexWrap The flex wrap.
189 void SetFlexWrap( WrapType flexWrap );
192 * @brief Get the flex wrap in the layout.
194 * @return The flex wrap.
196 WrapType GetFlexWrap() const;
199 * @brief Set the alignment of the layout content.
201 * @param[in] flexAlignment The alignment of the content.
203 void SetFlexAlignment( Alignment::Type flexAlignment );
206 * @brief Get the alignment of the layout content.
208 * @return The flex content alignment.
210 Alignment::Type GetFlexAlignment() const;
213 * @brief Set the alignment of the layout items.
215 * @param[in] flexAlignment The alignment of the items.
217 void SetFlexItemsAlignment( Alignment::Type flexAlignment );
220 * @brief Get the alignment of the layout items.
222 * @return The flex items alignment.
224 Alignment::Type GetFlexItemsAlignment() const;
226 public: // Not intended for application developers
230 * @brief This constructor is used by FlexLayout::New() methods.
232 * @param[in] actor A pointer to a newly allocated Dali resource
234 explicit DALI_INTERNAL FlexLayout( Internal::FlexLayout* body );
238 } // namespace Toolkit
241 #endif // DALI_TOOLKIT_LAYOUTING_FLEX_LAYOUT_H