1 #ifndef DALI_TOOLKIT_BUTTON_H
2 #define DALI_TOOLKIT_BUTTON_H
5 * Copyright (c) 2019 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 kinds 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 * 'Visual' describes not just traditional images like png, bmp but refers to whatever is used to show the button, it could be a color, gradient or some other kind of renderer.
64 * The button's appearance can be modified by setting properties for the various visuals/images.
66 * It is not mandatory to set all visuals. A button could be defined only by setting its \e background visual or by setting its \e background and \e selected visuals.
68 * The \e button visual is shown over the \e background visual.
69 * When pressed the unselected visuals are replaced by the \e selected visual. The text label is always placed on the top of all images.
71 * When the button is disabled, \e background, \e button and \e selected visuals are replaced by their \e disabled visuals.
75 * | %Signal Name | Method |
76 * |------------------|-----------------------------|
77 * | pressed | @ref PressedSignal() |
78 * | released | @ref ReleasedSignal() |
79 * | clicked | @ref ClickedSignal() |
80 * | stateChanged | @ref StateChangedSignal() |
83 * | %Action Name | Attributes | Description |
84 * |------------------|-------------------------|-----------------------------------------------|
85 * | buttonClick | Doesn't have attributes | Simulates a button click. See @ref DoAction() |
88 class DALI_TOOLKIT_API Button : public Control
93 * @brief Enumeration for the start and end property ranges for this control.
98 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
99 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices @SINCE_1_0.0
103 * @brief Enumeration for the instance of properties belonging to the Button class.
109 * @brief Enumeration for the instance of properties belonging to the Button class.
115 * @brief name "disabled", type bool
116 * @details Sets the button as \e disabled.
119 DISABLED = PROPERTY_START_INDEX,
122 * @brief name "autoRepeating", type bool
123 * @details If the \e autorepeating property is set to \e true then the \e togglable property is set to false
129 * @brief name "initialAutoRepeatingDelay", type float
130 * @details By default this value is set to 0.15 seconds.
133 INITIAL_AUTO_REPEATING_DELAY,
136 * @brief name "nextAutoRepeatingDelay", type float
137 * @details default this value is set to 0.05 seconds
140 NEXT_AUTO_REPEATING_DELAY,
143 * @brief name "togglable", type bool
144 * @details If the \e togglable property is set to \e true, then the \e autorepeating property is set to false.
150 * @brief name "selected", type bool
151 * @details Sets the togglable button as either selected or unselected, \e togglable property must be set to \e true.
157 * @brief name "unselectedVisual", type string if it is a url, map otherwise.
158 * @details Sets the unselected button foreground/icon visual
164 * @brief name "selectedImage", type string if it is a url, map otherwise
165 * @details Sets the selected button foreground/icon visual
171 * @brief name "disabledSelectedVisual", type string if it is a url, map otherwise
172 * @details Sets the disabled selected state foreground/icon button visual
175 DISABLED_SELECTED_VISUAL,
178 * @brief name "disabledUnselectedVisual", type string if it is a url, map otherwise
179 * @details Sets the disabled unselected state foreground/icon visual
182 DISABLED_UNSELECTED_VISUAL,
185 * @brief name "unselectedBackgroundVisual", type string if it is a url, map otherwise
186 * @details Sets the disabled in the unselected state background, button visual
189 UNSELECTED_BACKGROUND_VISUAL,
192 * @brief name "label", type Property::Map or std::string
198 * @brief name "selectedBackgroundVisual", type string if it is a url, map otherwise
199 * @details Sets the selected background button visual
202 SELECTED_BACKGROUND_VISUAL,
205 * @brief name "disabledUnselectedBackgroundVisual", type string if it is a url, map otherwise
206 * @details Sets the disabled while unselected background button visual
209 DISABLED_UNSELECTED_BACKGROUND_VISUAL,
212 * @brief name "disabledSelectedBackgroundVisual", type string if it is a url, map otherwise
213 * @details Sets the disabled while selected background button visual
216 DISABLED_SELECTED_BACKGROUND_VISUAL,
223 * @brief Creates an uninitialized Button.
225 * Only derived versions can be instantiated. Calling member
226 * functions with an uninitialized Dali::Object is not allowed.
232 * @brief Copy constructor.
234 * @param[in] button Handle to an object
236 Button( const Button& button );
239 * @brief Assignment operator.
241 * @param[in] button Handle to an object
242 * @return A reference to this
244 Button& operator=( const Button& button );
247 * @brief Downcasts a handle to Button handle.
249 * If handle points to a Button, the downcast produces valid handle.
250 * If not the returned handle is left uninitialized.
253 * @param[in] handle Handle to an object
254 * @return A handle to a Button or an uninitialized handle
256 static Button DownCast( BaseHandle handle );
261 * This is non-virtual since derived Handle types must not contain data or virtual methods.
269 * @brief Button signal type.
272 typedef Signal< bool ( Button ) > ButtonSignalType;
275 * @brief This signal is emitted when the button is touched.
277 * A callback of the following type may be connected:
279 * bool YourCallbackName( Button button );
282 * @return The signal to connect to
284 ButtonSignalType& PressedSignal();
287 * @brief This signal is emitted when the button is touched and the touch point leaves the boundary of the button.
289 * A callback of the following type may be connected:
291 * bool YourCallbackName( Button button );
294 * @return The signal to connect to
296 ButtonSignalType& ReleasedSignal();
299 * @brief This signal is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
301 * A callback of the following type may be connected:
303 * bool YourCallbackName( Button button );
306 * @return The signal to connect to
308 ButtonSignalType& ClickedSignal();
311 * @brief This signal is emitted when the button's state is changed.
313 * The application can get the state by calling IsSelected().
315 * A callback of the following type may be connected:
317 * bool YourCallbackName( Button button );
320 * @return The signal to connect to
322 ButtonSignalType& StateChangedSignal();
324 public: // Not intended for application developers
328 * @brief Creates a handle using the Toolkit::Internal implementation.
331 * @param[in] implementation The Control implementation
333 DALI_INTERNAL Button( Internal::Button& implementation );
336 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
339 * @param[in] internal A pointer to the internal CustomActor
341 DALI_INTERNAL Button( Dali::Internal::CustomActor* internal );
348 } // namespace Toolkit
352 #endif // DALI_TOOLKIT_BUTTON_H