1 #ifndef DALI_TOOLKIT_LAYOUTING_FLEX_NODE_H
2 #define DALI_TOOLKIT_LAYOUTING_FLEX_NODE_H
5 * Copyright (c) 2019 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/common/dali-common.h>
23 #include <dali/public-api/actors/actor.h>
26 #include <dali-toolkit/public-api/dali-toolkit-common.h>
39 * @brief Enumeration for the direction of the main axis in the flex container. This determines
40 * the direction that flex items are laid out in the flex container.
42 enum class FlexDirection
44 COLUMN, ///< The flexible items are displayed vertically as a column
45 COLUMN_REVERSE, ///< The flexible items are displayed vertically as a column, but in reverse order
46 ROW, ///< The flexible items are displayed horizontally as a row
47 ROW_REVERSE ///< The flexible items are displayed horizontally as a row, but in reverse order
51 * @brief Enumeration for the alignment of the flex items when the items do not use all available
52 * space on the main-axis.
54 enum class Justification
56 FLEX_START, ///< Items are positioned at the beginning of the container
57 CENTER, ///< Items are positioned at the center of the container
58 FLEX_END, ///< Items are positioned at the end of the container
59 SPACE_BETWEEN, ///< Items are positioned with equal space between the items
60 SPACE_AROUND ///< Items are positioned with equal space before, between, and after the items
64 * @brief Enumeration for the wrap type of the flex container when there is not enough room for
65 * all the items on one flex line.
69 NO_WRAP, ///< Flex items laid out in single line (shrunk to fit the flex container along the main axis)
70 WRAP ///< Flex items laid out in multiple lines if needed
74 * @brief Enumeration for the alignment of the flex items or lines when the items or lines do not
75 * use all the available space on the cross-axis.
79 AUTO, ///< Currently unsupported, placeholder for inheritance of parent alignment.
81 FLEX_START, ///< At the beginning of the container
82 CENTER, ///< At the center of the container
83 FLEX_END, ///< At the end of the container
84 STRETCH ///< Stretch to fit the container
89 * Struct used for MeasureCallback
93 SizeTuple( float x, float y ) : width( x ), height( y ){}
100 * @brief Callback signature for child Actor measure callback.
101 * @note Actor, child Actor to measure
102 * @note float, available width for child
103 * @note int, width measure specifcation mode
104 * @note float, available height for child
105 * @note int, height measure specification mode
107 using MeasureCallback = SizeTuple (*)( Dali::Actor, float , int , float , int );
110 * This class provides the API for calling into the Flex layout implementation.
112 class DALI_TOOLKIT_API Node
116 * @brief Constructor.
125 Node& operator=(Node&&) = default;
126 Node(Node&&) = default;
127 Node(const Node&) = delete;
128 Node& operator=(const Node&) = delete;
131 * @brief Insert child into the FlexLayout at the given index.
132 * @param[in] child Actor to insert.
133 * @param[in] measureFunction for the child.
134 * @param[in] index to insert at.
136 void AddChild( Actor child, MeasureCallback measureFunction, int index );
139 * @brief Remove child from the FlexLayout at the given index.
140 * @param[in] child child to be removed.
142 void RemoveChild( Actor child );
145 * @brief Return the dimensions of the node.
146 * @param[in] width width specification
147 * @param[in] widthMode width specification mode
148 * @param[in] height height specification
149 * @param[in] heightMode height specification mode
150 * @return Size tuple representing the width and height of the node
152 SizeTuple MeasureNode( float width, int widthMode, float height, int heightMode );
155 * @brief Perform the layout measure calculations.
156 * @param[in] availableWidth Amount of space available for layout, width.
157 * @param[in] availableHeight Amount of space available for layout, height.
158 * @param[in] isRTL Is the direction of the layout right to left.
160 void CalculateLayout( float availableWidth, float availableHeight, bool isRTL );
163 * @brief Get the calculated width of the given node.
164 * @return the width of the node
166 float GetFlexWidth() const;
169 * @brief Get the calculated height of the given node.
170 * @return the height of the node
172 float GetFlexHeight() const;
175 * @brief Get frame coordinates of the node at the given index.
176 * @param[in] index of the child
177 * @return Frame structure left x, top y, right z, bottom w
179 Vector4 GetNodeFrame(int index ) const;
182 * @brief Set the flex direction in the layout.
183 * The direction of the main-axis which determines the direction that flex items are laid out.
184 * @param[in] flexDirection The flex direction.
186 void SetFlexDirection( FlexDirection flexDirection );
189 * @brief Get the flex direction in the layout.
190 * @return The flex direction.
192 FlexDirection GetFlexDirection() const;
195 * @brief Set the justification in the layout.
196 * @param[in] flexJustification The flex justification.
198 void SetFlexJustification( Justification flexJustification );
201 * @brief Get the flex justification in the layout.
202 * @return The flex justification.
204 Justification GetFlexJustification() const;
207 * @brief Set the wrap in the layout.
208 * @param[in] flexWrap The flex wrap.
210 void SetFlexWrap(WrapType flexWrap );
213 * @brief Get the flex wrap in the layout.
214 * @return The flex wrap.
216 WrapType GetFlexWrap() const;
219 * @brief Set the alignment of the layout content.
220 * @param[in] flexAlignment The alignment of the content.
222 void SetFlexAlignment( Alignment flexAlignment );
225 * @brief Get the alignment of the layout content.
226 * @return The flex content alignment.
228 Alignment GetFlexAlignment() const;
231 * @brief Set the alignment of the layout items.
232 * @param[in] flexAlignment The alignment of the items.
234 void SetFlexItemsAlignment( Alignment flexAlignment );
237 * @brief Get the alignment of the layout items.
238 * @return The flex items alignment.
240 Alignment GetFlexItemsAlignment() const;
243 * @brief Set the margin.
244 * @param[in] margin The margin value.
246 void SetMargin( Extents margin );
249 * @brief Set the padding.
250 * @param[in] padding The padding value.
252 void SetPadding( Extents padding );
256 std::unique_ptr< Impl > mImpl;
262 } // namespace Toolkit
265 #endif // DALI_TOOLKIT_LAYOUTING_FLEX_NODE_H