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 * It's not mandatory to 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 * | stateChanged | @ref StateChangedSignal() |
80 * | %Action Name | Attributes | Description |
81 * |------------------|-------------------------|-----------------------------------------------|
82 * | buttonClick | Doesn't have attributes | Simulates a button click. See @ref DoAction() |
85 class DALI_IMPORT_API Button : public Control
90 * @brief Enumeration for the start and end property ranges for this control.
95 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
96 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices @SINCE_1_0.0
100 * @brief Enumeration for the instance of properties belonging to the Button class.
106 * @brief Enumeration for the instance of properties belonging to the Button class.
111 DISABLED = PROPERTY_START_INDEX, ///< name "disabled", @see SetDisabled(), type bool @SINCE_1_0.0
112 AUTO_REPEATING, ///< name "autoRepeating", @see SetAutoRepeating(), type bool @SINCE_1_0.0
113 INITIAL_AUTO_REPEATING_DELAY, ///< name "initialAutoRepeatingDelay", @see SetInitialAutoRepeatingDelay(), type float @SINCE_1_0.0
114 NEXT_AUTO_REPEATING_DELAY, ///< name "nextAutoRepeatingDelay", @see SetNextAutoRepeatingDelay(), type float @SINCE_1_0.0
115 TOGGLABLE, ///< name "togglable", @see SetTogglableButton(), type bool @SINCE_1_0.0
116 SELECTED, ///< name "selected", @see SetSelected(), type bool @SINCE_1_0.0
117 UNSELECTED_STATE_IMAGE, ///< name "unselectedStateImage", @see SetUnselectedImage(), type std::string @SINCE_1_0.0
118 SELECTED_STATE_IMAGE, ///< name "selectedStateImage", @see SetSelectedImage(), type std::string @SINCE_1_0.0
119 DISABLED_STATE_IMAGE, ///< name "disabledStateImage", @see SetDisabledImage(), type std::string @SINCE_1_0.0
120 UNSELECTED_COLOR, ///< name "unselectedColor", type Vector4 @SINCE_1_0.0
121 SELECTED_COLOR, ///< name "selectedColor", type Vector4 @SINCE_1_0.0
122 LABEL, ///< name "label", type Property::Map @SINCE_1_0.0
124 // Deprecated properties:
125 LABEL_TEXT, ///< name "labelText", @see SetLabelText(), type std::string @SINCE_1_0.0
132 * @brief Creates an uninitialized Button.
134 * Only derived versions can be instantiated. Calling member
135 * functions with an uninitialized Dali::Object is not allowed.
141 * @brief Copy constructor.
143 * @param[in] button Handle to an object
145 Button( const Button& button );
148 * @brief Assignment operator.
150 * @param[in] button Handle to an object
151 * @return A reference to this
153 Button& operator=( const Button& button );
156 * @brief Downcasts a handle to Button handle.
158 * If handle points to a Button, the downcast produces valid handle.
159 * If not the returned handle is left uninitialized.
162 * @param[in] handle Handle to an object
163 * @return A handle to a Button or an uninitialized handle
165 static Button DownCast( BaseHandle handle );
170 * This is non-virtual since derived Handle types must not contain data or virtual methods.
178 * @DEPRECATED_1_1.32 Use SetProperty DISABLED or Styling file
180 * @brief Sets the button as \e disabled.
182 * No signals are emitted when the \e disabled property is set.
185 * @param[in] disabled Disabled property
187 void SetDisabled( bool disabled ) DALI_DEPRECATED_API;
190 * @DEPRECATED_1_1.32 Use GetProperty DISABLED
192 * @brief Returns if the button is disabled.
194 * @return \e true if the button is \e disabled
196 bool IsDisabled() const DALI_DEPRECATED_API;
199 * @DEPRECATED_1_1.32 SetProperty AUTO_REPEATING or Styling file
201 * @brief Sets the \e autorepeating property.
203 * If the \e autorepeating property is set to \e true, then the \e togglable property is set to false
204 * but no signal is emitted.
207 * @param[in] autoRepeating \e autorepeating property
209 void SetAutoRepeating( bool autoRepeating ) DALI_DEPRECATED_API;
212 * @DEPRECATED_1_1.32 GetProperty AUTO_REPEATING
214 * @brief Returns if the autorepeating property is set.
216 * @return \e true if the \e autorepeating property is set
218 bool IsAutoRepeating() const DALI_DEPRECATED_API;
221 * @DEPRECATED_1_1.32 SetProperty INITIAL_AUTO_REPEATING_DELAY or Styling file
223 * @brief Sets the initial autorepeating delay.
225 * By default, this value is set to 0.15 seconds.
228 * @param[in] initialAutoRepeatingDelay in seconds
229 * @pre initialAutoRepeatingDelay must be greater than zero.
231 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay ) DALI_DEPRECATED_API;
234 * @DEPRECATED_1_1.32 GetProperty INITIAL_AUTO_REPEATING_DELAY
236 * @brief Gets the initial autorepeating delay in seconds.
238 * @return The initial autorepeating delay in seconds
240 float GetInitialAutoRepeatingDelay() const DALI_DEPRECATED_API;
243 * @DEPRECATED_1_1.32 SetProperty NEXT_AUTO_REPEATING_DELAY or Styling file
245 * @brief Sets the next autorepeating delay.
247 * By default, this value is set to 0.05 seconds.
250 * @param[in] nextAutoRepeatingDelay in seconds
251 * @pre nextAutoRepeatingDelay must be greater than zero.
253 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay ) DALI_DEPRECATED_API;
256 * @DEPRECATED_1_1.32 GetProperty NEXT_AUTO_REPEATING_DELAY
258 * @brief Gets the next autorepeating delay in seconds.
260 * @return The next autorepeating delay in seconds
262 float GetNextAutoRepeatingDelay() const DALI_DEPRECATED_API;
265 * @DEPRECATED_1_1.32 SetProperty TOGGLABLE or Styling file
267 * @brief Sets the \e togglable property.
269 * If the \e togglable property is set to \e true, then the \e autorepeating property is set to false.
272 * @param[in] togglable Togglable property
274 void SetTogglableButton( bool togglable ) DALI_DEPRECATED_API;
277 * @DEPRECATED_1_1.32 GetProperty TOGGLABLE
279 * @brief Returns if the togglable property is set.
281 * @return \e true if the \e togglable property is set
283 bool IsTogglableButton() const DALI_DEPRECATED_API;
286 * @DEPRECATED_1_1.32 SetProperty SELECTED
288 * @brief Sets the button as selected or unselected.
290 * \e togglable property must be set to \e true.
292 * Emits a Button::StateChangedSignal() signal.
295 * @param[in] selected Selected property
297 void SetSelected( bool selected ) DALI_DEPRECATED_API;
300 * DEPRECATED_1_1.32 GetProperty SELECTED
302 * @brief Returns if the selected property is set and the button is togglable.
304 * @return \e true if the button is \e selected
306 bool IsSelected() const DALI_DEPRECATED_API;
309 * @DEPRECATED_1_1.32 Use Styling file to set animation
311 * @brief Sets the animation time.
314 * @param[in] animationTime The animation time in seconds
316 void SetAnimationTime( float animationTime ) DALI_DEPRECATED_API;
319 * DEPRECATED_1_1.32 Use Styling file to set animation
321 * @brief Retrieves button's animation time.
324 * @return The animation time in seconds
326 float GetAnimationTime() const DALI_DEPRECATED_API;
329 * @brief Sets the button's label.
332 * @param[in] label The label text
334 void SetLabelText( const std::string& label ) DALI_DEPRECATED_API;
337 * DEPRECATED_1_1.32 GetProperty LABEL
339 * @brief Gets the label.
342 * @return The label text
344 std::string GetLabelText() const DALI_DEPRECATED_API;
347 * @DEPRECATED_1_1.32 Use Styling file
349 * @brief Sets the unselected button image.
352 * @param[in] filename The button image
354 void SetUnselectedImage( const std::string& filename ) DALI_DEPRECATED_API;
357 * @DEPRECATED_1_1.32 Use styling
359 * @brief Sets the background image.
362 * @param[in] filename The background image
364 void SetBackgroundImage( const std::string& filename ) DALI_DEPRECATED_API;
367 * @DEPRECATED_1_1.32 Use styling file
369 * @brief Sets the selected image.
372 * @param[in] filename The selected image
374 void SetSelectedImage( const std::string& filename ) DALI_DEPRECATED_API;
377 * @DEPRECATED_1_1.32 Use styling file
379 * @brief Sets the selected background image.
382 * @param[in] filename The selected background image
384 void SetSelectedBackgroundImage( const std::string& filename ) DALI_DEPRECATED_API;
387 * @DEPRECATED_1_1.32 Use styling file
389 * @brief Sets the disabled background image.
392 * @param[in] filename The disabled background image
394 void SetDisabledBackgroundImage( const std::string& filename ) DALI_DEPRECATED_API;
397 * @DEPRECATED_1_1.32 Use styling file
399 * @brief Sets the disabled button image.
402 * @param[in] filename The disabled button image
404 void SetDisabledImage( const std::string& filename ) DALI_DEPRECATED_API;
407 * @DEPRECATED_1_1.32 Use styling file
409 * @brief Sets the disabled selected button image.
412 * @param[in] filename The disabled selected button image
414 void SetDisabledSelectedImage( const std::string& filename ) DALI_DEPRECATED_API;
417 * @DEPRECATED_1_0.50. Instead, use SetLabelText
419 * @brief Sets the label with an actor.
422 * @param[in] label The actor to use as a label
424 void SetLabel( Actor label ) DALI_DEPRECATED_API;
427 * @DEPRECATED_1_0.50. Instead, use SetUnselectedImage.
429 * @brief Sets the button image.
432 * @param[in] image The button image
434 void SetButtonImage( Image image ) DALI_DEPRECATED_API;
437 * @DEPRECATED_1_0.50. Instead, use SetSelectedImage( const std::string& filename ).
439 * @brief Sets the selected image.
442 * @param[in] image The selected image
444 void SetSelectedImage( Image image ) DALI_DEPRECATED_API;
449 * @brief Gets the button image.
452 * @remarks Avoid using this method as it's a legacy code.
453 * @return An actor with the button image
455 Actor GetButtonImage() const DALI_DEPRECATED_API;
460 * @brief Gets the selected image.
463 * @remarks Avoid using this method as it's a legacy code.
464 * @return An actor with the selected image
466 Actor GetSelectedImage() const DALI_DEPRECATED_API;
471 * @brief Button signal type.
474 typedef Signal< bool ( Button ) > ButtonSignalType;
477 * @brief This signal is emitted when the button is touched.
479 * A callback of the following type may be connected:
481 * bool YourCallbackName( Button button );
484 * @return The signal to connect to
486 ButtonSignalType& PressedSignal();
489 * @brief This signal is emitted when the button is touched and the touch point leaves the boundary of the button.
491 * A callback of the following type may be connected:
493 * bool YourCallbackName( Button button );
496 * @return The signal to connect to
498 ButtonSignalType& ReleasedSignal();
501 * @brief This signal is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
503 * A callback of the following type may be connected:
505 * bool YourCallbackName( Button button );
508 * @return The signal to connect to
510 ButtonSignalType& ClickedSignal();
513 * @brief This signal is emitted when the button's state is changed.
515 * The application can get the state by calling IsSelected().
517 * A callback of the following type may be connected:
519 * bool YourCallbackName( Button button );
522 * @return The signal to connect to
524 ButtonSignalType& StateChangedSignal();
526 public: // Not intended for application developers
530 * @brief Creates a handle using the Toolkit::Internal implementation.
533 * @param[in] implementation The Control implementation
535 DALI_INTERNAL Button( Internal::Button& implementation );
539 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
542 * @param[in] internal A pointer to the internal CustomActor
544 DALI_INTERNAL Button( Dali::Internal::CustomActor* internal );
550 } // namespace Toolkit
554 #endif // __DALI_TOOLKIT_BUTTON_H__