1 #ifndef __DALI_TOOLKIT_BUTTON_H__
2 #define __DALI_TOOLKIT_BUTTON_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.h>
30 namespace Internal DALI_INTERNAL
36 * @brief Button is a base class for different kind of buttons.
38 * This class provides the disabled property and the clicked signal.
40 * A ClickedSignal() is emitted when the button is touched and the touch
41 * point doesn't leave the boundary of the button.
43 * When the \e disabled property is set to \e true, no signal is emitted.
45 class DALI_IMPORT_API Button : public Control
50 static const char* const SIGNAL_PRESSED; ///< name "pressed"
51 static const char* const SIGNAL_RELEASED; ///< name "released"
52 static const char* const SIGNAL_CLICKED; ///< name "clicked"
53 static const char* const SIGNAL_STATE_CHANGED; ///< name "state-changed"
56 static const char* const ACTION_BUTTON_CLICK; ///< name "button-click"
59 static const Property::Index PROPERTY_DISABLED; ///< name "disabled", @see SetDisabled(), type BOOLEAN
60 static const Property::Index PROPERTY_AUTO_REPEATING; ///< name "auto-repeating", @see SetAutoRepeating(), type BOOLEAN
61 static const Property::Index PROPERTY_INITIAL_AUTO_REPEATING_DELAY; ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type FLOAT
62 static const Property::Index PROPERTY_NEXT_AUTO_REPEATING_DELAY; ///< name "next-auto-repeating-delay", @see SetNextAutoRepeatingDelay(), type FLOAT
63 static const Property::Index PROPERTY_TOGGLABLE; ///< name "togglable", @see SetTogglableButton(), type BOOLEAN
64 static const Property::Index PROPERTY_SELECTED; ///< name "selected", @see SetSelected(), type BOOLEAN
65 static const Property::Index PROPERTY_NORMAL_STATE_ACTOR; ///< name "normal-state-actor", @see SetButtonImage(), type MAP
66 static const Property::Index PROPERTY_SELECTED_STATE_ACTOR; ///< name "selected-state-actor", @see SetSelectedImage(), type MAP
67 static const Property::Index PROPERTY_DISABLED_STATE_ACTOR; ///< name "disabled-state-actor", @see SetDisabledImage(), type MAP
68 static const Property::Index PROPERTY_LABEL_ACTOR; ///< name "label-actor", @see SetLabel(), type MAP
73 * @brief Create an uninitialized Button.
75 * Only derived versions can be instantiated. Calling member
76 * functions with an uninitialized Dali::Object is not allowed.
81 * @brief Copy constructor.
83 Button( const Button& button );
86 * @brief Assignment operator.
88 Button& operator=( const Button& button );
91 * @brief Downcast an Object handle to Button.
93 * If handle points to a Button the downcast produces valid
94 * handle. If not the returned handle is left uninitialized.
96 * @param[in] handle Handle to an object
97 * @return handle to a Button or an uninitialized handle
99 static Button DownCast( BaseHandle handle );
104 * This is non-virtual since derived Handle types must not contain data or virtual methods.
109 * @brief Sets the button as \e disabled.
111 * No signals are emitted when the \e disabled property is set.
113 * @param[in] disabled property.
115 void SetDisabled( bool disabled );
118 * @return \e true if the button is \e disabled.
120 bool IsDisabled() const;
123 * @brief Sets the \e autorepeating property.
125 * If the \e autorepeating property is set to \e true, then the \e togglable property is set to false
126 * but no signal is emitted.
128 * @param[in] autoRepeating \e autorepeating property.
130 void SetAutoRepeating( bool autoRepeating );
133 * @return \e true if the \e autorepeating property is set.
135 bool IsAutoRepeating() const;
138 * @brief Sets the initial autorepeating delay.
140 * By default this value is set to 0.15 seconds.
142 * @pre initialAutoRepeatingDelay must be greater than zero.
143 * @param[in] initialAutoRepeatingDelay in seconds.
145 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
148 * @return the initial autorepeating delay in seconds.
150 float GetInitialAutoRepeatingDelay() const;
153 * @brief Sets the next autorepeating delay.
155 * By default this value is set to 0.05 seconds.
157 * @pre nextAutoRepeatingDelay must be greater than zero.
158 * @param[in] nextAutoRepeatingDelay in seconds.
160 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
163 * @return the next autorepeating delay in seconds.
165 float GetNextAutoRepeatingDelay() const;
168 * @brief Sets the \e togglable property.
170 * If the \e togglable property is set to \e true, then the \e autorepeating property is set to false.
172 * @param[in] togglable property.
174 void SetTogglableButton( bool togglable );
177 * @return \e true if the \e togglable property is set.
179 bool IsTogglableButton() const;
182 * Sets the button as selected or unselected.
184 * \e togglable property must be set to \e true.
186 * Emits a Button::StateChangedSignal() signal.
188 * @param[in] selected property.
190 void SetSelected( bool selected );
193 * @return \e true if the \e selected property is set and the button is togglable.
195 bool IsSelected() const;
198 * @brief Sets the animation time.
200 * @param [in] animationTime The animation time in seconds.
202 void SetAnimationTime( float animationTime );
205 * @brief Retrieves button's animation time.
207 * @return The animation time in seconds.
209 float GetAnimationTime() const;
212 * @brief Sets the button label.
214 * @param[in] label The button label.
216 void SetLabel( const std::string& label );
219 * @copydoc SetLabel( const std::string& label )
221 void SetLabel( Actor label );
224 * @brief Gets the label.
226 * @return An actor with the label.
228 Actor GetLabel() const;
233 * @brief Button signal type
235 typedef Signal< bool ( Button ) > ButtonSignalType;
238 * @brief This signal is emitted when the button is touched.
240 * A callback of the following type may be connected:
242 * bool YourCallbackName( Button button );
244 * @return The signal to connect to.
246 ButtonSignalType& PressedSignal();
249 * @brief This signal is emitted when the button is touched and the touch point leaves the boundary of the button.
251 * A callback of the following type may be connected:
253 * bool YourCallbackName( Button button );
255 * @return The signal to connect to.
257 ButtonSignalType& ReleasedSignal();
260 * @brief This signal is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
262 * A callback of the following type may be connected:
264 * bool YourCallbackName( Button button );
266 * @return The signal to connect to.
268 ButtonSignalType& ClickedSignal();
271 * @brief This signal is emitted when the button's state is changed.
272 * The application can get the state by calling IsSelected().
274 * A callback of the following type may be connected:
276 * bool YourCallbackName( Button button );
278 * @return The signal to connect to.
280 ButtonSignalType& StateChangedSignal();
282 public: // Not intended for application developers
285 * @brief Creates a handle using the Toolkit::Internal implementation.
287 * @param[in] implementation The Control implementation.
289 DALI_INTERNAL Button( Internal::Button& implementation );
292 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
294 * @param[in] internal A pointer to the internal CustomActor.
296 DALI_INTERNAL Button( Dali::Internal::CustomActor* internal );
299 } // namespace Toolkit
303 #endif // __DALI_TOOLKIT_BUTTON_H__