1 #ifndef __DALI_TOOLKIT_BUTTON_H__
2 #define __DALI_TOOLKIT_BUTTON_H__
5 * Copyright (c) 2015 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
35 * @addtogroup dali_toolkit_controls_buttons
40 * @brief Button is a base class for different kind of buttons.
42 * This class provides the disabled property and the clicked signal.
44 * A ClickedSignal() is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
46 * When the \e disabled property is set to \e true, no signal is emitted.
48 * Button provides the following properties which modify the signals emitted:
50 * <li>\e autorepeating
51 * When \e autorepeating is set to \e true, a Button::PressedSignal(), Button::ReleasedSignal() and Button::ClickedSignal() signals are emitted at regular
52 * intervals while the button is touched.
53 * The intervals could be modified with the Button::SetInitialAutoRepeatingDelay and Button::SetNextAutoRepeatingDelay methods.
55 * A \e togglable button can't be \e autorepeating. If the \e autorepeating property is set to \e true, then the \e togglable property is set to
56 * false but no signal is emitted.
59 * When \e togglable is set to \e true, a Button::StateChangedSignal() signal is emitted, with the selected state.
62 * The button's appearance can be modified by setting properties for the various image filenames.
64 * The \e background is always shown and doesn't change if the button is pressed or released. The \e button image is shown over the \e background image when the
65 * button is not pressed and is replaced by the \e selected image when the button is pressed. The text label is placed always on the top of all images.
67 * When the button is disabled, \e background, \e button and \e selected images are replaced by their \e disabled images.
69 * Is not mandatory set all images. A button could be defined only by setting its \e background image or by setting its \e background and \e selected images.
72 * | %Signal Name | Method |
73 * |-------------------|-----------------------------|
74 * | pressed | @ref PressedSignal() |
75 * | released | @ref ReleasedSignal() |
76 * | clicked | @ref ClickedSignal() |
77 * | state-changed | @ref StateChangedSignal() |
80 * | %Action Name | %Button method called |
81 * |-------------------|-----------------------------|
82 * | button-click | %DoClickAction() |
84 class DALI_IMPORT_API Button : public Control
89 * @brief The start and end property ranges for this control.
93 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
94 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices
98 * @brief An enumeration of properties belonging to the Button class.
104 DISABLED = PROPERTY_START_INDEX, ///< name "disabled", @see SetDisabled(), type bool
105 AUTO_REPEATING, ///< name "auto-repeating", @see SetAutoRepeating(), type bool
106 INITIAL_AUTO_REPEATING_DELAY, ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type float
107 NEXT_AUTO_REPEATING_DELAY, ///< name "next-auto-repeating-delay", @see SetNextAutoRepeatingDelay(), type float
108 TOGGLABLE, ///< name "togglable", @see SetTogglableButton(), type bool
109 SELECTED, ///< name "selected", @see SetSelected(), type bool
110 UNSELECTED_STATE_IMAGE, ///< name "unselected-state-image", @see SetUnselectedImage(), type std::string
111 SELECTED_STATE_IMAGE, ///< name "selected-state-image", @see SetSelectedImage(), type std::string
112 DISABLED_STATE_IMAGE, ///< name "disabled-state-image", @see SetDisabledImage(), type std::string
113 UNSELECTED_COLOR, ///< name "unselected-color", type Vector4
114 SELECTED_COLOR, ///< name "selected-color", type Vector4
115 LABEL, ///< name "label", type Property::Map
117 // Deprecated properties:
118 LABEL_TEXT, ///< name "label-text", @see SetLabelText(), type std::string
125 * @brief Create an uninitialized Button.
127 * Only derived versions can be instantiated. Calling member
128 * functions with an uninitialized Dali::Object is not allowed.
133 * @brief Copy constructor.
135 Button( const Button& button );
138 * @brief Assignment operator.
140 Button& operator=( const Button& button );
143 * @brief Downcast an Object handle to Button.
145 * If handle points to a Button the downcast produces valid
146 * handle. If not the returned handle is left uninitialized.
148 * @param[in] handle Handle to an object
149 * @return handle to a Button or an uninitialized handle
151 static Button DownCast( BaseHandle handle );
156 * This is non-virtual since derived Handle types must not contain data or virtual methods.
161 * @brief Sets the button as \e disabled.
163 * No signals are emitted when the \e disabled property is set.
165 * @param[in] disabled property.
167 void SetDisabled( bool disabled );
170 * @return \e true if the button is \e disabled.
172 bool IsDisabled() const;
175 * @brief Sets the \e autorepeating property.
177 * If the \e autorepeating property is set to \e true, then the \e togglable property is set to false
178 * but no signal is emitted.
180 * @param[in] autoRepeating \e autorepeating property.
182 void SetAutoRepeating( bool autoRepeating );
185 * @return \e true if the \e autorepeating property is set.
187 bool IsAutoRepeating() const;
190 * @brief Sets the initial autorepeating delay.
192 * By default this value is set to 0.15 seconds.
194 * @pre initialAutoRepeatingDelay must be greater than zero.
195 * @param[in] initialAutoRepeatingDelay in seconds.
197 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
200 * @return the initial autorepeating delay in seconds.
202 float GetInitialAutoRepeatingDelay() const;
205 * @brief Sets the next autorepeating delay.
207 * By default this value is set to 0.05 seconds.
209 * @pre nextAutoRepeatingDelay must be greater than zero.
210 * @param[in] nextAutoRepeatingDelay in seconds.
212 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
215 * @return the next autorepeating delay in seconds.
217 float GetNextAutoRepeatingDelay() const;
220 * @brief Sets the \e togglable property.
222 * If the \e togglable property is set to \e true, then the \e autorepeating property is set to false.
224 * @param[in] togglable property.
226 void SetTogglableButton( bool togglable );
229 * @return \e true if the \e togglable property is set.
231 bool IsTogglableButton() const;
234 * Sets the button as selected or unselected.
236 * \e togglable property must be set to \e true.
238 * Emits a Button::StateChangedSignal() signal.
240 * @param[in] selected property.
242 void SetSelected( bool selected );
245 * @return \e true if the \e selected property is set and the button is togglable.
247 bool IsSelected() const;
250 * @brief Sets the animation time.
252 * @param[in] animationTime The animation time in seconds.
254 void SetAnimationTime( float animationTime );
257 * @brief Retrieves button's animation time.
259 * @return The animation time in seconds.
261 float GetAnimationTime() const;
264 * @brief Sets the button's label.
266 * @param[in] label The label text.
268 void SetLabelText( const std::string& label );
271 * @brief Gets the label.
273 * @return The label text.
275 std::string GetLabelText() const;
278 * @brief Sets the unselected button image.
280 * @param[in] filename The button image.
282 void SetUnselectedImage( const std::string& filename );
285 * @brief Sets the background image.
287 * @param[in] filename The background image.
289 void SetBackgroundImage( const std::string& filename );
292 * @brief Sets the selected image.
294 * @param[in] filename The selected image.
296 void SetSelectedImage( const std::string& filename );
299 * @brief Sets the selected background image.
301 * @param[in] filename The selected background image.
303 void SetSelectedBackgroundImage( const std::string& filename );
306 * @brief Sets the disabled background image.
308 * @param[in] filename The disabled background image.
310 void SetDisabledBackgroundImage( const std::string& filename );
313 * @brief Sets the disabled button image.
315 * @param[in] filename The disabled button image.
317 void SetDisabledImage( const std::string& filename );
320 * @brief Sets the disabled selected button image.
322 * @param[in] filename The disabled selected button image.
324 void SetDisabledSelectedImage( const std::string& filename );
329 * @deprecated DALi 1.0.50
331 * @brief Sets the label with an actor.
333 * @param[in] label The actor to use as a label
335 void SetLabel( Actor label );
338 * @deprecated DALi 1.0.50
340 * @brief Sets the button image.
342 * @param[in] image The button image.
344 void SetButtonImage( Image image );
347 * @deprecated DALi 1.0.50
349 * @brief Sets the selected image.
351 * @param[in] image The selected image.
353 void SetSelectedImage( Image image );
356 * @deprecated DALi 1.0.50
358 * @brief Gets the button image.
360 * @return An actor with the button image.
362 Actor GetButtonImage() const;
365 * @deprecated DALi 1.0.50
367 * @brief Gets the selected image.
369 * @return An actor with the selected image.
371 Actor GetSelectedImage() const;
376 * @brief Button signal type
378 typedef Signal< bool ( Button ) > ButtonSignalType;
381 * @brief This signal is emitted when the button is touched.
383 * A callback of the following type may be connected:
385 * bool YourCallbackName( Button button );
387 * @return The signal to connect to.
389 ButtonSignalType& PressedSignal();
392 * @brief This signal is emitted when the button is touched and the touch point leaves the boundary of the button.
394 * A callback of the following type may be connected:
396 * bool YourCallbackName( Button button );
398 * @return The signal to connect to.
400 ButtonSignalType& ReleasedSignal();
403 * @brief This signal is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
405 * A callback of the following type may be connected:
407 * bool YourCallbackName( Button button );
409 * @return The signal to connect to.
411 ButtonSignalType& ClickedSignal();
414 * @brief This signal is emitted when the button's state is changed.
415 * The application can get the state by calling IsSelected().
417 * A callback of the following type may be connected:
419 * bool YourCallbackName( Button button );
421 * @return The signal to connect to.
423 ButtonSignalType& StateChangedSignal();
425 public: // Not intended for application developers
428 * @brief Creates a handle using the Toolkit::Internal implementation.
430 * @param[in] implementation The Control implementation.
432 DALI_INTERNAL Button( Internal::Button& implementation );
435 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
437 * @param[in] internal A pointer to the internal CustomActor.
439 DALI_INTERNAL Button( Dali::Internal::CustomActor* internal );
445 } // namespace Toolkit
449 #endif // __DALI_TOOLKIT_BUTTON_H__