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
88 * @brief Enumeration for the position type of the flex item how it is positioned within its parent.
90 enum class PositionType
92 RELATIVE, ///< Flex items laid out relatively
93 ABSOLUTE ///< Flex items laid out absolutely
97 * Struct used for MeasureCallback
101 SizeTuple( float x, float y ) : width( x ), height( y ){}
108 * @brief Callback signature for child Actor measure callback.
109 * @note Actor, child Actor to measure
110 * @note float, available width for child
111 * @note int, width measure specifcation mode
112 * @note float, available height for child
113 * @note int, height measure specification mode
115 using MeasureCallback = SizeTuple (*)( Dali::Actor, float , int , float , int );
118 * This class provides the API for calling into the Flex layout implementation.
120 class DALI_TOOLKIT_API Node
124 * @brief Constructor.
133 Node& operator=(Node&&) = default;
134 Node(Node&&) = default;
135 Node(const Node&) = delete;
136 Node& operator=(const Node&) = delete;
139 * @brief Insert child into the FlexLayout at the given index.
140 * @param[in] child Actor to insert.
141 * @param[in] margin of child Actor.
142 * @param[in] measureFunction for the child.
143 * @param[in] index to insert at.
144 * @return child node pointer
146 Node* AddChild( Actor child, Extents margin, MeasureCallback measureFunction, int index );
149 * @brief Remove child from the FlexLayout at the given index.
150 * @param[in] child child to be removed.
152 void RemoveChild( Actor child );
155 * @brief Return the dimensions of the node.
156 * @param[in] width width specification
157 * @param[in] widthMode width specification mode
158 * @param[in] height height specification
159 * @param[in] heightMode height specification mode
160 * @return Size tuple representing the width and height of the node
162 SizeTuple MeasureNode( float width, int widthMode, float height, int heightMode );
165 * @brief Perform the layout measure calculations.
166 * @param[in] availableWidth Amount of space available for layout, width.
167 * @param[in] availableHeight Amount of space available for layout, height.
168 * @param[in] isRTL Is the direction of the layout right to left.
170 void CalculateLayout( float availableWidth, float availableHeight, bool isRTL );
173 * @brief Get the calculated width of the given node.
174 * @return the width of the node
176 float GetFlexWidth() const;
179 * @brief Get the calculated height of the given node.
180 * @return the height of the node
182 float GetFlexHeight() const;
185 * @brief Get frame coordinates of the node at the given index.
186 * @param[in] index of the child
187 * @return Frame structure left x, top y, right z, bottom w
189 Vector4 GetNodeFrame(int index ) const;
192 * @brief Set the flex direction in the layout.
193 * The direction of the main-axis which determines the direction that flex items are laid out.
194 * @param[in] flexDirection The flex direction.
196 void SetFlexDirection( FlexDirection flexDirection );
199 * @brief Get the flex direction in the layout.
200 * @return The flex direction.
202 FlexDirection GetFlexDirection() const;
205 * @brief Set the justification in the layout.
206 * @param[in] flexJustification The flex justification.
208 void SetFlexJustification( Justification flexJustification );
211 * @brief Get the flex justification in the layout.
212 * @return The flex justification.
214 Justification GetFlexJustification() const;
217 * @brief Set the wrap in the layout.
218 * @param[in] flexWrap The flex wrap.
220 void SetFlexWrap(WrapType flexWrap );
223 * @brief Get the flex wrap in the layout.
224 * @return The flex wrap.
226 WrapType GetFlexWrap() const;
229 * @brief Set the alignment of the layout content.
230 * @param[in] flexAlignment The alignment of the content.
232 void SetFlexAlignment( Alignment flexAlignment );
235 * @brief Get the alignment of the layout content.
236 * @return The flex content alignment.
238 Alignment GetFlexAlignment() const;
241 * @brief Set the alignment of the layout items.
242 * @param[in] flexAlignment The alignment of the items.
244 void SetFlexItemsAlignment( Alignment flexAlignment );
247 * @brief Get the alignment of the layout items.
248 * @return The flex items alignment.
250 Alignment GetFlexItemsAlignment() const;
253 * @brief Set the alignment self of the layout items.
254 * @param[in] flexAlignmentSelf The alignment self of the items.
256 void SetFlexAlignmentSelf( Alignment flexAlignmentSelf );
259 * @brief Get the alignment self of the layout items.
260 * @return The flex items alignment self.
262 Alignment GetFlexAlignmentSelf() const;
265 * @brief Set the position type of the layout items.
266 * @param[in] flexPositionType The position type of the items.
268 void SetFlexPositionType( PositionType flexPositionType );
271 * @brief Get the position type of the layout items.
272 * @return The flex position type.
274 PositionType GetFlexPositionType() const;
277 * @brief Set the aspect ratio of the layout items.
278 * @param[in] flexAspectRatio The aspect ratio of the items.
280 void SetFlexAspectRatio( float flexAspectRatio );
283 * @brief Get the aspect ratio of the layout items.
284 * @return The flex aspect ratio.
286 float GetFlexAspectRatio() const;
289 * @brief Set the basis of the layout items.
290 * @param[in] flexBasis The basis of the items.
292 void SetFlexBasis( float flexBasis );
295 * @brief Get the basis of the layout items.
296 * @return The flex basis.
298 float GetFlexBasis() const;
301 * @brief Set the shrink of the layout items.
302 * @param[in] flexShrink The shrink of the items.
304 void SetFlexShrink( float flexShrink );
307 * @brief Get the shrink of the layout items.
308 * @return The flex shrink.
310 float GetFlexShrink() const;
313 * @brief Set the grow of the layout items.
314 * @param[in] flexGrow The grow of the items.
316 void SetFlexGrow( float flexGrow );
319 * @brief Get the grow of the layout items.
320 * @return The flex grow.
322 float GetFlexGrow() const;
325 * @brief Set the margin.
326 * @param[in] margin The margin value.
328 void SetMargin( Extents margin );
331 * @brief Set the padding.
332 * @param[in] padding The padding value.
334 void SetPadding( Extents padding );
338 std::unique_ptr< Impl > mImpl;
344 } // namespace Toolkit
347 #endif // DALI_TOOLKIT_LAYOUTING_FLEX_NODE_H