1 #ifndef __DALI_TOOLKIT_TABLE_VIEW_H__
2 #define __DALI_TOOLKIT_TABLE_VIEW_H__
5 * Copyright (c) 2014 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>
25 #include <dali-toolkit/public-api/controls/control.h>
33 namespace Internal DALI_INTERNAL
39 * TableView is a layout container for aligning child actors in a grid like layout.
40 * TableView constrains the x and y position and width and height of the child actors.
41 * z position and depth are left intact so that 3D model actors can also be laid out
42 * in a grid without loosing their depth scaling.
44 class DALI_IMPORT_API TableView : public Control
49 * @brief The start and end property ranges for this control.
53 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
54 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices
58 * @brief An enumeration of properties belonging to the TableView class.
60 * LayoutRows: set the height of the rows.
61 * It has the format as follows in script:
65 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedHight
66 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeHeight
70 * LayoutColumns: set the height of the rows.
71 * It has the format as follows in script:
75 "0": { "policy": "fixed", "value": 40 }, //@see SetFixedWidth
76 "2": { "policy": "relative", "value": 0.33 } //@see SetRelativeWidth
84 ROWS = PROPERTY_START_INDEX, ///< name "rows", type UNSIGNED_INTEGER
85 COLUMNS, ///< name "columns", type UNSIGNED_INTEGER
86 CELL_PADDING, ///< name "cell-padding", type VECTOR2
87 LAYOUT_ROWS, ///< name "layout-rows", type MAP
88 LAYOUT_COLUMNS, ///< name "layout-columns", type MAP
92 // Custom properties for where to put the actor, these properties should be registered to the child which would be added to the table
93 static const std::string CELL_INDICES_PROPERTY_NAME; ///< Property, name "cell-indices", type VECTOR2
94 static const std::string ROW_SPAN_PROPERTY_NAME; ///< Property, name "row-span", type FLOAT (Currently builder unable to differentiate integer and float from Json string)
95 static const std::string COLUMN_SPAN_PROPERTY_NAME; ///< Property, name "column-span", type FLOAT (Currently builder unable to differentiate integer and float from Json string)
98 * @brief Describes how the size of a row / column been set
102 Fixed, ///< Fixed with the given value.
103 Relative, ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width
104 Fill ///< Get the remainder of the 100% (after subtracting Padding, Fixed and Relative height/ width) divided evenly between 'fill' rows/columns
108 * Structure to specify layout position for child actor
113 * Constructor to initialise values to defaults for convenience
115 CellPosition( unsigned int rowIndex = 0, unsigned int columnIndex = 0,
116 unsigned int rowSpan = 1, unsigned int columnSpan = 1 )
117 : rowIndex( rowIndex ), columnIndex( columnIndex ),
118 rowSpan( rowSpan ), columnSpan( columnSpan )
121 unsigned int rowIndex;
122 unsigned int columnIndex;
123 unsigned int rowSpan;
124 unsigned int columnSpan;
128 * Create a TableView handle; this can be initialised with TableView::New()
129 * Calling member functions with an uninitialised handle is not allowed.
134 * Copy constructor. Creates another handle that points to the same real object
135 * @param handle to copy from
137 TableView( const TableView& handle );
140 * Assignment operator. Changes this handle to point to another real object
142 TableView& operator=( const TableView& handle );
147 * This is non-virtual since derived Handle types must not contain data or virtual methods.
152 * Create the TableView control.
153 * @param[in] initialRows for the table
154 * @param[in] initialColumns for the table
155 * @return A handle to the TableView control.
157 static TableView New( unsigned int initialRows, unsigned int initialColumns );
160 * Downcast an Object handle to TableView. If handle points to a TableView the
161 * downcast produces valid handle. If not the returned handle is left uninitialized.
162 * @param[in] handle Handle to an object
163 * @return handle to a TableView or an uninitialized handle
165 static TableView DownCast( BaseHandle handle );
168 * Adds a child to the table
169 * If the row or column index is outside the table, the table gets resized bigger
170 * @pre The child actor has been initialized.
171 * @param[in] child to add
172 * @param[in] position for the child
173 * @return true if the addition succeeded, false if the cell is already occupied
175 bool AddChild( Actor child, CellPosition position );
178 * Returns a child from the given layout position
179 * Note! if there is no child in this position this method returns an uninitialized
181 * @param[in] position in the table
182 * @return child that was in the cell or an uninitialized handle
184 Actor GetChildAt( CellPosition position );
187 * Removes a child from the given layout position
188 * Note! if there is no child in this position this method does nothing
189 * @param[in] position for the child to remove
190 * @return child that was removed or an uninitialized handle
192 Actor RemoveChildAt( CellPosition position );
195 * Finds the childs layout position
196 * @param[in] child to search for
197 * @param[out] position for the child
198 * @return true if the child was included in this TableView
200 bool FindChildPosition( Actor child, CellPosition& position );
203 * Insert a new row to given index
204 * @param [in] rowIndex of the new row
206 void InsertRow( unsigned int rowIndex );
209 * Delete a row from given index
210 * Removed elements are deleted
211 * @param [in] rowIndex of the row to delete
213 void DeleteRow( unsigned int rowIndex );
216 * Delete a row from given index
217 * @param [in] rowIndex of the row to delete
218 * @param [out] removed elements
220 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
223 * Insert a new column to given index
224 * @param [in] columnIndex of the new column
226 void InsertColumn( unsigned int columnIndex );
229 * Delete a column from given index.
230 * Removed elements are deleted
231 * @param [in] columnIndex of the column to delete
233 void DeleteColumn( unsigned int columnIndex );
236 * Delete a column from given index
237 * @param [in] columnIndex of the column to delete
238 * @param [out] removed elements
240 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
243 * Resize the TableView. Note! if the new size is smaller than old,
244 * superfluous actors get removed. If you want to relayout removed children,
245 * use the variant that returns the removed Actors and reinsert them into the table
246 * If an actor spans to a removed row or column it gets removed from the table
247 * @param[in] rows for the table
248 * @param[in] columns for the table
250 void Resize( unsigned int rows, unsigned int columns );
253 * Resize the TableView. Note! if the new size is smaller than old,
254 * superfluous actors get removed.
255 * If an actor spans to a removed row or column it gets removed from the table
256 * @param[in] rows for the table
257 * @param[in] columns for the table
258 * @param[out] removed actor handles
260 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
263 * Set horizontal and vertical padding between cells
264 * @param[in] padding width and height
266 void SetCellPadding( Size padding );
269 * @return the current padding as width and height
271 Size GetCellPadding();
274 * Sets a row to have fixed height
275 * Setting a fixed height of 0 has no effect
276 * @pre The row rowIndex must exist.
277 * @param rowIndex for row with fixed height
278 * @param height in world coordinate units
280 void SetFixedHeight( unsigned int rowIndex, float height );
283 * Gets a row's fixed height.
284 * Note! The returned value is valid if it has been set before.
285 * @pre The row rowIndex must exist.
286 * @return height in world coordinate units.
288 float GetFixedHeight( unsigned int rowIndex ) const;
291 * Sets a row to have relative height. Relative height means percentage of
292 * the remainder of the table height after subtracting Padding and Fixed height rows
293 * Setting a relative height of 0 has no effect
294 * @pre The row rowIndex must exist.
295 * @param rowIndex for row with relative height
296 * @param heightPercentage between 0.0f and 1.0f
298 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
301 * Gets a row's relative height.
302 * Note! The returned value is valid if it has been set before.
303 * @pre The row rowIndex must exist.
304 * @return height in percentage units, between 0.0f and 1.0f.
306 float GetRelativeHeight( unsigned int rowIndex ) const;
309 * Sets a column to have fixed width
310 * Setting a fixed width of 0 has no effect
311 * @pre The column columnIndex must exist.
312 * @param columnIndex for column with fixed width
313 * @param width in world coordinate units
315 void SetFixedWidth( unsigned int columnIndex, float width );
318 * Gets a column's fixed width.
319 * Note! The returned value is valid if it has been set before.
320 * @pre The column columnIndex must exist.
321 * @return width in world coordinate units.
323 float GetFixedWidth( unsigned int columnIndex ) const;
326 * Sets a column to have relative width. Relative width means percentage of
327 * the remainder of table width after subtracting Padding and Fixed width columns
328 * Setting a relative width of 0 has no effect
329 * @pre The column columnIndex must exist.
330 * @param columnIndex for column with fixed width
331 * @param widthPercentage between 0.0f and 1.0f
333 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
336 * Gets a column's relative width.
337 * Note! The returned value is valid if it has been set before.
338 * @pre The column columnIndex must exist.
339 * @return width in percentage units, between 0.0f and 1.0f.
341 float GetRelativeWidth( unsigned int columnIndex ) const;
344 * @return the amount of rows in the table
346 unsigned int GetRows();
349 * @return the amount of columns in the table
351 unsigned int GetColumns();
353 public: // Not intended for application developers
356 * Creates a handle using the Toolkit::Internal implementation.
357 * @param[in] implementation The Control implementation.
359 DALI_INTERNAL TableView(Internal::TableView& implementation);
362 * Allows the creation of this Control from an Internal::CustomActor pointer.
363 * @param[in] internal A pointer to the internal CustomActor.
365 explicit DALI_INTERNAL TableView( Dali::Internal::CustomActor* internal );
368 } // namespace Toolkit
372 #endif // __DALI_TOOLKIT_TABLE_VIEW_H__