X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftable-view%2Ftable-view-impl.h;h=6f0776abb765e0dd485888dd43cef192a407f613;hb=4946918df0bb894b946175b13529c656893c440a;hp=55a7d7bd78f2f3aa80f12c57fcacbbd0d648af0f;hpb=2ec164cd618f93ccafe17b1d0b8ff16401ed4aef;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/table-view/table-view-impl.h b/dali-toolkit/internal/controls/table-view/table-view-impl.h index 55a7d7b..6f0776a 100644 --- a/dali-toolkit/internal/controls/table-view/table-view-impl.h +++ b/dali-toolkit/internal/controls/table-view/table-view-impl.h @@ -1,8 +1,8 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__ -#define __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__ +#ifndef DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H +#define DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,20 +18,20 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES +#include #include -#include #include "array-2d.h" namespace Dali { - namespace Toolkit { - namespace Internal { - /** * TableView is a custom control for laying out actors in a table layout * @see Dali::Toolkit:TableView for more details @@ -39,87 +39,76 @@ namespace Internal class TableView : public Control { public: - - /** - * Enum for the size policies of rows and columns - */ - enum CellSizePolicy - { - FILL, ///< Fill up available space, may have a ratio associated with it - FIXED, ///< A specific fixed width or height - FIT ///< Fit around actors in the row or column - }; - /** * Create a new TableView. * @return A smart-pointer to the newly allocated TableView. */ - static Toolkit::TableView New( unsigned int initialRows, unsigned int initialColumns ); + static Toolkit::TableView New(unsigned int initialRows, unsigned int initialColumns); /** * @copydoc Toolkit::TableView::AddChild */ - bool AddChild( Actor& child, const Toolkit::TableView::CellPosition& position ); + bool AddChild(Actor& child, const Toolkit::TableView::CellPosition& position); /** * @copydoc Toolkit::TableView::GetChildAt */ - Actor GetChildAt( const Toolkit::TableView::CellPosition& position ); + Actor GetChildAt(const Toolkit::TableView::CellPosition& position); /** * @copydoc Toolkit::TableView::RemoveChildAt */ - Actor RemoveChildAt( const Toolkit::TableView::CellPosition& position ); + Actor RemoveChildAt(const Toolkit::TableView::CellPosition& position); /** * @copydoc Toolkit::TableView::FindChildPosition */ - bool FindChildPosition( const Actor& child, Toolkit::TableView::CellPosition& positionOut ); + bool FindChildPosition(const Actor& child, Toolkit::TableView::CellPosition& positionOut); /** * @copydoc Toolkit::TableView::InsertRow */ - void InsertRow( unsigned int rowIndex ); + void InsertRow(unsigned int rowIndex); /** * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex ) */ - void DeleteRow( unsigned int rowIndex ); + void DeleteRow(unsigned int rowIndex); /** * @copydoc Toolkit::TableView::DeleteRow( unsigned int rowIndex, std::vector& removed ) */ - void DeleteRow( unsigned int rowIndex, std::vector& removed ); + void DeleteRow(unsigned int rowIndex, std::vector& removed); /** * @copydoc Toolkit::TableView::InsertColumn */ - void InsertColumn( unsigned int columnIndex ); + void InsertColumn(unsigned int columnIndex); /** * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex ) */ - void DeleteColumn( unsigned int columnIndex ); + void DeleteColumn(unsigned int columnIndex); /** * @copydoc Toolkit::TableView::DeleteColumn( unsigned int columnIndex, std::vector& removed ) */ - void DeleteColumn( unsigned int columnIndex, std::vector& removed ); + void DeleteColumn(unsigned int columnIndex, std::vector& removed); /** * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns ) */ - void Resize( unsigned int rows, unsigned int columns ); + void Resize(unsigned int rows, unsigned int columns); /** * @copydoc Toolkit::TableView::Resize( unsigned int rows, unsigned int columns, std::vector& removed ) */ - void Resize( unsigned int rows, unsigned int columns, std::vector& removed ); + void Resize(unsigned int rows, unsigned int columns, std::vector& removed); /** * @copydoc Toolkit::TableView::SetCellPadding */ - void SetCellPadding( Size padding ); + void SetCellPadding(Size padding); /** * @copydoc Toolkit::TableView::GetCellPadding @@ -127,76 +116,64 @@ public: Size GetCellPadding(); /** - * @brief Set a row policy - * - * @param[in] rowIndex The row to set the policy for - * @param[in] policy The policy to set + * @copydoc Toolkit::TableView::SetFitHeight */ - void SetRowPolicy( unsigned int rowIndex, CellSizePolicy policy ); + void SetFitHeight(unsigned int rowIndex); /** - * @brief Querry a row policy - * - * @param[in] rowIndex The row to querry - * @return Return the policy + * @copydoc Toolkit::TableView::IsFitHeight */ - CellSizePolicy GetRowPolicy( unsigned int rowIndex ) const; + bool IsFitHeight(unsigned int rowIndex) const; /** - * @brief Set a column policy - * - * @param[in] columnIndex The column to set the policy for - * @param[in] policy The policy to set + * @copydoc Toolkit::TableView::SetFitWidth */ - void SetColumnPolicy( unsigned int columnIndex, CellSizePolicy policy ); + void SetFitWidth(unsigned int columnIndex); /** - * @brief Querry a column policy - * - * @param[in] columnIndex The column to querry - * @return Return the policy + * @copydoc Toolkit::TableView::IsFitWidth */ - CellSizePolicy GetColumnPolicy( unsigned int columnIndex ) const; + bool IsFitWidth(unsigned int columnIndex) const; /** * @copydoc Toolkit::TableView::SetFixedWidth */ - void SetFixedWidth( unsigned int columnIndex, float width ); + void SetFixedWidth(unsigned int columnIndex, float width); /** * @copydoc Toolkit::TableView::GetFixedWidth */ - float GetFixedWidth( unsigned int columnIndex ) const; + float GetFixedWidth(unsigned int columnIndex) const; /** * @copydoc Toolkit::TableView::SetFixedHeight */ - void SetFixedHeight( unsigned int rowIndex, float height ); + void SetFixedHeight(unsigned int rowIndex, float height); /** * @copydoc Toolkit::TableView::GetFixedHeight */ - float GetFixedHeight( unsigned int rowIndex ) const; + float GetFixedHeight(unsigned int rowIndex) const; /** * @copydoc Toolkit::TableView::SetRelativeHeight */ - void SetRelativeHeight( unsigned int rowIndex, float heightPercentage ); + void SetRelativeHeight(unsigned int rowIndex, float heightPercentage); /** * @copydoc Toolkit::TableView::GetRelativeHeight */ - float GetRelativeHeight( unsigned int rowIndex ) const; + float GetRelativeHeight(unsigned int rowIndex) const; /** * @copydoc Toolkit::TableView::SetRelativeWidth */ - void SetRelativeWidth( unsigned int columnIndex, float widthPercentage ); + void SetRelativeWidth(unsigned int columnIndex, float widthPercentage); /** * @copydoc Toolkit::TableView::GetRelativeWidth */ - float GetRelativeWidth( unsigned int columnIndex ) const; + float GetRelativeWidth(unsigned int columnIndex) const; /** * @copydoc Toolkit::TableView::GetRows @@ -211,7 +188,7 @@ public: /** * @copydoc Toolkit::TableView::SetCellAlignment */ - void SetCellAlignment( Toolkit::TableView::CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical ); + void SetCellAlignment(Toolkit::TableView::CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical); // Properties @@ -221,7 +198,7 @@ public: * @param[in] index The property index. * @param[in] value The new property value. */ - static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ); + static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value); /** * Called to retrieve a property of an object of this type. @@ -229,67 +206,70 @@ public: * @param[in] index The property index. * @return The current value of the property. */ - static Property::Value GetProperty( BaseObject* object, Property::Index index ); + static Property::Value GetProperty(BaseObject* object, Property::Index index); private: // From Control - /** - * @copydoc Control::OnControlChildAdd(Actor& child) + * @copydoc Control::OnChildAdd(Actor& child) */ - virtual void OnControlChildAdd( Actor& child ); + void OnChildAdd(Actor& child) override; /** - * @copydoc Control::OnControlChildRemove(Actor& child) + * @copydoc Control::OnChildRemove(Actor& child) */ - virtual void OnControlChildRemove( Actor& child ); + void OnChildRemove(Actor& child) override; /** * @copydoc Control::OnRelayout */ - virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ); + void OnRelayout(const Vector2& size, RelayoutContainer& container) override; /** * @copydoc Control::CalculateChildSize */ - virtual float CalculateChildSize( const Actor& child, Dimension dimension ); + float CalculateChildSize(const Actor& child, Dimension::Type dimension) override; /** * @copydoc Control::OnInitialize() */ - virtual void OnInitialize(); + void OnInitialize() override; /** * @copydoc Control::GetNextKeyboardFocusableActor */ - virtual Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled ); + Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled) override; /** * @copydoc Control::GetNaturalSize() */ - virtual Vector3 GetNaturalSize(); + Vector3 GetNaturalSize() override; /** * @copydoc Control::RelayoutDependentOnChildren() */ - virtual bool RelayoutDependentOnChildren( Dimension dimension = ALL_DIMENSIONS ); + bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override; /** * @copydoc Control::OnCalculateRelayoutSize */ - virtual void OnCalculateRelayoutSize( Dimension dimension ); + void OnCalculateRelayoutSize(Dimension::Type dimension) override; /** * @copydoc Control::OnLayoutNegotiated */ - virtual void OnLayoutNegotiated( float size, Dimension dimension ); + void OnLayoutNegotiated(float size, Dimension::Type dimension) override; -private: // Implementation + /** + * @copydoc CustomActorImpl::OnSizeSet( const Vector3& size ) + */ + void OnSizeSet(const Vector3& size) override; +private: // Implementation /** * Struct to hold data for rows and columns * * If sizePolicy is FIXED then size is the absolute size to use. - * If sizePolicy is FIT or FILL then size is the calculated value of size. + * If sizePolicy is FIT, RELATIVE or FILL then size is the calculated value of size. */ struct RowColumnData { @@ -297,10 +277,10 @@ private: // Implementation * Default constructor */ RowColumnData() - : size( 0.0f ), - fillRatio( 0.0f ), - sizePolicy( FILL ), - userFillRatio( false ) + : size(0.0f), + fillRatio(0.0f), + position(0.0f), + sizePolicy(Toolkit::TableView::FILL) { } @@ -310,55 +290,53 @@ private: // Implementation * @param[in] newSize The size to set for this data * @param[in] newSizePolicy The policy used to interpret the size value */ - RowColumnData( float newSize, float newFillRatio, CellSizePolicy newSizePolicy, bool newUserFillRatio ) - : size( newSize ), - fillRatio( newFillRatio ), - sizePolicy( newSizePolicy ), - userFillRatio( newUserFillRatio ) + RowColumnData(float newSize, float newFillRatio, Toolkit::TableView::LayoutPolicy newSizePolicy) + : size(newSize), + fillRatio(newFillRatio), + position(0.0f), + sizePolicy(newSizePolicy) { } - float size; ///< Set or calculated size - float fillRatio; ///< Ratio to fill remaining space - CellSizePolicy sizePolicy; ///< The size policy used to interpret the size value - bool userFillRatio : 1; ///< FillRatio was set by user + float size; ///< Set or calculated size + float fillRatio; ///< Ratio to fill remaining space, only valid with RELATIVE or FILL policy + float position; ///< Position of the row/column, this value is updated during every Relayout round + Toolkit::TableView::LayoutPolicy sizePolicy; ///< The size policy used to interpret the size value }; typedef Dali::Vector RowColumnArray; public: - /** * Structure for the layout data */ struct CellData { CellData() - : horizontalAlignment( HorizontalAlignment::LEFT ), - verticalAlignment( VerticalAlignment::TOP ) + : horizontalAlignment(HorizontalAlignment::LEFT), + verticalAlignment(VerticalAlignment::TOP) { } // data members - Dali::Actor actor; + Dali::Actor actor; Toolkit::TableView::CellPosition position; - HorizontalAlignment::Type horizontalAlignment; - VerticalAlignment::Type verticalAlignment; + HorizontalAlignment::Type horizontalAlignment; + VerticalAlignment::Type verticalAlignment; }; private: - /** * Construct a new TableView. */ - TableView( unsigned int initialRows, unsigned int initialColumns ); + TableView(unsigned int initialRows, unsigned int initialColumns); /** * Resizes the data containers to match the new size * @param [in] rows in the table * @param [in] columns in the table */ - void ResizeContainers( unsigned int rows, unsigned int columns ); + void ResizeContainers(unsigned int rows, unsigned int columns); /** * Resizes the data containers to match the new size @@ -366,7 +344,7 @@ private: * @param [in] columns in the table * @param [out] removed celldata */ - void ResizeContainers( unsigned int rows, unsigned int columns, std::vector& removed ); + void ResizeContainers(unsigned int rows, unsigned int columns, std::vector& removed); /** * Helper to get the list of lost actors in the case when table looses cells. @@ -376,45 +354,36 @@ private: * @param rowsRemoved from table * @param columnsRemoved from table */ - void RemoveAndGetLostActors( const std::vector& lost, std::vector& removed, - unsigned int rowsRemoved, unsigned int columnsRemoved ); + void RemoveAndGetLostActors(const std::vector& lost, std::vector& removed, unsigned int rowsRemoved, unsigned int columnsRemoved); /** * Helper to remove all instances of the actor * @param child actor to remove * @return true if the actor was found */ - bool RemoveAllInstances( const Actor& child ); + bool RemoveAllInstances(const Actor& child); /** - * @brief Compute relative sizes for an array + * @brief Calculate the ratio of FILL rows/columns * * @param[in] data The RowColumn data to compute the relative sizes for */ - void ComputeRelativeSizes( RowColumnArray& data ); + void CalculateFillSizes(RowColumnArray& data); /** * @brief Calculate the total fixed sizes for a row or column * * @param[in] data The row or column data to process */ - float CalculateTotalFixedSize( const RowColumnArray& data ); + float CalculateTotalFixedSize(const RowColumnArray& data); /** - * @brief Calculate the fixed sizes for a row or column + * @brief Calculate the sizes of FIT rows/columns * * @param[in] data The row or column data to process - * @param[in] dimension The dimension being calculated: row == HEIGHT, column == WIDTH + * @param[in] dimension The dimension being calculated: row == Dimension::HEIGHT, column == Dimension::WIDTH */ - void CalculateFixedSizes( RowColumnArray& data, Dimension dimension ); - - /** - * @brief Calculate the value of the relative sizes - * - * @param[in] data The row or column data to process - * @param[in] size The size of the table view in that dimension - */ - void CalculateRelativeSizes( RowColumnArray& data, float size ); + void CalculateFitSizes(RowColumnArray& data, Dimension::Type dimension); /** * @brief Search for a FIT cell in the array @@ -422,12 +391,15 @@ private: * @param[in] data The row or column data to process * @return Return if a FIT cell was found or not */ - bool FindFit( const RowColumnArray& data ); + bool FindFit(const RowColumnArray& data); /** - * @brief Calculate row and column data when it is dirty + * @brief Return the cell padding for a given dimension + * + * @param[in] dimension The dimension to return the padding for + * @return Return the padding (x = low, y = high) */ - void CalculateRowColumnData(); + Vector2 GetCellPadding(Dimension::Type dimension); /** * A reference counted object may only be deleted by calling Unreference() @@ -435,18 +407,19 @@ private: virtual ~TableView(); private: // scripting support - /** * Called to set the heights/widths property. * @param[in] tableViewImpl The object whose property is set. - * @param[in] funcFixed The set function to call, it can be SetFixedHeight or SetFixedWidths. - * @param[in] funcRelative The set function to call, it can be SetRelativeHeight or SetRelativeWidths. + * @param[in] funcFixed The set function to call, it can be SetFixedHeight or SetFixedWidth. + * @param[in] funcRelative The set function to call, it can be SetRelativeHeight or SetRelativeWidth. + * @param[in] funcFit The set function to call, it can be SetFitHeight or SetFiltWidth. * @param[in] value The new property value. */ - static void SetHeightOrWidthProperty( TableView& tableViewImpl, - void(TableView::*funcFixed)(unsigned int, float), - void(TableView::*funcRelative)(unsigned int, float), - const Property::Value& map ); + static void SetHeightOrWidthProperty(TableView& tableViewImpl, + void (TableView::*funcFixed)(unsigned int, float), + void (TableView::*funcRelative)(unsigned int, float), + void (TableView::*funcFit)(unsigned int), + const Property::Value& map); /** * Called to retrieve the property value of row heights. @@ -465,8 +438,7 @@ private: // scripting support * @param[in] data The array of row or column data * @param[out] map The property value. */ - void GetMapPropertyValue( const RowColumnArray& data, Property::Map& map ); - + void GetMapPropertyValue(const RowColumnArray& data, Property::Map& map); /** * Helper class to prevent child adds and removes from causing relayout @@ -475,12 +447,11 @@ private: // scripting support class RelayoutingLock { public: // API - /** * Constructor, sets the lock boolean */ - RelayoutingLock( TableView& parent ) - : mLock( parent.mLayoutingChild ) + RelayoutingLock(TableView& parent) + : mLock(parent.mLayoutingChild) { mLock = true; } @@ -503,29 +474,30 @@ private: // scripting support }; private: - // Undefined copy constructor and assignment operators TableView(const TableView&); TableView& operator=(const TableView& rhs); -private: // Data +private: // Data + Array2d mCellData; ///< Data for each cell: Actor, alignment settings etc - Array2d mCellData; ///< Data for each cell: Actor, alignment settings etc + RowColumnArray mRowData; ///< Data for each row + RowColumnArray mColumnData; ///< Data for each column + Size mFixedTotals; ///< Accumulated totals for fixed width and height - RowColumnArray mRowData; ///< Data for each row - RowColumnArray mColumnData; ///< Data for each column - Size mFixedTotals; ///< Accumulated totals for fixed width and height + Size mPadding; ///< Padding to apply to each cell - Size mPadding; ///< Padding to apply to each cell - bool mLayoutingChild; ///< Can't be a bitfield due to Relayouting lock - bool mRowColumnDirty : 1; ///< Flag to indicate the row column data is dirty + WeakHandle mPreviousFocusedActor; ///< Perviously focused actor + bool mLayoutingChild; ///< Can't be a bitfield due to Relayouting lock + bool mRowDirty : 1; ///< Flag to indicate the row data is dirty + bool mColumnDirty : 1; ///< Flag to indicate the column data is dirty }; } // namespace Internal // Helpers for public-api forwarding methods -inline Toolkit::Internal::TableView& GetImpl( Toolkit::TableView& tableView ) +inline Toolkit::Internal::TableView& GetImpl(Toolkit::TableView& tableView) { DALI_ASSERT_ALWAYS(tableView); @@ -534,7 +506,7 @@ inline Toolkit::Internal::TableView& GetImpl( Toolkit::TableView& tableView ) return static_cast(handle); } -inline const Toolkit::Internal::TableView& GetImpl( const Toolkit::TableView& tableView ) +inline const Toolkit::Internal::TableView& GetImpl(const Toolkit::TableView& tableView) { DALI_ASSERT_ALWAYS(tableView); @@ -547,4 +519,4 @@ inline const Toolkit::Internal::TableView& GetImpl( const Toolkit::TableView& ta } // namespace Dali -#endif // __DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H__ +#endif // DALI_TOOLKIT_INTERNAL_TABLE_VIEW_H