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 );
264 private: // Implementation
267 * Struct to hold data for rows and columns
269 * If sizePolicy is FIXED then size is the absolute size to use.
270 * If sizePolicy is FIT or FILL then size is the calculated value of size.
275 * Default constructor
281 sizePolicy( Toolkit::TableView::FILL )
288 * @param[in] newSize The size to set for this data
289 * @param[in] newSizePolicy The policy used to interpret the size value
291 RowColumnData( float newSize, float newFillRatio, Toolkit::TableView::LayoutPolicy newSizePolicy )
293 fillRatio( newFillRatio ),
295 sizePolicy( newSizePolicy )
299 float size; ///< Set or calculated size
300 float fillRatio; ///< Ratio to fill remaining space, only valid with RELATIVE or FILL policy
301 float position; ///< Position of the row/column, this value is updated during every Relayout round
302 Toolkit::TableView::LayoutPolicy sizePolicy; ///< The size policy used to interpret the size value
305 typedef Dali::Vector<RowColumnData> RowColumnArray;
310 * Structure for the layout data
315 : horizontalAlignment( HorizontalAlignment::LEFT ),
316 verticalAlignment( VerticalAlignment::TOP )
322 Toolkit::TableView::CellPosition position;
323 HorizontalAlignment::Type horizontalAlignment;
324 VerticalAlignment::Type verticalAlignment;
330 * Construct a new TableView.
332 TableView( unsigned int initialRows, unsigned int initialColumns );
335 * Resizes the data containers to match the new size
336 * @param [in] rows in the table
337 * @param [in] columns in the table
339 void ResizeContainers( unsigned int rows, unsigned int columns );
342 * Resizes the data containers to match the new size
343 * @param [in] rows in the table
344 * @param [in] columns in the table
345 * @param [out] removed celldata
347 void ResizeContainers( unsigned int rows, unsigned int columns, std::vector<CellData>& removed );
350 * Helper to get the list of lost actors in the case when table looses cells.
351 * Also handles the case when actors span multiple cells
353 * @param removed actors
354 * @param rowsRemoved from table
355 * @param columnsRemoved from table
357 void RemoveAndGetLostActors( const std::vector<CellData>& lost, std::vector<Actor>& removed,
358 unsigned int rowsRemoved, unsigned int columnsRemoved );
361 * Helper to remove all instances of the actor
362 * @param child actor to remove
363 * @return true if the actor was found
365 bool RemoveAllInstances( const Actor& child );
368 * @brief Compute relative sizes for an array
370 * @param[in] data The RowColumn data to compute the relative sizes for
372 void ComputeRelativeSizes( RowColumnArray& data );
375 * @brief Calculate the total fixed sizes for a row or column
377 * @param[in] data The row or column data to process
379 float CalculateTotalFixedSize( const RowColumnArray& data );
382 * @brief Calculate the fixed sizes for a row or column
384 * @param[in] data The row or column data to process
385 * @param[in] dimension The dimension being calculated: row == Dimension::HEIGHT, column == Dimension::WIDTH
387 void CalculateFixedSizes( RowColumnArray& data, Dimension::Type dimension );
390 * @brief Calculate the value of the relative sizes
392 * @param[in] data The row or column data to process
393 * @param[in] size The size of the table view in that dimension
395 void CalculateRelativeSizes( RowColumnArray& data, float size );
398 * @brief Search for a FIT cell in the array
400 * @param[in] data The row or column data to process
401 * @return Return if a FIT cell was found or not
403 bool FindFit( const RowColumnArray& data );
406 * @brief Calculate row and column data when it is dirty
408 void CalculateRowColumnData();
411 * @brief Return the cell padding for a given dimension
413 * @param[in] dimension The dimension to return the padding for
414 * @return Return the padding (x = low, y = high)
416 Vector2 GetCellPadding( Dimension::Type dimension );
419 * A reference counted object may only be deleted by calling Unreference()
421 virtual ~TableView();
423 private: // scripting support
426 * Called to set the heights/widths property.
427 * @param[in] tableViewImpl The object whose property is set.
428 * @param[in] funcFixed The set function to call, it can be SetFixedHeight or SetFixedWidth.
429 * @param[in] funcRelative The set function to call, it can be SetRelativeHeight or SetRelativeWidth.
430 * @param[in] funcFit The set function to call, it can be SetFitHeight or SetFiltWidth.
431 * @param[in] value The new property value.
433 static void SetHeightOrWidthProperty( TableView& tableViewImpl,
434 void(TableView::*funcFixed)(unsigned int, float),
435 void(TableView::*funcRelative)(unsigned int, float),
436 void(TableView::*funcFit)(unsigned int),
437 const Property::Value& map );
440 * Called to retrieve the property value of row heights.
441 * @return The property value of row heights.
443 Property::Value GetRowHeightsPropertyValue();
446 * Called to retrieve the property value of column widths.
447 * @return The fixed-widths property value.
449 Property::Value GetColumnWidthsPropertyValue();
452 * Generate the map type property value from the size vectors.
453 * @param[in] data The array of row or column data
454 * @param[out] map The property value.
456 void GetMapPropertyValue( const RowColumnArray& data, Property::Map& map );
460 * Helper class to prevent child adds and removes from causing relayout
461 * when we're already anyways going to do one in the end
463 class RelayoutingLock
468 * Constructor, sets the lock boolean
470 RelayoutingLock( TableView& parent )
471 : mLock( parent.mLayoutingChild )
477 * Destructor, releases lock boolean
482 // Note, we could also call Relayout here. This would save one line of code
483 // from each method that uses this lock but destructors are not meant to do
484 // big processing so better to not do it here. This destructor would also
485 // be called in case of an exception and we don't definitely want to do Relayout
495 // Undefined copy constructor and assignment operators
496 TableView(const TableView&);
497 TableView& operator=(const TableView& rhs);
501 Array2d<CellData> mCellData; ///< Data for each cell: Actor, alignment settings etc
503 RowColumnArray mRowData; ///< Data for each row
504 RowColumnArray mColumnData; ///< Data for each column
505 Size mFixedTotals; ///< Accumulated totals for fixed width and height
507 Size mPadding; ///< Padding to apply to each cell
508 bool mLayoutingChild; ///< Can't be a bitfield due to Relayouting lock
509 bool mRowColumnDirty : 1; ///< Flag to indicate the row column data is dirty
512 } // namespace Internal
514 // Helpers for public-api forwarding methods
516 inline Toolkit::Internal::TableView& GetImpl( Toolkit::TableView& tableView )
518 DALI_ASSERT_ALWAYS(tableView);
520 Dali::RefObject& handle = tableView.GetImplementation();
522 return static_cast<Toolkit::Internal::TableView&>(handle);
525 inline const Toolkit::Internal::TableView& GetImpl( const Toolkit::TableView& tableView )
527 DALI_ASSERT_ALWAYS(tableView);
529 const Dali::RefObject& handle = tableView.GetImplementation();
531 return static_cast<const Toolkit::Internal::TableView&>(handle);
534 } // namespace Toolkit
538 #endif // __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__