1 #ifndef __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_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-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/table-view/table-view.h>
36 * TableView is a custom control for laying out actors in a table layout
37 * @see Dali::Toolkit:TableView for more details
39 class TableView : public Control
44 * Create a new TableView.
45 * @return A smart-pointer to the newly allocated TableView.
47 static Toolkit::TableView New( unsigned int initialRows, unsigned int initialColumns );
50 * @copydoc Toolkit::TableView::AddChild
52 bool AddChild( Actor& child, const Toolkit::TableView::CellPosition& position );
55 * @copydoc Toolkit::TableView::GetChildAt
57 Actor GetChildAt( const Toolkit::TableView::CellPosition& position );
60 * @copydoc Toolkit::TableView::RemoveChildAt
62 Actor RemoveChildAt( const Toolkit::TableView::CellPosition& position );
65 * @copydoc Toolkit::TableView::FindChildPosition
67 bool FindChildPosition( const Actor& child, Toolkit::TableView::CellPosition& positionOut );
70 * @copydoc Toolkit::TableView::InsertRow
72 void InsertRow( unsigned int rowIndex );
75 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex )
77 void DeleteRow( unsigned int rowIndex );
80 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed )
82 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
85 * @copydoc Toolkit::TableView::InsertColumn
87 void InsertColumn( unsigned int columnIndex );
90 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex )
92 void DeleteColumn( unsigned int columnIndex );
95 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed )
97 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
100 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns )
102 void Resize( unsigned int rows, unsigned int columns );
105 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed )
107 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
110 * @copydoc Toolkit::TableView::SetCellPadding
112 void SetCellPadding( Size padding );
115 * @copydoc Toolkit::TableView::GetCellPadding
117 Size GetCellPadding();
120 * @copydoc Toolkit::TableView::SetFitHeight
122 void SetFitHeight( unsigned int rowIndex );
125 * @copydoc Toolkit::TableView::IsFitHeight
127 bool IsFitHeight( unsigned int rowIndex ) const;
130 * @copydoc Toolkit::TableView::SetFitWidth
132 void SetFitWidth( unsigned int columnIndex );
135 * @copydoc Toolkit::TableView::IsFitWidth
137 bool IsFitWidth( unsigned int columnIndex ) const;
140 * @copydoc Toolkit::TableView::SetFixedWidth
142 void SetFixedWidth( unsigned int columnIndex, float width );
145 * @copydoc Toolkit::TableView::GetFixedWidth
147 float GetFixedWidth( unsigned int columnIndex ) const;
150 * @copydoc Toolkit::TableView::SetFixedHeight
152 void SetFixedHeight( unsigned int rowIndex, float height );
155 * @copydoc Toolkit::TableView::GetFixedHeight
157 float GetFixedHeight( unsigned int rowIndex ) const;
160 * @copydoc Toolkit::TableView::SetRelativeHeight
162 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
165 * @copydoc Toolkit::TableView::GetRelativeHeight
167 float GetRelativeHeight( unsigned int rowIndex ) const;
170 * @copydoc Toolkit::TableView::SetRelativeWidth
172 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
175 * @copydoc Toolkit::TableView::GetRelativeWidth
177 float GetRelativeWidth( unsigned int columnIndex ) const;
180 * @copydoc Toolkit::TableView::GetRows
182 unsigned int GetRows();
185 * @copydoc Toolkit::TableView::GetColumns
187 unsigned int GetColumns();
190 * @copydoc Toolkit::TableView::SetCellAlignment
192 void SetCellAlignment( Toolkit::TableView::CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical );
197 * Called when a property of an object of this type is set.
198 * @param[in] object The object whose property is set.
199 * @param[in] index The property index.
200 * @param[in] value The new property value.
202 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
205 * Called to retrieve a property of an object of this type.
206 * @param[in] object The object whose property is to be retrieved.
207 * @param[in] index The property index.
208 * @return The current value of the property.
210 static Property::Value GetProperty( BaseObject* object, Property::Index index );
212 private: // From Control
215 * @copydoc Control::OnControlChildAdd(Actor& child)
217 virtual void OnControlChildAdd( Actor& child );
220 * @copydoc Control::OnControlChildRemove(Actor& child)
222 virtual void OnControlChildRemove( Actor& child );
225 * @copydoc Control::OnRelayout
227 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
230 * @copydoc Control::CalculateChildSize
232 virtual float CalculateChildSize( const Actor& child, Dimension::Type dimension );
235 * @copydoc Control::OnInitialize()
237 virtual void OnInitialize();
240 * @copydoc Control::GetNextKeyboardFocusableActor
242 virtual Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
245 * @copydoc Control::GetNaturalSize()
247 virtual Vector3 GetNaturalSize();
250 * @copydoc Control::RelayoutDependentOnChildren()
252 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
255 * @copydoc Control::OnCalculateRelayoutSize
257 virtual void OnCalculateRelayoutSize( Dimension::Type dimension );
260 * @copydoc Control::OnLayoutNegotiated
262 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension );
265 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size )
267 virtual void OnSizeSet( const Vector3& size );
269 private: // Implementation
272 * Struct to hold data for rows and columns
274 * If sizePolicy is FIXED then size is the absolute size to use.
275 * If sizePolicy is FIT, RELATIVE or FILL then size is the calculated value of size.
280 * Default constructor
286 sizePolicy( Toolkit::TableView::FILL )
293 * @param[in] newSize The size to set for this data
294 * @param[in] newSizePolicy The policy used to interpret the size value
296 RowColumnData( float newSize, float newFillRatio, Toolkit::TableView::LayoutPolicy newSizePolicy )
298 fillRatio( newFillRatio ),
300 sizePolicy( newSizePolicy )
304 float size; ///< Set or calculated size
305 float fillRatio; ///< Ratio to fill remaining space, only valid with RELATIVE or FILL policy
306 float position; ///< Position of the row/column, this value is updated during every Relayout round
307 Toolkit::TableView::LayoutPolicy sizePolicy; ///< The size policy used to interpret the size value
310 typedef Dali::Vector<RowColumnData> RowColumnArray;
315 * Structure for the layout data
320 : horizontalAlignment( HorizontalAlignment::LEFT ),
321 verticalAlignment( VerticalAlignment::TOP )
327 Toolkit::TableView::CellPosition position;
328 HorizontalAlignment::Type horizontalAlignment;
329 VerticalAlignment::Type verticalAlignment;
335 * Construct a new TableView.
337 TableView( unsigned int initialRows, unsigned int initialColumns );
340 * Resizes the data containers to match the new size
341 * @param [in] rows in the table
342 * @param [in] columns in the table
344 void ResizeContainers( unsigned int rows, unsigned int columns );
347 * Resizes the data containers to match the new size
348 * @param [in] rows in the table
349 * @param [in] columns in the table
350 * @param [out] removed celldata
352 void ResizeContainers( unsigned int rows, unsigned int columns, std::vector<CellData>& removed );
355 * Helper to get the list of lost actors in the case when table looses cells.
356 * Also handles the case when actors span multiple cells
358 * @param removed actors
359 * @param rowsRemoved from table
360 * @param columnsRemoved from table
362 void RemoveAndGetLostActors( const std::vector<CellData>& lost, std::vector<Actor>& removed,
363 unsigned int rowsRemoved, unsigned int columnsRemoved );
366 * Helper to remove all instances of the actor
367 * @param child actor to remove
368 * @return true if the actor was found
370 bool RemoveAllInstances( const Actor& child );
373 * @brief Calculate the ratio of FILL rows/columns
375 * @param[in] data The RowColumn data to compute the relative sizes for
377 void CalculateFillSizes( RowColumnArray& data );
380 * @brief Calculate the total fixed sizes for a row or column
382 * @param[in] data The row or column data to process
384 float CalculateTotalFixedSize( const RowColumnArray& data );
387 * @brief Calculate the sizes of FIT rows/columns
389 * @param[in] data The row or column data to process
390 * @param[in] dimension The dimension being calculated: row == Dimension::HEIGHT, column == Dimension::WIDTH
392 void CalculateFitSizes( RowColumnArray& data, Dimension::Type dimension );
395 * @brief Search for a FIT cell in the array
397 * @param[in] data The row or column data to process
398 * @return Return if a FIT cell was found or not
400 bool FindFit( const RowColumnArray& data );
403 * @brief Return the cell padding for a given dimension
405 * @param[in] dimension The dimension to return the padding for
406 * @return Return the padding (x = low, y = high)
408 Vector2 GetCellPadding( Dimension::Type dimension );
411 * A reference counted object may only be deleted by calling Unreference()
413 virtual ~TableView();
415 private: // scripting support
418 * Called to set the heights/widths property.
419 * @param[in] tableViewImpl The object whose property is set.
420 * @param[in] funcFixed The set function to call, it can be SetFixedHeight or SetFixedWidth.
421 * @param[in] funcRelative The set function to call, it can be SetRelativeHeight or SetRelativeWidth.
422 * @param[in] funcFit The set function to call, it can be SetFitHeight or SetFiltWidth.
423 * @param[in] value The new property value.
425 static void SetHeightOrWidthProperty( TableView& tableViewImpl,
426 void(TableView::*funcFixed)(unsigned int, float),
427 void(TableView::*funcRelative)(unsigned int, float),
428 void(TableView::*funcFit)(unsigned int),
429 const Property::Value& map );
432 * Called to retrieve the property value of row heights.
433 * @return The property value of row heights.
435 Property::Value GetRowHeightsPropertyValue();
438 * Called to retrieve the property value of column widths.
439 * @return The fixed-widths property value.
441 Property::Value GetColumnWidthsPropertyValue();
444 * Generate the map type property value from the size vectors.
445 * @param[in] data The array of row or column data
446 * @param[out] map The property value.
448 void GetMapPropertyValue( const RowColumnArray& data, Property::Map& map );
452 * Helper class to prevent child adds and removes from causing relayout
453 * when we're already anyways going to do one in the end
455 class RelayoutingLock
460 * Constructor, sets the lock boolean
462 RelayoutingLock( TableView& parent )
463 : mLock( parent.mLayoutingChild )
469 * Destructor, releases lock boolean
474 // Note, we could also call Relayout here. This would save one line of code
475 // from each method that uses this lock but destructors are not meant to do
476 // big processing so better to not do it here. This destructor would also
477 // be called in case of an exception and we don't definitely want to do Relayout
487 // Undefined copy constructor and assignment operators
488 TableView(const TableView&);
489 TableView& operator=(const TableView& rhs);
493 Array2d<CellData> mCellData; ///< Data for each cell: Actor, alignment settings etc
495 RowColumnArray mRowData; ///< Data for each row
496 RowColumnArray mColumnData; ///< Data for each column
497 Size mFixedTotals; ///< Accumulated totals for fixed width and height
499 Size mPadding; ///< Padding to apply to each cell
500 bool mLayoutingChild; ///< Can't be a bitfield due to Relayouting lock
501 bool mRowDirty : 1; ///< Flag to indicate the row data is dirty
502 bool mColumnDirty : 1; ///< Flag to indicate the column data is dirty
505 } // namespace Internal
507 // Helpers for public-api forwarding methods
509 inline Toolkit::Internal::TableView& GetImpl( Toolkit::TableView& tableView )
511 DALI_ASSERT_ALWAYS(tableView);
513 Dali::RefObject& handle = tableView.GetImplementation();
515 return static_cast<Toolkit::Internal::TableView&>(handle);
518 inline const Toolkit::Internal::TableView& GetImpl( const Toolkit::TableView& tableView )
520 DALI_ASSERT_ALWAYS(tableView);
522 const Dali::RefObject& handle = tableView.GetImplementation();
524 return static_cast<const Toolkit::Internal::TableView&>(handle);
527 } // namespace Toolkit
531 #endif // __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__