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.
46 * | %Signal Name | Method |
47 * |-------------------|-----------------------------|
48 * | pressed | @ref PressedSignal() |
49 * | released | @ref ReleasedSignal() |
50 * | clicked | @ref ClickedSignal() |
51 * | state-changed | @ref StateChangedSignal() |
54 * | %Action Name | %Button method called |
55 * |-------------------|-----------------------------|
56 * | button-click | %DoClickAction() |
58 class DALI_IMPORT_API Button : public Control
63 * @brief The start and end property ranges for this control.
67 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
68 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices
72 * @brief An enumeration of properties belonging to the Button class.
78 DISABLED = PROPERTY_START_INDEX, ///< name "disabled", @see SetDisabled(), type bool
79 AUTO_REPEATING, ///< name "auto-repeating", @see SetAutoRepeating(), type bool
80 INITIAL_AUTO_REPEATING_DELAY, ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type float
81 NEXT_AUTO_REPEATING_DELAY, ///< name "next-auto-repeating-delay", @see SetNextAutoRepeatingDelay(), type float
82 TOGGLABLE, ///< name "togglable", @see SetTogglableButton(), type bool
83 SELECTED, ///< name "selected", @see SetSelected(), type bool
84 NORMAL_STATE_ACTOR, ///< name "normal-state-actor", @see SetButtonImage(), type Map
85 SELECTED_STATE_ACTOR, ///< name "selected-state-actor", @see SetSelectedImage(), type Map
86 DISABLED_STATE_ACTOR, ///< name "disabled-state-actor", @see SetDisabledImage(), type Map
87 LABEL_ACTOR, ///< name "label-actor", @see SetLabel(), type Map
94 * @brief Create an uninitialized Button.
96 * Only derived versions can be instantiated. Calling member
97 * functions with an uninitialized Dali::Object is not allowed.
102 * @brief Copy constructor.
104 Button( const Button& button );
107 * @brief Assignment operator.
109 Button& operator=( const Button& button );
112 * @brief Downcast an Object handle to Button.
114 * If handle points to a Button the downcast produces valid
115 * handle. If not the returned handle is left uninitialized.
117 * @param[in] handle Handle to an object
118 * @return handle to a Button or an uninitialized handle
120 static Button DownCast( BaseHandle handle );
125 * This is non-virtual since derived Handle types must not contain data or virtual methods.
130 * @brief Sets the button as \e disabled.
132 * No signals are emitted when the \e disabled property is set.
134 * @param[in] disabled property.
136 void SetDisabled( bool disabled );
139 * @return \e true if the button is \e disabled.
141 bool IsDisabled() const;
144 * @brief Sets the \e autorepeating property.
146 * If the \e autorepeating property is set to \e true, then the \e togglable property is set to false
147 * but no signal is emitted.
149 * @param[in] autoRepeating \e autorepeating property.
151 void SetAutoRepeating( bool autoRepeating );
154 * @return \e true if the \e autorepeating property is set.
156 bool IsAutoRepeating() const;
159 * @brief Sets the initial autorepeating delay.
161 * By default this value is set to 0.15 seconds.
163 * @pre initialAutoRepeatingDelay must be greater than zero.
164 * @param[in] initialAutoRepeatingDelay in seconds.
166 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
169 * @return the initial autorepeating delay in seconds.
171 float GetInitialAutoRepeatingDelay() const;
174 * @brief Sets the next autorepeating delay.
176 * By default this value is set to 0.05 seconds.
178 * @pre nextAutoRepeatingDelay must be greater than zero.
179 * @param[in] nextAutoRepeatingDelay in seconds.
181 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
184 * @return the next autorepeating delay in seconds.
186 float GetNextAutoRepeatingDelay() const;
189 * @brief Sets the \e togglable property.
191 * If the \e togglable property is set to \e true, then the \e autorepeating property is set to false.
193 * @param[in] togglable property.
195 void SetTogglableButton( bool togglable );
198 * @return \e true if the \e togglable property is set.
200 bool IsTogglableButton() const;
203 * Sets the button as selected or unselected.
205 * \e togglable property must be set to \e true.
207 * Emits a Button::StateChangedSignal() signal.
209 * @param[in] selected property.
211 void SetSelected( bool selected );
214 * @return \e true if the \e selected property is set and the button is togglable.
216 bool IsSelected() const;
219 * @brief Sets the animation time.
221 * @param [in] animationTime The animation time in seconds.
223 void SetAnimationTime( float animationTime );
226 * @brief Retrieves button's animation time.
228 * @return The animation time in seconds.
230 float GetAnimationTime() const;
233 * @brief Sets the button label.
235 * @param[in] label The button label.
237 void SetLabel( const std::string& label );
240 * @copydoc SetLabel( const std::string& label )
242 void SetLabel( Actor label );
245 * @brief Gets the label.
247 * @return An actor with the label.
249 Actor GetLabel() const;
254 * @brief Button signal type
256 typedef Signal< bool ( Button ) > ButtonSignalType;
259 * @brief This signal is emitted when the button is touched.
261 * A callback of the following type may be connected:
263 * bool YourCallbackName( Button button );
265 * @return The signal to connect to.
267 ButtonSignalType& PressedSignal();
270 * @brief This signal is emitted when the button is touched and the touch point leaves the boundary of the button.
272 * A callback of the following type may be connected:
274 * bool YourCallbackName( Button button );
276 * @return The signal to connect to.
278 ButtonSignalType& ReleasedSignal();
281 * @brief This signal is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
283 * A callback of the following type may be connected:
285 * bool YourCallbackName( Button button );
287 * @return The signal to connect to.
289 ButtonSignalType& ClickedSignal();
292 * @brief This signal is emitted when the button's state is changed.
293 * The application can get the state by calling IsSelected().
295 * A callback of the following type may be connected:
297 * bool YourCallbackName( Button button );
299 * @return The signal to connect to.
301 ButtonSignalType& StateChangedSignal();
303 public: // Not intended for application developers
306 * @brief Creates a handle using the Toolkit::Internal implementation.
308 * @param[in] implementation The Control implementation.
310 DALI_INTERNAL Button( Internal::Button& implementation );
313 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
315 * @param[in] internal A pointer to the internal CustomActor.
317 DALI_INTERNAL Button( Dali::Internal::CustomActor* internal );
320 } // namespace Toolkit
324 #endif // __DALI_TOOLKIT_BUTTON_H__