TextField is re-laied out after its properties are changed.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / visual-factory / visual-base.h
1 #ifndef DALI_TOOLKIT_VISUAL_BASE_H
2 #define DALI_TOOLKIT_VISUAL_BASE_H
3 /*
4  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/object/base-handle.h>
22 #include <dali/public-api/actors/actor.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/dali-toolkit-common.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal DALI_INTERNAL
34 {
35 namespace Visual
36 {
37 class Base;
38 }
39 }
40
41 namespace Visual
42 {
43
44 /**
45  * @brief A Visual provides a renderer for drawing a control component. A control may have multiple visuals.
46  *
47  * Visuals reuse geometry, shader etc. across controls. They ensure that the renderer and texture sets exist only when control is on-stage.
48  * Each visual also responds to actor size and color change, and provides clipping at the renderer level.
49  * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
50  *
51  * The following properties are optional, but can be supplied in the property map to Dali::Toolkit::VisualFactory::CreateVisual().
52  *
53  * | %Property Name          | Type             |
54  * |-------------------------|------------------|
55  * | customShader            | MAP              |
56  * | transform               | MAP              |
57  *
58  * where \b customShader is a map with at least one of the following properties:
59  * | %Property Name          | Type                       | Required | Default | Description                             |
60  * |-------------------------|----------------------------|----------|---------|-----------------------------------------|
61  * | vertexShader            | STRING                     | No       | ""      | Vertex shader code                      |
62  * | fragmentShader          | STRING                     | No       | ""      | Fragment shader code                    |
63  * | subdivideGridX          | INTEGER                    | No       | 1       | How to subdivide the grid along X       |
64  * | subdivideGridY          | INTEGER                    | No       | 1       | How to subdivide the grid along Y       |
65  * | shaderHints             | INTEGER or ARRAY of STRING | No       | NONE    | Bitmask of hints @sa Dali::Shader::Hint |
66  *
67  * and \b transform is a map with the following properties:
68  * | %Property Name          | Type              | Required | Default                | Description                                         |
69  * |-------------------------|-------------------|----------|------------------------|-----------------------------------------------------|
70  * | offset                  | VECTOR2           | No       | (0,0)                  | Offset of visual from origin                        |
71  * | size                    | VECTOR2           | No       | (1,1)                  | size of visual                                      |
72  * | origin                  | INTEGER or STRING | No       | CENTER                 | origin of the visual @sa Dali::Toolkit::Align       |
73  * | anchorPoint             | INTEGER or STRING | No       | CENTER                 | anchor point of the visual @sa Dali::Toolkit::Align |
74  * | offsetPolicy            | VECTOR2           | No       | ( RELATIVE, RELATIVE ) | @sa Dali::Toolkit::Visual::Transform::Policy   |
75  * | sizePolicy              | VECTOR2           | No       | ( RELATIVE, RELATIVE ) | @sa Dali::Toolkit::Visual::Transform::Policy   |
76  *
77  * Relative means that the component describes a factor of the parent control size;
78  * size.x = 1 means full width; size.y = 0.5 means half height.
79  *
80  * Absolute means that the component describes world units (equivalent to pixels)
81  *
82  */
83 class DALI_TOOLKIT_API Base : public BaseHandle
84 {
85 public:
86
87   /**
88    * @brief Create an empty Visual Handle
89    */
90   Base();
91
92   /**
93    * @brief Destructor
94    *
95    * This is non-virtual since derived Handle types must not contain data or virtual methods.
96    */
97   ~Base();
98
99   /**
100    * @brief This copy constructor is required for (smart) pointer semantics.
101    *
102    * @param[in] handle A reference to the copied handle.
103    */
104   Base( const Base& handle );
105
106   /**
107    * @brief This assignment operator is required for (smart) pointer semantics.
108    *
109    * @param [in] handle  A reference to the copied handle.
110    * @return A reference to this.
111    */
112   Base& operator=( const Base& handle );
113
114   /**
115    * @brief Set the name of the visual
116    *
117    * Used by the styling system to animate properties
118    * @param[in] name The name to give the visual
119    */
120   void SetName( const std::string& name );
121
122   /**
123    * @brief Get the name of the visual
124    *
125    * Used by the styling system to animate properties
126    * @return The name of the visual
127    */
128   const std::string& GetName() const;
129
130   /**
131    * @brief Sets the transform and the control size
132    *
133    * @param[in] transform A property map describing the transform
134    * @param[in] controlSize The size of the parent control for visuals that need to scale internally.
135    */
136   void SetTransformAndSize( const Dali::Property::Map& transform, Size controlSize );
137
138   /**
139    * @brief Returns the height for a given width.
140    *
141    * @param[in] width Width to use.
142    *
143    * @return The height based on the width.
144    */
145   float GetHeightForWidth( float width );
146
147   /**
148    * @brief Returns the width for a given height.
149    *
150    * @param[in] height Height to use.
151    *
152    * @return The width based on the height.
153    */
154   float GetWidthForHeight( float height );
155
156   /**
157    * @brief Return the natural size of the visual.
158    *
159    * Deriving classes stipulate the natural size and by default a
160    * visual has a ZERO natural size.
161    *
162    * @note A visual may not actually have a natural size until it has
163    * been placed on stage and acquired all it's resources.
164    *
165    * @param[out] naturalSize The visual's natural size
166    */
167   void GetNaturalSize( Vector2& naturalSize );
168
169   /**
170    * @brief Set the depth index of this visual.
171    *
172    * Depth-index controls draw-order for overlapping visuals.
173    * Visuals with higher depth indices are rendered in front of other visual with smaller values
174    *
175    * @param[in] index The depth index of this visual.
176    */
177   void SetDepthIndex( int index );
178
179   /**
180    * @brief Get the depth index of this visual
181    *
182    * @return The depth index of this visual.
183    */
184   int GetDepthIndex() const;
185
186   /**
187    * @brief Create the property map representing this visual.
188    *
189    * @param[out] map The visual property map.
190    */
191   void CreatePropertyMap( Dali::Property::Map& map ) const;
192
193 public: // Not intended for application developers
194
195   explicit DALI_INTERNAL Base(Internal::Visual::Base *impl);
196
197 };
198
199 } // namespace Visual
200
201 } // namespace Toolkit
202
203 } // namespace Dali
204
205 #endif /*DALI_TOOLKIT_VISUAL_BASE_H*/