1 #ifndef __DALI_TOOLKIT_TABLE_VIEW_H__
2 #define __DALI_TOOLKIT_TABLE_VIEW_H__
5 * Copyright (c) 2015 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/vector-wrapper.h>
23 #include <dali/public-api/actors/actor-enumerations.h>
26 #include <dali-toolkit/public-api/controls/control.h>
34 namespace Internal DALI_INTERNAL
39 * @addtogroup dali_toolkit_controls_table_view
44 * @brief TableView is a layout container for aligning child actors in a grid like layout.
46 * TableView constrains the x and y position and width and height of the child actors.
47 * z position and depth are left intact so that 3D model actors can also be laid out
48 * in a grid without loosing their depth scaling.
51 * <h3>Per-child Custom properties for script supporting:</h3>
53 * When an actor is add to the tableView through Actor::Add() instead of TableView::AddChild,
54 * the following custom properties of the actor are checked to decide the actor position inside the table.
56 * These properties are registered dynamically to the child and is non-animatable.
58 * | %Property Name | Type |
59 * |-------------------------|-------------|
60 * | cellIndex | Vector2 |
62 * | columnSpan | float |
63 * | cellHorizontalAlignment | string |
64 * | cellVerticalAlignment | string |
66 * 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.
67 * The available values for cellHorizontalAlignment are: left, center, right.
68 * The available values for cellVerticalAlignment are: top, center, bottom.
74 * "url": "{DALI_IMAGE_DIR}gallery-small-1.jpg"
77 * "cellIndex":[1,1], // property to specify the top-left cell this child occupies, if not set, the first available cell is used
78 * "rowSpan":3, // property to specify how many rows this child occupies, if not set, default value is 1
79 * "columnSpan": 2, // property to specify how many columns this child occupies, if nor set, default value is 1
80 * "cellHorizontalAlignment": "left", // property to specify how to align horizontally inside the cells, if not set, default value is 'left'
81 * "cellVerticalAlignment": "center" // property to specify how to align vertically inside the cells, if not set, default value is 'top'
86 class DALI_IMPORT_API TableView : public Control
91 * @brief The start and end property ranges for this control.
96 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
97 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000, ///< Reserve property indices @SINCE_1_0.0
99 CHILD_PROPERTY_START_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX, ///< @SINCE_1_1.36
100 CHILD_PROPERTY_END_INDEX = CHILD_PROPERTY_REGISTRATION_START_INDEX + 1000 ///< Reserve child property indices @SINCE_1_1.36
104 * @brief An enumeration of properties belonging to the TableView class.
106 * LayoutRows: set the height of the rows.
107 * It has the format as follows in script:
111 * "0": { "policy": "fixed", "value": 40 }, //@see SetFixedHight
112 * "2": { "policy": "relative", "value": 0.33 }, //@see SetRelativeHeight
113 * "3": { "policy": "fit", "value":0.0 } //@see SetFitHeight, the value is not used, its height is decided by the children in this row
117 * LayoutColumns: set the width of the columns.
118 * It has the format as follows in script:
122 * "0": { "policy": "fixed", "value": 40 }, //@see SetFixedWidth
123 * "1": { "policy": "fit", "value":0.0 } //@see SetFitHeight, the value is not used, its width is decided by the children in this column
124 * "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeWidth
133 ROWS = PROPERTY_START_INDEX, ///< name "rows", type unsigned int @SINCE_1_0.0
134 COLUMNS, ///< name "columns", type unsigned int @SINCE_1_0.0
135 CELL_PADDING, ///< name "cellPadding", type Vector2 @SINCE_1_0.0
136 LAYOUT_ROWS, ///< name "layoutRows", type Map @SINCE_1_0.0
137 LAYOUT_COLUMNS, ///< name "layoutColumns", type Map @SINCE_1_0.0
142 * @brief An enumeration of child properties belonging to the TableView class.
149 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
150 ROW_SPAN, ///< name "rowSpan", The number of rows this child occupies, if not set, default value is 1, type FLOAT @SINCE_1_1.36
151 COLUMN_SPAN, ///< name "columnSpan", The number of columns this child occupies, if not set, default value is 1, type FLOAT @SINCE_1_1.36
152 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
153 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
158 * @brief Describes how the size of a row / column been set
163 FIXED, ///< Fixed with the given value. @SINCE_1_0.0
164 RELATIVE, ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width @SINCE_1_0.0
165 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
166 FIT ///< Fit around its children. @SINCE_1_0.0
170 * @brief Structure to specify layout position for child actor
176 * @brief Constructor to initialise values to defaults for convenience
178 * @param[in] rowIndex The row index initialized
179 * @param[in] columnIndex The column index initialized
180 * @param[in] rowSpan The row span initialized
181 * @param[in] columnSpan The column span initialized
183 CellPosition( unsigned int rowIndex = 0, unsigned int columnIndex = 0,
184 unsigned int rowSpan = 1, unsigned int columnSpan = 1 )
185 : rowIndex( rowIndex ), columnIndex( columnIndex ),
186 rowSpan( rowSpan ), columnSpan( columnSpan )
189 unsigned int rowIndex;
190 unsigned int columnIndex;
191 unsigned int rowSpan;
192 unsigned int columnSpan;
196 * @brief Create a TableView handle; this can be initialised with TableView::New()
197 * Calling member functions with an uninitialised handle is not allowed.
203 * @brief Copy constructor. Creates another handle that points to the same real object
205 * @param[in] handle to copy from
207 TableView( const TableView& handle );
210 * @brief Assignment operator. Changes this handle to point to another real object
212 * @param[in] handle Handle to an object
213 * @return A reference to this
215 TableView& operator=( const TableView& handle );
220 * This is non-virtual since derived Handle types must not contain data or virtual methods.
226 * @brief Create the TableView control.
228 * @param[in] initialRows for the table
229 * @param[in] initialColumns for the table
230 * @return A handle to the TableView control.
232 static TableView New( unsigned int initialRows, unsigned int initialColumns );
235 * @brief Downcast a handle to TableView handle.
237 * If handle points to a TableView the
238 * downcast produces valid handle. If not the returned handle is left uninitialized.
240 * @param[in] handle Handle to an object
241 * @return handle to a TableView or an uninitialized handle
243 static TableView DownCast( BaseHandle handle );
246 * @brief Adds a child to the table
247 * If the row or column index is outside the table, the table gets resized bigger
249 * @param[in] child to add
250 * @param[in] position for the child
251 * @return true if the addition succeeded, false if the cell is already occupied
252 * @pre The child actor has been initialized.
254 bool AddChild( Actor child, CellPosition position );
257 * @brief Returns a child from the given layout position
259 * @param[in] position in the table
260 * @return child that was in the cell or an uninitialized handle
261 * @note If there is no child in this position this method returns an uninitialized.
264 Actor GetChildAt( CellPosition position );
267 * @brief Removes a child from the given layout position
269 * @param[in] position for the child to remove
270 * @return child that was removed or an uninitialized handle
271 * @note If there is no child in this position this method does nothing.
273 Actor RemoveChildAt( CellPosition position );
276 * @brief Finds the childs layout position
278 * @param[in] child to search for
279 * @param[out] position for the child
280 * @return true if the child was included in this TableView
282 bool FindChildPosition( Actor child, CellPosition& position );
285 * @brief Insert a new row to given index
287 * @param [in] rowIndex of the new row
289 void InsertRow( unsigned int rowIndex );
292 * @brief Delete a row from given index
293 * Removed elements are deleted
295 * @param [in] rowIndex of the row to delete
297 void DeleteRow( unsigned int rowIndex );
300 * @brief Delete a row from given index
302 * @param [in] rowIndex of the row to delete
303 * @param [out] removed elements
305 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
308 * @brief Insert a new column to given index
310 * @param [in] columnIndex of the new column
312 void InsertColumn( unsigned int columnIndex );
315 * @brief Delete a column from given index.
316 * Removed elements are deleted
318 * @param [in] columnIndex of the column to delete
320 void DeleteColumn( unsigned int columnIndex );
323 * @brief Delete a column from given index
325 * @param [in] columnIndex of the column to delete
326 * @param [out] removed elements
328 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
331 * @brief Resize the TableView.
333 * @param[in] rows for the table
334 * @param[in] columns for the table
335 * @note If the new size is smaller than old,
336 * superfluous actors get removed. If you want to relayout removed children,
337 * use the variant that returns the removed Actors and reinsert them into the table.
338 * If an actor spans to a removed row or column it gets removed from the table.
340 void Resize( unsigned int rows, unsigned int columns );
343 * @brief Resize the TableView.
345 * @param[in] rows for the table
346 * @param[in] columns for the table
347 * @param[out] removed actor handles
348 * @note If the new size is smaller than old,
349 * superfluous actors get removed.
350 * If an actor spans to a removed row or column it gets removed from the table.
352 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
355 * @brief Set horizontal and vertical padding between cells
357 * @param[in] padding width and height
359 void SetCellPadding( Size padding );
362 * @brief Get the current padding as width and height.
364 * @return the current padding as width and height
366 Size GetCellPadding();
369 * @brief Specify this row as fitting its height to its children
372 * @param[in] rowIndex The row to set
374 void SetFitHeight( unsigned int rowIndex );
377 * @brief Is the row a fit row
380 * @param[in] rowIndex The row to check
381 * @return Return true if the row is fit
383 bool IsFitHeight( unsigned int rowIndex ) const;
386 * @brief Specify this column as fitting its width to its children
389 * @param[in] columnIndex The column to set
391 void SetFitWidth( unsigned int columnIndex );
394 * @brief Is the column a fit column
397 * @param[in] columnIndex The column to check
398 * @return Return true if the column is fit
400 bool IsFitWidth( unsigned int columnIndex ) const;
403 * @brief Sets a row to have fixed height
404 * Setting a fixed height of 0 has no effect
406 * @param rowIndex for row with fixed height
407 * @param height in world coordinate units
408 * @pre The row rowIndex must exist.
410 void SetFixedHeight( unsigned int rowIndex, float height );
413 * @brief Gets a row's fixed height.
415 * @param[in] rowIndex The row index with fixed height
416 * @return height in world coordinate units.
417 * @pre The row rowIndex must exist.
418 * @note The returned value is valid if it has been set before.
420 float GetFixedHeight( unsigned int rowIndex ) const;
423 * @brief Sets a row to have relative height. Relative height means percentage of
424 * the remainder of the table height after subtracting Padding and Fixed height rows
425 * Setting a relative height of 0 has no effect
427 * @param rowIndex for row with relative height
428 * @param heightPercentage between 0.0f and 1.0f
429 * @pre The row rowIndex must exist.
431 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
434 * @brief Gets a row's relative height.
436 * @param[in] rowIndex The row index with relative height
437 * @return height in percentage units, between 0.0f and 1.0f.
438 * @pre The row rowIndex must exist.
439 * @note The returned value is valid if it has been set before.
441 float GetRelativeHeight( unsigned int rowIndex ) const;
444 * @brief Sets a column to have fixed width
445 * Setting a fixed width of 0 has no effect
447 * @param columnIndex for column with fixed width
448 * @param width in world coordinate units
449 * @pre The column columnIndex must exist.
451 void SetFixedWidth( unsigned int columnIndex, float width );
454 * @brief Gets a column's fixed width.
456 * @param[in] columnIndex The column index with fixed width
457 * @return width in world coordinate units.
458 * @pre The column columnIndex must exist.
459 * @note The returned value is valid if it has been set before.
461 float GetFixedWidth( unsigned int columnIndex ) const;
464 * @brief Sets a column to have relative width. Relative width means percentage of
465 * the remainder of table width after subtracting Padding and Fixed width columns
466 * Setting a relative width of 0 has no effect
468 * @param columnIndex for column with fixed width
469 * @param widthPercentage between 0.0f and 1.0f
470 * @pre The column columnIndex must exist.
472 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
475 * @brief Gets a column's relative width.
477 * @param[in] columnIndex The column index with relative width
478 * @return width in percentage units, between 0.0f and 1.0f.
479 * @pre The column columnIndex must exist.
480 * @note The returned value is valid if it has been set before.
482 float GetRelativeWidth( unsigned int columnIndex ) const;
485 * @brief Gets the amount of rows in the table.
487 * @return the amount of rows in the table
489 unsigned int GetRows();
492 * @brief Gets the amount of columns in the table.
494 * @return the amount of columns in the table
496 unsigned int GetColumns();
499 * @brief Set the alignment on a cell.
501 * Cells without calling this function have the default values of LEFT and TOP respectively.
504 * @param[in] position The cell to set alignment on.
505 * @param[in] horizontal The horizontal alignment.
506 * @param[in] vertical The vertical alignment.
508 void SetCellAlignment( CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical );
510 public: // Not intended for application developers
514 * @brief Creates a handle using the Toolkit::Internal implementation.
516 * @param[in] implementation The Control implementation.
518 DALI_INTERNAL TableView(Internal::TableView& implementation);
521 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
523 * @param[in] internal A pointer to the internal CustomActor.
525 explicit DALI_INTERNAL TableView( Dali::Internal::CustomActor* internal );
532 } // namespace Toolkit
536 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__