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
46 TABLEVIEW_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
47 TABLEVIEW_PROPERTY_END_INDEX = TABLEVIEW_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
51 * Structure for the layout data
57 Toolkit::TableView::CellPosition position;
61 * Create a new TableView.
62 * @return A smart-pointer to the newly allocated TableView.
64 static Toolkit::TableView New( unsigned int initialRows, unsigned int initialColumns );
67 * @copydoc Toolkit::TableView::AddChild
69 bool AddChild( Actor child, Toolkit::TableView::CellPosition position );
72 * @copydoc Toolkit::TableView::GetChildAt
74 Actor GetChildAt( Toolkit::TableView::CellPosition position );
77 * @copydoc Toolkit::TableView::RemoveChildAt
79 Actor RemoveChildAt( Toolkit::TableView::CellPosition position );
82 * @copydoc Toolkit::TableView::FindChildPosition
84 bool FindChildPosition( Actor child, Toolkit::TableView::CellPosition& position );
87 * @copydoc Toolkit::TableView::InsertRow
89 void InsertRow( unsigned int rowIndex );
92 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex )
94 void DeleteRow( unsigned int rowIndex );
97 * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed )
99 void DeleteRow( unsigned int rowIndex, std::vector<Actor>& removed );
102 * @copydoc Toolkit::TableView::InsertColumn
104 void InsertColumn( unsigned int columnIndex );
107 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex )
109 void DeleteColumn( unsigned int columnIndex );
112 * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed )
114 void DeleteColumn( unsigned int columnIndex, std::vector<Actor>& removed );
117 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns )
119 void Resize( unsigned int rows, unsigned int columns );
122 * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed )
124 void Resize( unsigned int rows, unsigned int columns, std::vector<Actor>& removed );
127 * @copydoc Toolkit::TableView::SetCellPadding
129 void SetCellPadding( Size padding );
132 * @copydoc Toolkit::TableView::GetCellPadding
134 Size GetCellPadding();
137 * @copydoc Toolkit::TableView::SetFixedHeight
139 void SetFixedHeight( unsigned int rowIndex, float height );
142 * @copydoc Toolkit::TableView::GetFixedHeight
144 float GetFixedHeight( unsigned int rowIndex ) const;
147 * @copydoc Toolkit::TableView::SetRelativeHeight
149 void SetRelativeHeight( unsigned int rowIndex, float heightPercentage );
152 * @copydoc Toolkit::TableView::GetRelativeHeight
154 float GetRelativeHeight( unsigned int rowIndex ) const;
157 * @copydoc Toolkit::TableView::SetFixedWidth
159 void SetFixedWidth( unsigned int columnIndex, float width );
162 * @copydoc Toolkit::TableView::GetFixedWidth
164 float GetFixedWidth( unsigned int columnIndex ) const;
167 * @copydoc Toolkit::TableView::SetRelativeWidth
169 void SetRelativeWidth( unsigned int columnIndex, float widthPercentage );
172 * @copydoc Toolkit::TableView::GetRelativeWidth
174 float GetRelativeWidth( unsigned int columnIndex ) const;
177 * @copydoc Toolkit::TableView::SetLayoutAnimationDuration
179 void SetLayoutAnimationDuration( float duration );
182 * @copydoc Toolkit::TableView::GetLayoutAnimationDuration
184 float GetLayoutAnimationDuration();
188 * @copydoc Toolkit::TableView::GetRows
190 unsigned int GetRows();
193 * @copydoc Toolkit::TableView::GetColumns
195 unsigned int GetColumns();
200 * Called when a property of an object of this type is set.
201 * @param[in] object The object whose property is set.
202 * @param[in] index The property index.
203 * @param[in] value The new property value.
205 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
208 * Called to retrieve a property of an object of this type.
209 * @param[in] object The object whose property is to be retrieved.
210 * @param[in] index The property index.
211 * @return The current value of the property.
213 static Property::Value GetProperty( BaseObject* object, Property::Index index );
215 private: // From Control
218 * @copydoc Control::OnControlChildAdd(Actor& child)
220 virtual void OnControlChildAdd(Actor& child);
223 * @copydoc Control::OnControlChildRemove(Actor& child)
225 virtual void OnControlChildRemove(Actor& child);
228 * @copydoc Control::OnRelaidOut
230 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
233 * @copydoc Control::OnInitialize()
235 virtual void OnInitialize();
238 * @copydoc Control::GetNextKeyboardFocusableActor
240 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
242 private: // Implementation
245 * Construct a new TableView.
247 TableView( unsigned int initialRows, unsigned int initialColumns );
250 * Resizes the data containers to match the new size
251 * @param [in] rows in the table
252 * @param [in] columns in the table
254 void ResizeContainers( unsigned int rows, unsigned int columns );
257 * Resizes the data containers to match the new size
258 * @param [in] rows in the table
259 * @param [in] columns in the table
260 * @param [out] removed celldata
262 void ResizeContainers( unsigned int rows, unsigned int columns, std::vector<CellData>& removed );
265 * Helper to get the list of lost actors in the case when table looses cells.
266 * Also handles the case when actors span multiple cells
268 * @param removed actors
269 * @param rowsRemoved from table
270 * @param columnsRemoved from table
272 void RemoveAndGetLostActors( const std::vector<CellData>& lost, std::vector<Actor>& removed,
273 unsigned int rowsRemoved, unsigned int columnsRemoved );
276 * Helper to remove all instances of the actor
277 * @param child actor to remove
278 * @return true if the actor was found
280 bool RemoveAllInstances( Actor child );
283 * Helper to update relative sizes
284 * @param fixedHeightsTotal sum of the fixed height rows
285 * @param fixedWidthsTotal sum of the fixed width columns
287 void UpdateRelativeSizes( float& fixedHeightsTotal, float& fixedWidthsTotal );
290 * A reference counted object may only be deleted by calling Unreference()
292 virtual ~TableView();
294 private: // scripting support
297 * Called to set the heights/widths property.
298 * @param[in] tableViewImpl The object whose property is set.
299 * @param[in] funcFixed The set function to call, it can be SetFixedHeight or SetFixedWidths.
300 * @param[in] funcRelative The set function to call, it can be SetRelativeHeight or SetRelativeWidths.
301 * @param[in] value The new property value.
303 static void SetHeightOrWidthProperty( TableView& tableViewImpl,
304 void(TableView::*funcFixed)(unsigned int, float),
305 void(TableView::*funcRelative)(unsigned int, float),
306 const Property::Value& map );
309 * Called to retrieve the property value of row heights.
310 * @return The property value of row heights.
312 Property::Value GetRowHeightsPropertyValue();
315 * Called to retrieve the property value of column widths.
316 * @return The fixed-widths property value.
318 Property::Value GetColumnWidthsPropertyValue();
321 * Generate the map type property value from the size vectors.
322 * @param[in] fixedSize The vector of fixed heights or widths.
323 * @param[in] relativeSize The vector of relative heights or widths.
324 * @param[out] map The property value.
326 void GetMapPropertyValue( const std::vector<float>& fixedSize, const std::vector<float>& relativeSize, Property::Map& map );
330 * Helper class to prevent child adds and removes from causing relayout
331 * when we're already anyways going to do one in the end
333 class RelayoutingLock
338 * Constructor, sets the lock boolean
340 RelayoutingLock( TableView& parent )
341 : mLock( parent.mLayoutingChild )
347 * Destructor, releases lock boolean
352 // Note, we could also call Relayout here. This would save one line of code
353 // from each method that uses this lock but destructors are not meant to do
354 // big processing so better to not do it here. This destructor would also
355 // be called in case of an exception and we don't definitely want to do Relayout
365 // Undefined copy constructor and assignment operators
366 TableView(const TableView&);
367 TableView& operator=(const TableView& rhs);
371 Array2d<CellData> mCellData;
372 Array2d<Size> mRelativeSizes;
373 std::vector<float> mFixedHeights;
374 std::vector<float> mRelativeHeights;
375 std::vector<float> mFixedWidths;
376 std::vector<float> mRelativeWidths;
378 bool mLayoutingChild;
379 float mConstraintDuration;
383 } // namespace Internal
385 // Helpers for public-api forwarding methods
387 inline Toolkit::Internal::TableView& GetImpl( Toolkit::TableView& tableView )
389 DALI_ASSERT_ALWAYS(tableView);
391 Dali::RefObject& handle = tableView.GetImplementation();
393 return static_cast<Toolkit::Internal::TableView&>(handle);
396 inline const Toolkit::Internal::TableView& GetImpl( const Toolkit::TableView& tableView )
398 DALI_ASSERT_ALWAYS(tableView);
400 const Dali::RefObject& handle = tableView.GetImplementation();
402 return static_cast<const Toolkit::Internal::TableView&>(handle);
405 } // namespace Toolkit
409 #endif // __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__