1 #ifndef DALI_TOOLKIT_GRID_LAYOUT_H
2 #define DALI_TOOLKIT_GRID_LAYOUT_H
5 * Copyright (c) 2021 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.
23 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-layout.h>
25 #include <dali-toolkit/public-api/dali-toolkit-common.h>
35 typedef IntrusivePtr<GridLayout> GridLayoutPtr; ///< Pointer to a Dali::Toolkit::GridLayout object
38 * @brief An ItemView layout which arranges items in a grid.
40 class GridLayout : public ItemLayout
44 * @brief Create a new grid layout.
46 static GridLayoutPtr New();
49 * @brief Virtual destructor.
51 virtual ~GridLayout();
54 * Apply grid layout Properties.
55 * @param[in] properties The properties of the layout.
57 void SetGridLayoutProperties(const Property::Map& properties);
60 * @brief Set the number of columns in the layout.
62 * @param[in] columns The number of columns.
64 void SetNumberOfColumns(unsigned int columns);
67 * @brief Get the number of columns in the layout.
69 * @return The number of columns.
71 unsigned int GetNumberOfColumns() const;
74 * @brief Set the spacing between rows.
76 * @param[in] spacing The row spacing.
78 void SetRowSpacing(float spacing);
81 * @brief Get the spacing between rows.
83 * @return The row spacing.
85 float GetRowSpacing() const;
88 * @brief Set the spacing between columns.
90 * @param[in] spacing The row spacing.
92 void SetColumnSpacing(float spacing);
95 * @brief Get the spacing between columns.
97 * @return The row spacing.
99 float GetColumnSpacing() const;
102 * @brief Set the margin in the top of the layout.
104 * @param[in] margin The layout top margin.
106 void SetTopMargin(float margin);
109 * @brief Get the margin in the top of the layout.
111 * @return The layout top margin.
113 float GetTopMargin() const;
116 * @brief Set the margin in the bottom of the layout.
118 * @param[in] margin The layout bottom margin.
120 void SetBottomMargin(float margin);
123 * @brief Get the margin in the bottom of the layout.
125 * @return The layout bottom margin.
127 float GetBottomMargin() const;
130 * @brief Set the margin in the left and right of the layout.
132 * @param[in] margin The layout side margin.
134 void SetSideMargin(float margin);
137 * @brief Get the margin in the left and right of the layout.
139 * @return The layout side margin.
141 float GetSideMargin() const;
144 * @brief Set the gap of items in the Z axis in different columns.
146 * @param[in] gap The gap of items.
148 void SetZGap(float gap);
151 * @brief Get the gap of items in the Z axis in different columns.
153 * @return The gap of items.
155 float GetZGap() const;
158 * @brief Set the factor used to customise the scroll speed while dragging and swiping the layout.
160 * @param[in] scrollSpeed The scroll speed factor.
162 void SetScrollSpeedFactor(float scrollSpeed);
165 * @brief Set the maximum swipe speed in pixels per second.
167 * @param[in] speed The maximum swipe speed.
169 void SetMaximumSwipeSpeed(float speed);
172 * @brief Set the duration of the flick animation in seconds.
174 * This is the time taken to animate each item to its next layout
175 * position (e.g. from 1.0 to 2.0) when a flick animation is
176 * triggered by a swipe gesture.
178 * @pre durationSeconds must be greater than zero.
179 * @param[in] durationSeconds The duration of flick animation in seconds.
181 void SetItemFlickAnimationDuration(float durationSeconds);
184 * @copydoc ItemLayout::GetScrollSpeedFactor()
186 float GetScrollSpeedFactor() const override;
189 * @copydoc ItemLayout::GetMaximumSwipeSpeed()
191 float GetMaximumSwipeSpeed() const override;
194 * @copydoc ItemLayout::GetItemFlickAnimationDuration()
196 float GetItemFlickAnimationDuration() const override;
199 * @copydoc ItemLayout::GetClosestOnScreenLayoutPosition()
201 float GetClosestOnScreenLayoutPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize) override;
204 * @copydoc ItemLayout::GetNextFocusItemID()
206 int GetNextFocusItemID(int itemID, int maxItems, Dali::Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled) override;
210 * @copydoc ItemLayout::GetMinimumLayoutPosition()
212 float GetMinimumLayoutPosition(unsigned int numberOfItems, Vector3 layoutSize) const override;
215 * @copydoc ItemLayout::GetClosestAnchorPosition()
217 float GetClosestAnchorPosition(float layoutPosition) const override;
220 * @copydoc ItemLayout::GetItemScrollToPosition()
222 float GetItemScrollToPosition(unsigned int itemId) const override;
225 * @copydoc ItemLayout::GetItemsWithinArea()
227 ItemRange GetItemsWithinArea(float firstItemPosition, Vector3 layoutSize) const override;
230 * @copydoc ItemLayout::GetReserveItemCount()
232 unsigned int GetReserveItemCount(Vector3 layoutSize) const override;
235 * @copydoc ItemLayout::GetDefaultItemSize()
237 void GetDefaultItemSize(unsigned int itemId, const Vector3& layoutSize, Vector3& itemSize) const override;
240 * @copydoc ItemLayout::GetScrollDirection()
242 Degree GetScrollDirection() const override;
245 * @copydoc ItemLayout::ApplyConstraints()
247 void ApplyConstraints(Actor& actor, const int itemId, const Vector3& layoutSize, const Actor& itemViewActor) override;
250 * @copydoc ItemLayout::GetItemPosition()
252 Vector3 GetItemPosition(int itemID, float currentLayoutPosition, const Vector3& layoutSize) const override;
256 * @brief Protected constructor; see also GridLayout::New().
262 GridLayout(const GridLayout& itemLayout);
265 GridLayout& operator=(const GridLayout& rhs);
272 } // namespace Internal
274 } // namespace Toolkit
278 #endif // DALI_TOOLKIT_GRID_LAYOUT_H