1 #ifndef DALI_TOOLKIT_TABLE_VIEW_H
2 #define DALI_TOOLKIT_TABLE_VIEW_H
5 * Copyright (c) 2020 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/actors/actor-enumerations.h>
23 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali-toolkit/public-api/controls/control.h>
32 namespace Internal DALI_INTERNAL
37 * @addtogroup dali_toolkit_controls_table_view
42 * @brief TableView is a layout container for aligning child actors in a grid like layout.
44 * TableView constrains the x and y position and width and height of the child actors.
45 * z position and depth are left intact so that 3D model actors can also be laid out
46 * in a grid without loosing their depth scaling.
49 * <h3>Per-child Custom properties for script supporting:</h3>
51 * When an actor is add to the tableView through Actor::Add() instead of TableView::AddChild,
52 * the following custom properties of the actor are checked to decide the actor position inside the table.
54 * These properties are registered dynamically to the child and is non-animatable.
56 * | %Property Name | Type |
57 * |-------------------------|-------------|
58 * | cellIndex | Vector2 |
60 * | columnSpan | float |
61 * | cellHorizontalAlignment | string |
62 * | cellVerticalAlignment | string |
64 * The rowSpan or columnSpan has integer value, but its type is float here due to the limitation of the builder's ability to differentiate integer and float from Json string.
65 * The available values for cellHorizontalAlignment are: left, center, right.
66 * The available values for cellVerticalAlignment are: top, center, bottom.
72 * "url": "{DALI_IMAGE_DIR}gallery-small-1.jpg"
75 * "cellIndex":[1,1], // Property to specify the top-left cell this child occupies, if not set, the first available cell is used
76 * "rowSpan":3, // Property to specify how many rows this child occupies, if not set, default value is 1
77 * "columnSpan": 2, // Property to specify how many columns this child occupies, if nor set, default value is 1
78 * "cellHorizontalAlignment": "left", // Property to specify how to align horizontally inside the cells, if not set, default value is 'left'
79 * "cellVerticalAlignment": "center" // Property to specify how to align vertically inside the cells, if not set, default value is 'top'
84 class DALI_TOOLKIT_API TableView : public Control
88 * @brief Enumeration for the start and end property ranges for this control.
93 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
94 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ///< Reserve property indices @SINCE_1_0.0
96 CHILD_PROPERTY_START_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX, ///< @SINCE_1_1.36
97 CHILD_PROPERTY_END_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX + 1000 ///< Reserve child property indices @SINCE_1_1.36
101 * @brief Enumeration for the instance of properties belonging to the TableView class.
103 * LayoutRows: set the height of the rows.
104 * It has the format as follows in script:
108 * "0": { "policy": "fixed", "value": 40 }, //@see SetFixedHight
109 * "2": { "policy": "relative", "value": 0.33 }, //@see SetRelativeHeight
110 * "3": { "policy": "fit", "value":0.0 } //@see SetFitHeight, the value is not used, its height is decided by the children in this row
114 * LayoutColumns: set the width of the columns.
115 * It has the format as follows in script:
119 * "0": { "policy": "fixed", "value": 40 }, //@see SetFixedWidth
120 * "1": { "policy": "fit", "value":0.0 } //@see SetFitHeight, the value is not used, its width is decided by the children in this column
121 * "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeWidth
129 * @brief Enumeration for the instance of properties belonging to the TableView class.
135 ROWS = PROPERTY_START_INDEX, ///< name "rows", type unsigned int @SINCE_1_0.0
136 COLUMNS, ///< name "columns", type unsigned int @SINCE_1_0.0
137 CELL_PADDING, ///< name "cellPadding", type Vector2 @SINCE_1_0.0
138 LAYOUT_ROWS, ///< name "layoutRows", type Map @SINCE_1_0.0
139 LAYOUT_COLUMNS, ///< name "layoutColumns", type Map @SINCE_1_0.0
144 * @brief Enumeration for the instance of child properties belonging to the TableView class.
150 * @brief Enumeration for the instance of child properties belonging to the TableView class.
155 CELL_INDEX = CHILD_PROPERTY_START_INDEX, ///< name "cellIndex", The top-left cell this child occupies, if not set, the first available cell is used, type VECTOR2 @SINCE_1_1.36
156 ROW_SPAN, ///< name "rowSpan", The number of rows this child occupies, if not set, default value is 1, type FLOAT @SINCE_1_1.36
157 COLUMN_SPAN, ///< name "columnSpan", The number of columns this child occupies, if not set, default value is 1, type FLOAT @SINCE_1_1.36
158 CELL_HORIZONTAL_ALIGNMENT, ///< name "cellHorizontalAlignment", The horizontal alignment of this child inside the cells, if not set, default value is 'left', type STRING @SINCE_1_1.36
159 CELL_VERTICAL_ALIGNMENT ///< name "cellVerticalAlignment", The vertical alignment of this child inside the cells, if not set, default value is 'top', type STRING @SINCE_1_1.36
164 * @brief Enumeration for describing how the size of a row / column has been set.
169 FIXED, ///< Fixed with the given value. @SINCE_1_0.0
170 RELATIVE, ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width @SINCE_1_0.0
171 FILL, ///< Default policy, get the remainder of the 100% (after subtracting Fixed, Fit and Relative height/ width) divided evenly between 'fill' rows/columns @SINCE_1_0.0
172 FIT ///< Fit around its children. @SINCE_1_0.0
176 * @brief Structure to specify layout position for child actor.
182 * @brief Constructor to initialise values to defaults for convenience.
184 * @param[in] rowIndex The row index initialized
185 * @param[in] columnIndex The column index initialized
186 * @param[in] rowSpan The row span initialized
187 * @param[in] columnSpan The column span initialized
189 CellPosition(unsigned int rowIndex = 0, unsigned int columnIndex = 0, unsigned int rowSpan = 1, unsigned int columnSpan = 1)
190 : rowIndex(rowIndex),
191 columnIndex(columnIndex),
193 columnSpan(columnSpan)
197 unsigned int rowIndex;
198 unsigned int columnIndex;
199 unsigned int rowSpan;
200 unsigned int columnSpan;
204 * @brief Creates a TableView handle; this can be initialized with TableView::New().
205 * Calling member functions with an uninitialized handle is not allowed.
211 * @brief Copy constructor. Creates another handle that points to the same real object.
213 * @param[in] handle Handle to copy from
215 TableView(const TableView& handle);
218 * @brief Assignment operator. Changes this handle to point to another real object.
220 * @param[in] handle Handle to an object
221 * @return A reference to this
223 TableView& operator=(const TableView& handle);
228 * This is non-virtual since derived Handle types must not contain data or virtual methods.
234 * @brief Creates the TableView control.
236 * @param[in] initialRows for the table
237 * @param[in] initialColumns for the table
238 * @return A handle to the TableView control
240 static TableView New(unsigned int initialRows, unsigned int initialColumns);
243 * @brief Downcasts a handle to TableView handle.
245 * If handle points to a TableView, the downcast produces valid handle.
246 * If not, the returned handle is left uninitialized.
248 * @param[in] handle Handle to an object
249 * @return Handle to a TableView or an uninitialized handle
251 static TableView DownCast(BaseHandle handle);
254 * @brief Adds a child to the table.
255 * If the row or column index is outside the table, the table gets resized bigger.
257 * @param[in] child The child to add
258 * @param[in] position The position for the child
259 * @return @c true if the addition succeeded, @c false if the cell is already occupied
260 * @pre The child actor has been initialized.
262 bool AddChild(Actor child, CellPosition position);
265 * @brief Returns a child from the given layout position.
267 * @param[in] position The position in the table
268 * @return Child that was in the cell or an uninitialized handle
269 * @note If there is no child in this position this method returns an uninitialized.
272 Actor GetChildAt(CellPosition position);
275 * @brief Removes a child from the given layout position.
277 * @param[in] position The position for the child to remove
278 * @return Child that was removed or an uninitialized handle
279 * @note If there is no child in this position, this method does nothing.
281 Actor RemoveChildAt(CellPosition position);
284 * @brief Finds the child's layout position.
286 * @param[in] child The child to search for
287 * @param[out] position The position for the child
288 * @return true if the child was included in this TableView
290 bool FindChildPosition(Actor child, CellPosition& position);
293 * @brief Inserts a new row to given index.
295 * @param[in] rowIndex The rowIndex of the new row
297 void InsertRow(unsigned int rowIndex);
300 * @brief Deletes a row from the given index.
301 * Removed elements are deleted.
303 * @param[in] rowIndex The rowIndex of the row to delete
305 void DeleteRow(unsigned int rowIndex);
308 * @brief Deletes a row from the given index.
310 * @param[in] rowIndex The rowIndex of the row to delete
311 * @param[out] removed The removed elements
313 void DeleteRow(unsigned int rowIndex, std::vector<Actor>& removed);
316 * @brief Inserts a new column to the given index.
318 * @param[in] columnIndex The columnIndex of the new column
320 void InsertColumn(unsigned int columnIndex);
323 * @brief Deletes a column from the given index.
324 * Removed elements are deleted.
326 * @param[in] columnIndex The columnIndex of the column to delete
328 void DeleteColumn(unsigned int columnIndex);
331 * @brief Deletes a column from the given index.
333 * @param[in] columnIndex The columnIndex of the column to delete
334 * @param[out] removed The removed elements
336 void DeleteColumn(unsigned int columnIndex, std::vector<Actor>& removed);
339 * @brief Resizes the TableView.
341 * @param[in] rows The rows for the table
342 * @param[in] columns The columns for the table
343 * @note If the new size is smaller than old,
344 * superfluous actors get removed. If you want to relayout removed children,
345 * use the variant that returns the removed Actors and reinsert them into the table.
346 * If an actor spans to a removed row or column, it gets removed from the table.
348 void Resize(unsigned int rows, unsigned int columns);
351 * @brief Resizes the TableView.
353 * @param[in] rows The rows for the table
354 * @param[in] columns The columns for the table
355 * @param[out] removed The removed actor handles
356 * @note If the new size is smaller than old, superfluous actors get removed.
357 * If an actor spans to a removed row or column it gets removed from the table.
359 void Resize(unsigned int rows, unsigned int columns, std::vector<Actor>& removed);
362 * @brief Sets horizontal and vertical padding between cells.
364 * @param[in] padding Width and height
366 void SetCellPadding(Size padding);
369 * @brief Gets the current padding as width and height.
371 * @return The current padding as width and height
373 Size GetCellPadding();
376 * @brief Specifies this row as fitting its height to its children.
379 * @param[in] rowIndex The row to set
381 void SetFitHeight(unsigned int rowIndex);
384 * @brief Checks if the row is a fit row.
387 * @param[in] rowIndex The row to check
388 * @return Return true if the row is fit
390 bool IsFitHeight(unsigned int rowIndex) const;
393 * @brief Specifies this column as fitting its width to its children.
396 * @param[in] columnIndex The column to set
398 void SetFitWidth(unsigned int columnIndex);
401 * @brief Checks if the column is a fit column.
404 * @param[in] columnIndex The column to check
405 * @return Return true if the column is fit
407 bool IsFitWidth(unsigned int columnIndex) const;
410 * @brief Sets a row to have fixed height.
411 * Setting a fixed height of 0 has no effect.
413 * @param rowIndex The rowIndex for row with fixed height
414 * @param height The height in world coordinate units
415 * @pre The row rowIndex must exist.
417 void SetFixedHeight(unsigned int rowIndex, float height);
420 * @brief Gets a row's fixed height.
422 * @param[in] rowIndex The row index with fixed height
423 * @return height The height in world coordinate units
424 * @pre The row rowIndex must exist.
425 * @note The returned value is valid if it has been set before.
427 float GetFixedHeight(unsigned int rowIndex) const;
430 * @brief Sets a row to have relative height. Relative height means percentage of
431 * the remainder of the table height after subtracting Padding and Fixed height rows.
432 * Setting a relative height of 0 has no effect.
434 * @param rowIndex The rowIndex for row with relative height
435 * @param heightPercentage between 0.0f and 1.0f
436 * @pre The row rowIndex must exist.
438 void SetRelativeHeight(unsigned int rowIndex, float heightPercentage);
441 * @brief Gets a row's relative height.
443 * @param[in] rowIndex The row index with relative height
444 * @return Height in percentage units, between 0.0f and 1.0f
445 * @pre The row rowIndex must exist.
446 * @note The returned value is valid if it has been set before.
448 float GetRelativeHeight(unsigned int rowIndex) const;
451 * @brief Sets a column to have fixed width.
452 * Setting a fixed width of 0 has no effect.
454 * @param columnIndex The columnIndex for column with fixed width
455 * @param width The width in world coordinate units
456 * @pre The column columnIndex must exist.
458 void SetFixedWidth(unsigned int columnIndex, float width);
461 * @brief Gets a column's fixed width.
463 * @param[in] columnIndex The column index with fixed width
464 * @return Width in world coordinate units
465 * @pre The column columnIndex must exist.
466 * @note The returned value is valid if it has been set before.
468 float GetFixedWidth(unsigned int columnIndex) const;
471 * @brief Sets a column to have relative width. Relative width means percentage of
472 * the remainder of table width after subtracting Padding and Fixed width columns.
473 * Setting a relative width of 0 has no effect.
475 * @param columnIndex The columnIndex for column with fixed width
476 * @param widthPercentage The widthPercentage between 0.0f and 1.0f
477 * @pre The column columnIndex must exist.
479 void SetRelativeWidth(unsigned int columnIndex, float widthPercentage);
482 * @brief Gets a column's relative width.
484 * @param[in] columnIndex The column index with relative width
485 * @return Width in percentage units, between 0.0f and 1.0f
486 * @pre The column columnIndex must exist.
487 * @note The returned value is valid if it has been set before.
489 float GetRelativeWidth(unsigned int columnIndex) const;
492 * @brief Gets the amount of rows in the table.
494 * @return The amount of rows in the table
496 unsigned int GetRows();
499 * @brief Gets the amount of columns in the table.
501 * @return The amount of columns in the table
503 unsigned int GetColumns();
506 * @brief Sets the alignment on a cell.
508 * Cells without calling this function have the default values of LEFT and TOP respectively.
511 * @param[in] position The cell to set alignment on
512 * @param[in] horizontal The horizontal alignment
513 * @param[in] vertical The vertical alignment
515 void SetCellAlignment(CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical);
517 public: // Not intended for application developers
520 * @brief Creates a handle using the Toolkit::Internal implementation.
522 * @param[in] implementation The Control implementation
524 DALI_INTERNAL TableView(Internal::TableView& implementation);
527 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
529 * @param[in] internal A pointer to the internal CustomActor
531 explicit DALI_INTERNAL TableView(Dali::Internal::CustomActor* internal);
538 } // namespace Toolkit
542 #endif // DALI_TOOLKIT_TABLE_VIEW_H