A simple control using visuals
[platform/core/uifw/dali-demo.git] / examples / simple-visuals-control / my-control.h
1 #ifndef DALI_DEMO_MY_CONTROL_H
2 #define DALI_DEMO_MY_CONTROL_H
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <string>
22
23 namespace Demo
24 {
25
26 namespace Internal
27 {
28 class MyControl;
29 }
30
31 /**
32  * @brief MyControl is an example control,
33  *
34  * @details It's purpose is to show how to create a simple control to work with the style sheet and state changes.
35  * States changes includes Normal, Focused and Disabled, this example uses the style sheet to set visuals for Normal and Focused states.
36  * When the Focus manager changes the control to be focused the visual displayed is changed and vice versa.
37  *
38  * The visual has the property name ICON_VISUAL with the style sheet string equivalent of "iconVisual"
39  *
40  */
41
42 class MyControl : public Dali::Toolkit::Control
43 {
44 public:
45
46   /**
47    * The start and end property ranges for this Control
48    * My control can use properties from Toolkit::Control as it is derived from it. As control is derived from Actor, MyControl can also use Dali::Actor Properties.
49    *
50    * To ensure that the Property indexes from MyControl do not shadow any from Control we start it's index from the end of Toolkit::Control's indexes.
51    *
52    * Toolkit::Control would have done the same with Actor.
53    *
54    * The end index for this control is set to the start index + 1000 hence MyControl can have 1000 property indexes.
55    *
56    * PROPERTY_END_INDEX for MyControl is public, if another control is derived from it then if can specify MyControl::PROPERTY_END_INDEX+1 to start it's
57    * indexing after MyControls last index.
58    */
59   enum PropertyRange
60   {
61     PROPERTY_START_INDEX = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1,
62     PROPERTY_END_INDEX   = PROPERTY_START_INDEX + 1000,
63     ANIMATABLE_PROPERTY_START_INDEX = Dali::ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,
64     ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_START_INDEX+1000
65   };
66
67   struct Property
68   {
69     enum
70     {
71       /**
72        * @brief name "iconVisual", type string if it is a url, map otherwise
73        * @details Sets the icon visual to be displayed by the control
74        */
75       ICON_VISUAL = PROPERTY_START_INDEX
76     };
77   };
78
79 public: // Construction / destruction
80
81   /**
82    * @brief Create an uninitialized handle
83    */
84   MyControl();
85
86   /**
87    * @brief Create a new MyControl
88    */
89   static MyControl New();
90
91   /**
92    * @brief Destructor. This is non-virtual since derived Handle types must not contain data or virtual methods
93    */
94   ~MyControl();
95
96   /**
97    * @brief Copy Constructor
98    *
99    * @param[in] shadowButton the handle of the control to copy
100    */
101   MyControl( const MyControl& shadowButton );
102
103   /**
104    * @brief Assignment Operator
105    *
106    * @param[in] shadowButton the source of the assignment
107    */
108   MyControl& operator=( const MyControl& shadowButton );
109
110   /**
111    * @brief Downcast
112    *
113    * @param[in] shadowButton the handle of control to downcast to MyControl
114    */
115   static MyControl DownCast( BaseHandle handle );
116
117
118 public: //  // Not intended for application developers
119
120   /// @cond internal
121   /**
122    * @brief Create a handle from an implementation
123    */
124   MyControl( Internal::MyControl& implementation );
125
126   /**
127    * @brief Allow the creation of an ShadowButton handle from an internal CustomActor pointer
128    */
129   MyControl( Dali::Internal::CustomActor* internal );
130   /// @endcond
131 };
132
133 } // namespace Demo
134
135 #endif // DALI_DEMO_MY_CONTROL_H