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 row-span or column span 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"
76 * "customProperties": {
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
101 * @brief An enumeration 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 height of the rows.
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
130 ROWS = PROPERTY_START_INDEX, ///< name "rows", type unsigned int @SINCE_1_0.0
131 COLUMNS, ///< name "columns", type unsigned int @SINCE_1_0.0
132 CELL_PADDING, ///< name "cellPadding", type Vector2 @SINCE_1_0.0
133 LAYOUT_ROWS, ///< name "layoutRows", type Map @SINCE_1_0.0
134 LAYOUT_COLUMNS, ///< name "layoutColumns", type Map @SINCE_1_0.0
139 * @brief Describes how the size of a row / column been set
144 FIXED, ///< Fixed with the given value. @SINCE_1_0.0
145 RELATIVE, ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width @SINCE_1_0.0
146 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
147 FIT ///< Fit around its children. @SINCE_1_0.0
151 * @brief Structure to specify layout position for child actor
157 * @brief Constructor to initialise values to defaults for convenience
160 CellPosition( unsigned int rowIndex = 0, unsigned int columnIndex = 0,
161 unsigned int rowSpan = 1, unsigned int columnSpan = 1 )
162 : rowIndex( rowIndex ), columnIndex( columnIndex ),
163 rowSpan( rowSpan ), columnSpan( columnSpan )
166 unsigned int rowIndex;
167 unsigned int columnIndex;
168 unsigned int rowSpan;
169 unsigned int columnSpan;
173 * @brief Create a TableView handle; this can be initialised with TableView::New()
174 * Calling member functions with an uninitialised handle is not allowed.
180 * @brief Copy constructor. Creates another handle that points to the same real object
182 * @param handle to copy from
184 TableView( const TableView& handle );
187 * @brief Assignment operator. Changes this handle to point to another real object
190 TableView& operator=( const TableView& handle );
195 * This is non-virtual since derived Handle types must not contain data or virtual methods.
201 * @brief Create the TableView control.
203 * @param[in] initialRows for the table
204 * @param[in] initialColumns for the table
205 * @return A handle to the TableView control.
207 static TableView New( unsigned int initialRows, unsigned int initialColumns );
210 * @brief Downcast a handle to TableView handle.
212 * If handle points to a TableView the
213 * downcast produces valid handle. If not the returned handle is left uninitialized.
215 * @param[in] handle Handle to an object
216 * @return handle to a TableView or an uninitialized handle
218 static TableView DownCast( BaseHandle handle );
221 * @brief Adds a child to the table
222 * If the row or column index is outside the table, the table gets resized bigger
224 * @param[in] child to add
225 * @param[in] position for the child
226 * @return true if the addition succeeded, false if the cell is already occupied
227 * @pre The child actor has been initialized.
229 bool AddChild( Actor child, CellPosition position );
232 * @brief Returns a child from the given layout position
234 * @param[in] position in the table
235 * @return child that was in the cell or an uninitialized handle
236 * @note If there is no child in this position this method returns an uninitialized.
239 Actor GetChildAt( CellPosition position );
242 * @brief Removes a child from the given layout position
244 * @param[in] position for the child to remove
245 * @return child that was removed or an uninitialized handle
246 * @note If there is no child in this position this method does nothing.
248 Actor RemoveChildAt( CellPosition position );
251 * @brief Finds the childs layout position
253 * @param[in] child to search for
254 * @param[out] position for the child
255 * @return true if the child was included in this TableView
257 bool FindChildPosition( Actor child, CellPosition& position );
260 * @brief Insert a new row to given index
262 * @param [in] rowIndex of the new row
264 void InsertRow( unsigned int rowIndex );
267 * @brief Delete a row from given index
268 * Removed elements are deleted
270 * @param [in] rowIndex of the row to delete
272 void DeleteRow( unsigned int rowIndex );
275 * @brief Delete a row from given index
277 * @param [in] rowIndex of the row to delete
278 * @param [out] removed elements
280 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
283 * @brief Insert a new column to given index
285 * @param [in] columnIndex of the new column
287 void InsertColumn( unsigned int columnIndex );
290 * @brief Delete a column from given index.
291 * Removed elements are deleted
293 * @param [in] columnIndex of the column to delete
295 void DeleteColumn( unsigned int columnIndex );
298 * @brief Delete a column from given index
300 * @param [in] columnIndex of the column to delete
301 * @param [out] removed elements
303 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
306 * @brief Resize the TableView.
308 * @param[in] rows for the table
309 * @param[in] columns for the table
310 * @note If the new size is smaller than old,
311 * superfluous actors get removed. If you want to relayout removed children,
312 * use the variant that returns the removed Actors and reinsert them into the table.
313 * If an actor spans to a removed row or column it gets removed from the table.
315 void Resize( unsigned int rows, unsigned int columns );
318 * @brief Resize the TableView.
320 * @param[in] rows for the table
321 * @param[in] columns for the table
322 * @param[out] removed actor handles
323 * @note If the new size is smaller than old,
324 * superfluous actors get removed.
325 * If an actor spans to a removed row or column it gets removed from the table.
327 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
330 * @brief Set horizontal and vertical padding between cells
332 * @param[in] padding width and height
334 void SetCellPadding( Size padding );
337 * @brief Get the current padding as width and height.
339 * @return the current padding as width and height
341 Size GetCellPadding();
344 * @brief Specify this row as fitting its height to its children
347 * @param[in] rowIndex The row to set
349 void SetFitHeight( unsigned int rowIndex );
352 * @brief Is the row a fit row
355 * @param[in] rowIndex The row to check
356 * @return Return true if the row is fit
358 bool IsFitHeight( unsigned int rowIndex ) const;
361 * @brief Specify this column as fitting its width to its children
364 * @param[in] columnIndex The column to set
366 void SetFitWidth( unsigned int columnIndex );
369 * @brief Is the column a fit column
372 * @param[in] columnIndex The column to check
373 * @return Return true if the column is fit
375 bool IsFitWidth( unsigned int columnIndex ) const;
378 * @brief Sets a row to have fixed height
379 * Setting a fixed height of 0 has no effect
381 * @param rowIndex for row with fixed height
382 * @param height in world coordinate units
383 * @pre The row rowIndex must exist.
385 void SetFixedHeight( unsigned int rowIndex, float height );
388 * @brief Gets a row's fixed height.
390 * @return height in world coordinate units.
391 * @pre The row rowIndex must exist.
392 * @note The returned value is valid if it has been set before.
394 float GetFixedHeight( unsigned int rowIndex ) const;
397 * @brief Sets a row to have relative height. Relative height means percentage of
398 * the remainder of the table height after subtracting Padding and Fixed height rows
399 * Setting a relative height of 0 has no effect
401 * @param rowIndex for row with relative height
402 * @param heightPercentage between 0.0f and 1.0f
403 * @pre The row rowIndex must exist.
405 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
408 * @brief Gets a row's relative height.
410 * @return height in percentage units, between 0.0f and 1.0f.
411 * @pre The row rowIndex must exist.
412 * @note The returned value is valid if it has been set before.
414 float GetRelativeHeight( unsigned int rowIndex ) const;
417 * @brief Sets a column to have fixed width
418 * Setting a fixed width of 0 has no effect
420 * @param columnIndex for column with fixed width
421 * @param width in world coordinate units
422 * @pre The column columnIndex must exist.
424 void SetFixedWidth( unsigned int columnIndex, float width );
427 * @brief Gets a column's fixed width.
429 * @return width in world coordinate units.
430 * @pre The column columnIndex must exist.
431 * @note The returned value is valid if it has been set before.
433 float GetFixedWidth( unsigned int columnIndex ) const;
436 * @brief Sets a column to have relative width. Relative width means percentage of
437 * the remainder of table width after subtracting Padding and Fixed width columns
438 * Setting a relative width of 0 has no effect
440 * @param columnIndex for column with fixed width
441 * @param widthPercentage between 0.0f and 1.0f
442 * @pre The column columnIndex must exist.
444 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
447 * @brief Gets a column's relative width.
449 * @return width in percentage units, between 0.0f and 1.0f.
450 * @pre The column columnIndex must exist.
451 * @note The returned value is valid if it has been set before.
453 float GetRelativeWidth( unsigned int columnIndex ) const;
456 * @brief Gets the amount of rows in the table.
458 * @return the amount of rows in the table
460 unsigned int GetRows();
463 * @brief Gets the amount of columns in the table.
465 * @return the amount of columns in the table
467 unsigned int GetColumns();
470 * @brief Set the alignment on a cell.
472 * Cells without calling this function have the default values of LEFT and TOP respectively.
475 * @param[in] position The cell to set alignment on.
476 * @param[in] horizontal The horizontal alignment.
477 * @param[in] vertical The vertical alignment.
479 void SetCellAlignment( CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical );
481 public: // Not intended for application developers
484 * @brief Creates a handle using the Toolkit::Internal implementation.
486 * @param[in] implementation The Control implementation.
488 DALI_INTERNAL TableView(Internal::TableView& implementation);
491 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
493 * @param[in] internal A pointer to the internal CustomActor.
495 explicit DALI_INTERNAL TableView( Dali::Internal::CustomActor* internal );
501 } // namespace Toolkit
505 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__