TableView: Cleanup
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / table-view / table-view.h
index 5f9bd5d..c3f0545 100644 (file)
@@ -1,27 +1,31 @@
 #ifndef __DALI_TOOLKIT_TABLE_VIEW_H__
 #define __DALI_TOOLKIT_TABLE_VIEW_H__
 
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/vector-wrapper.h>
+#include <dali/public-api/actors/actor-enumerations.h>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/dali-vector.h>
 #include <dali-toolkit/public-api/controls/control.h>
 
-namespace Dali DALI_IMPORT_API
+namespace Dali
 {
 
 namespace Toolkit
@@ -33,16 +37,109 @@ class TableView;
 }
 
 /**
- * TableView is a layout container for aligning child actors in a grid like layout.
+ * @brief TableView is a layout container for aligning child actors in a grid like layout.
+ *
  * TableView constrains the x and y position and width and height of the child actors.
  * z position and depth are left intact so that 3D model actors can also be laid out
  * in a grid without loosing their depth scaling.
+ *
+ * @nosubgrouping
+ * <h3>Per-child Custom properties for script supporting:</h3>
+ *
+ * When an actor is add to the tableView through Actor::Add() instead of TableView::AddChild,
+ * the following custom properties of the actor are checked to decide the actor position inside the table.
+ *
+ * These properties are registered dynamically to the child and is non-animatable.
+ *
+ * | %Property Name            | Type        |
+ * |---------------------------|-------------|
+ * | cell-index                | Vector2     |
+ * | row-span                  | float       |
+ * | column-span               | float       |
+ * | cell-horizontal-alignment | string      |
+ * | cell-vertical-alignment   | string      |
+ *
+ * The row-span or column span has integer value, but its type is float here due to the limitation of the builder's ability to differentiate integer and float from Json string.
+ * The available values for cell-horizontal-alignment are: left, center, right.
+ * The available values for cell-vertical-alignment are: top, center, bottom.
+ *
+ * @code
+ * "name":"gallery-1",
+ * "type":"ImageActor",
+ * "image": {
+ *    "filename": "{DALI_IMAGE_DIR}gallery-small-1.jpg"
+ *  },
+ *  "custom-properties": {
+ *     "cell-index":[1,1],  // property to specify the top-left cell this child occupies, if not set, the first available cell is used
+ *     "row-span":3,        // property to specify how many rows this child occupies, if not set, default value is 1
+ *     "column-span": 2,    // property to specify how many columns this child occupies, if nor set, default value is 1
+ *     "cell-horizontal-alignment": "left", // property to specify how to align horizontally inside the cells, if not set, default value is 'left'
+ *     "cell-vertical-alignment": "center"  // property to specify how to align vertically inside the cells, if not set, default value is 'top'
+ *   }
+ * @endcode
  */
-class TableView : public Control
+class DALI_IMPORT_API TableView : public Control
 {
 public:
 
   /**
+   * @brief The start and end property ranges for this control.
+   */
+  enum PropertyRange
+  {
+    PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
+    PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000              ///< Reserve property indices
+  };
+
+  /**
+   * @brief An enumeration of properties belonging to the TableView class.
+   *
+   * LayoutRows: set the height of the rows.
+   * It has the format as follows in script:
+   * @code
+   * "layout-rows":
+      {
+        "0": { "policy": "fixed", "value": 40 },       //@see SetFixedHight
+        "2": { "policy": "relative", "value": 0.33 },  //@see SetRelativeHeight
+        "3": { "policy": "fit", "value":0.0 }          //@see SetFitHeight, the value is not used, its height is decided by the children in this row
+      }
+   * @endcode
+   *
+   * LayoutColumns: set the height of the rows.
+   * It has the format as follows in script:
+   * @code
+   * "layout-columns":
+      {
+        "0": { "policy": "fixed", "value": 40 },       //@see SetFixedWidth
+        "1": { "policy": "fit", "value":0.0 }          //@see SetFitHeight, the value is not used, its width is decided by the children in this column
+        "2": { "policy": "relative", "value": 0.33 }   //@see SetRelativeWidth
+      }
+   * @endcode
+   */
+  struct Property
+  {
+    enum
+    {
+      ROWS = PROPERTY_START_INDEX, ///< name "rows",           type unsigned int
+      COLUMNS,                     ///< name "columns",        type unsigned int
+      CELL_PADDING,                ///< name "cell-padding",   type Vector2
+      LAYOUT_ROWS,                 ///< name "layout-rows",    type Map
+      LAYOUT_COLUMNS,              ///< name "layout-columns", type Map
+    };
+  };
+
+  /**
+   * @brief Describes how the size of a row / column been set
+   */
+  enum LayoutPolicy
+  {
+    FIXED,      ///< Fixed with the given value.
+    RELATIVE,   ///< Calculated as percentage of the remainder after subtracting Padding and Fixed height/width
+    FILL,       ///< Default policy, get the remainder of the 100% (after subtracting Fixed, Fit and Relative height/ width) divided evenly between 'fill' rows/columns
+    FIT         ///< Fit around its children.
+  };
+
+  /**
    * Structure to specify layout position for child actor
    */
   struct CellPosition
@@ -80,10 +177,11 @@ public:
   TableView& operator=( const TableView& handle );
 
   /**
-   * Virtual destructor.
-   * Dali::Object derived classes typically do not contain member data.
+   * @brief Destructor
+   *
+   * This is non-virtual since derived Handle types must not contain data or virtual methods.
    */
-  virtual ~TableView();
+  ~TableView();
 
   /**
    * Create the TableView control.
@@ -208,6 +306,36 @@ public:
   Size GetCellPadding();
 
   /**
+   * @brief Specify this row as fitting its height to its children
+   *
+   * @param[in] rowIndex The row to set
+   */
+  void SetFitHeight( unsigned int rowIndex );
+
+  /**
+   * @brief Is the row a fit row
+   *
+   * @param[in] rowIndex The row to check
+   * @return Return true if the row is fit
+   */
+  bool IsFitHeight( unsigned int rowIndex ) const;
+
+  /**
+   * @brief Specify this column as fitting its width to its children
+   *
+   * @param[in] columnIndex The column to set
+   */
+  void SetFitWidth( unsigned int columnIndex );
+
+  /**
+   * @brief Is the column a fit column
+   *
+   * @param[in] columnIndex The column to check
+   * @return Return true if the column is fit
+   */
+  bool IsFitWidth( unsigned int columnIndex ) const;
+
+  /**
    * Sets a row to have fixed height
    * Setting a fixed height of 0 has no effect
    * @pre The row rowIndex must exist.
@@ -278,19 +406,6 @@ public:
   float GetRelativeWidth( unsigned int columnIndex ) const;
 
   /**
-   * Sets the layout animation duration for add, remove and relayout
-   * @param duration for the layout animations
-   * @note The default duration is 0.0f.
-   */
-  void SetLayoutAnimationDuration( float duration );
-
-  /**
-   * Gets the layout animation duration for add, remove and relayout
-   * @return duration for the layout animations
-   */
-  float GetLayoutAnimationDuration();
-
-  /**
    * @return the amount of rows in the table
    */
   unsigned int GetRows();
@@ -300,19 +415,30 @@ public:
    */
   unsigned int GetColumns();
 
+  /**
+   * @brief Set the alignment on a cell.
+   *
+   * Cells without calling this function have the default values of LEFT and TOP respectively.
+   *
+   * @param[in] position The cell to set alignment on.
+   * @param[in] horizontal The horizontal alignment.
+   * @param[in] vertical The vertical alignment.
+   */
+  void SetCellAlignment( CellPosition position, HorizontalAlignment::Type horizontal, VerticalAlignment::Type vertical );
+
 public: // Not intended for application developers
 
   /**
    * Creates a handle using the Toolkit::Internal implementation.
    * @param[in]  implementation  The Control implementation.
    */
-  TableView(Internal::TableView& implementation);
+  DALI_INTERNAL TableView(Internal::TableView& implementation);
 
   /**
    * Allows the creation of this Control from an Internal::CustomActor pointer.
    * @param[in]  internal  A pointer to the internal CustomActor.
    */
-  TableView( Dali::Internal::CustomActor* internal );
+  explicit DALI_INTERNAL TableView( Dali::Internal::CustomActor* internal );
 };
 
 } // namespace Toolkit