1 #ifndef DALI_TOOLKIT_BUTTON_H
2 #define DALI_TOOLKIT_BUTTON_H
5 * Copyright (c) 2020 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>
28 namespace Internal DALI_INTERNAL
33 * @addtogroup dali_toolkit_controls_buttons
38 * @brief Button is a base class for different kinds of buttons.
40 * This class provides the disabled property and the clicked signal.
42 * A ClickedSignal() is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
44 * When the \e disabled property is set to \e true, no signal is emitted.
46 * Button provides the following properties which modify the signals emitted:
48 * <li>\e autorepeating
49 * When \e autorepeating is set to \e true, a Button::PressedSignal(), Button::ReleasedSignal() and Button::ClickedSignal() signals are emitted at regular
50 * intervals while the button is touched.
51 * The intervals could be modified with the Button::SetInitialAutoRepeatingDelay and Button::SetNextAutoRepeatingDelay methods.
53 * 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
54 * false but no signal is emitted.
57 * When \e togglable is set to \e true, a Button::StateChangedSignal() signal is emitted, with the selected state.
60 * '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.
62 * The button's appearance can be modified by setting properties for the various visuals/images.
64 * 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.
66 * The \e button visual is shown over the \e background visual.
67 * When pressed the unselected visuals are replaced by the \e selected visual. The text label is always placed on the top of all images.
69 * When the button is disabled, \e background, \e button and \e selected visuals are replaced by their \e disabled visuals.
73 * | %Signal Name | Method |
74 * |------------------|-----------------------------|
75 * | pressed | @ref PressedSignal() |
76 * | released | @ref ReleasedSignal() |
77 * | clicked | @ref ClickedSignal() |
78 * | stateChanged | @ref StateChangedSignal() |
81 * | %Action Name | Attributes | Description |
82 * |------------------|-------------------------|-----------------------------------------------|
83 * | buttonClick | Doesn't have attributes | Simulates a button click. See @ref DoAction() |
86 class DALI_TOOLKIT_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.
112 * @brief name "disabled", type bool
113 * @details Sets the button as \e disabled.
116 DISABLED = PROPERTY_START_INDEX,
119 * @brief name "autoRepeating", type bool
120 * @details If the \e autorepeating property is set to \e true then the \e togglable property is set to false
126 * @brief name "initialAutoRepeatingDelay", type float
127 * @details By default this value is set to 0.15 seconds.
130 INITIAL_AUTO_REPEATING_DELAY,
133 * @brief name "nextAutoRepeatingDelay", type float
134 * @details default this value is set to 0.05 seconds
137 NEXT_AUTO_REPEATING_DELAY,
140 * @brief name "togglable", type bool
141 * @details If the \e togglable property is set to \e true, then the \e autorepeating property is set to false.
147 * @brief name "selected", type bool
148 * @details Sets the togglable button as either selected or unselected, \e togglable property must be set to \e true.
154 * @brief name "unselectedVisual", type string if it is a url, map otherwise.
155 * @details Sets the unselected button foreground/icon visual
161 * @brief name "selectedImage", type string if it is a url, map otherwise
162 * @details Sets the selected button foreground/icon visual
168 * @brief name "disabledSelectedVisual", type string if it is a url, map otherwise
169 * @details Sets the disabled selected state foreground/icon button visual
172 DISABLED_SELECTED_VISUAL,
175 * @brief name "disabledUnselectedVisual", type string if it is a url, map otherwise
176 * @details Sets the disabled unselected state foreground/icon visual
179 DISABLED_UNSELECTED_VISUAL,
182 * @brief name "unselectedBackgroundVisual", type string if it is a url, map otherwise
183 * @details Sets the disabled in the unselected state background, button visual
186 UNSELECTED_BACKGROUND_VISUAL,
189 * @brief name "label", type Property::Map or std::string
195 * @brief name "selectedBackgroundVisual", type string if it is a url, map otherwise
196 * @details Sets the selected background button visual
199 SELECTED_BACKGROUND_VISUAL,
202 * @brief name "disabledUnselectedBackgroundVisual", type string if it is a url, map otherwise
203 * @details Sets the disabled while unselected background button visual
206 DISABLED_UNSELECTED_BACKGROUND_VISUAL,
209 * @brief name "disabledSelectedBackgroundVisual", type string if it is a url, map otherwise
210 * @details Sets the disabled while selected background button visual
213 DISABLED_SELECTED_BACKGROUND_VISUAL,
219 * @brief Creates an uninitialized Button.
221 * Only derived versions can be instantiated. Calling member
222 * functions with an uninitialized Dali::Object is not allowed.
228 * @brief Copy constructor.
230 * @param[in] button Handle to an object
232 Button(const Button& button);
235 * @brief Move constructor
238 * @param[in] rhs A reference to the moved handle
240 Button(Button&& rhs) noexcept;
243 * @brief Assignment operator.
245 * @param[in] button Handle to an object
246 * @return A reference to this
248 Button& operator=(const Button& button);
251 * @brief Move assignment
254 * @param[in] rhs A reference to the moved handle
255 * @return A reference to this
257 Button& operator=(Button&& rhs) noexcept;
260 * @brief Downcasts a handle to Button handle.
262 * If handle points to a Button, the downcast produces valid handle.
263 * If not the returned handle is left uninitialized.
266 * @param[in] handle Handle to an object
267 * @return A handle to a Button or an uninitialized handle
269 static Button DownCast(BaseHandle handle);
274 * This is non-virtual since derived Handle types must not contain data or virtual methods.
281 * @brief Button signal type.
284 typedef Signal<bool(Button)> ButtonSignalType;
287 * @brief This signal is emitted when the button is touched.
289 * A callback of the following type may be connected:
291 * bool YourCallbackName( Button button );
294 * @return The signal to connect to
296 ButtonSignalType& PressedSignal();
299 * @brief This signal is emitted when the button is touched and the touch point leaves 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& ReleasedSignal();
311 * @brief This signal is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
313 * A callback of the following type may be connected:
315 * bool YourCallbackName( Button button );
318 * @return The signal to connect to
320 ButtonSignalType& ClickedSignal();
323 * @brief This signal is emitted when the button's state is changed.
325 * The application can get the state by calling IsSelected().
327 * A callback of the following type may be connected:
329 * bool YourCallbackName( Button button );
332 * @return The signal to connect to
334 ButtonSignalType& StateChangedSignal();
336 public: // Not intended for application developers
339 * @brief Creates a handle using the Toolkit::Internal implementation.
342 * @param[in] implementation The Control implementation
344 DALI_INTERNAL Button(Internal::Button& implementation);
347 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
350 * @param[in] internal A pointer to the internal CustomActor
352 DALI_INTERNAL Button(Dali::Internal::CustomActor* internal);
359 } // namespace Toolkit
363 #endif // DALI_TOOLKIT_BUTTON_H