1 #ifndef __DALI_TOOLKIT_PUSH_BUTTON_H__
2 #define __DALI_TOOLKIT_PUSH_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.
30 // Forward declarations
32 namespace Internal DALI_INTERNAL
34 // Forward declarations
40 * @brief A PushButton changes its appearance when is pressed and returns to its original when is released.
42 * By default a PushButton emits a PushButton::PressedSignal() signal when the button is pressed, a Button::ClickedSignal() signal when it's clicked
43 * and a PushButton::ReleasedSignal() signal when it's released or having pressed it, the touch point leaves the boundary of the button.
45 * PushButton provides the following properties which modify signals emitted:
47 * <li>\e autorepeating
49 * When \e autorepeating is set to \e true, a PushButton::PressedSignal(), PushButton::ReleasedSignal() and Button::ClickedSignal() signals are emitted at regular
50 * intervals while the button is touched.
52 * The intervals could be modified with the PushButton::SetInitialAutoRepeatingDelay and PushButton::SetNextAutoRepeatingDelay methods.
54 * A \e toggle button can't be \e autorepeating. If the \e autorepeating property is set to \e true, then the \e toggled property is set to
55 * false but no signal is emitted.
59 * When \e toggle is set to \e true, a Button::StateChangedSignal() signal is emitted, with the toggle state, every time the button is touched instead
60 * of emit PushButton::PressedSignal(), Button::ClickedSignal() and PushButton::ReleasedSignal() signals.
62 * An \e autorepeating button can't be \e toggle. If the \e toggled property is set to \e true, then the \e autorepeating property is set to false.
65 * The button's appearance could be modified by setting images or actors with PushButton::SetButtonImage, PushButton::SetBackgroundImage,
66 * PushButton::SetSelectedImage, PushButton::SetDisabledBackgroundImage and PushButton::SetDisabledImage or setting a text with
67 * PushButton::SetLabel.
69 * 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
70 * 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.
72 * When the button is disabled, \e background, \e button and \e selected images are replaced by their \e disabled images.
74 * The methods used to modify the button's appearance could receive Dali::Actor objects as a parameter, so more complex images could be defined.
76 * 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.
78 class DALI_IMPORT_API PushButton : public Button
83 static const char* const SIGNAL_PRESSED; ///< name "pressed"
84 static const char* const SIGNAL_RELEASED; ///< name "released"
87 static const char* const ACTION_PUSH_BUTTON_CLICK; ///< name "push-button-click"
92 * @brief Create an uninitialized PushButton; this can be initialized with PushButton::New().
94 * Calling member functions with an uninitialized Dali::Object is not allowed.
99 * @brief Copy constructor.
101 PushButton( const PushButton& pushButton );
104 * @brief Assignment operator.
106 PushButton& operator=( const PushButton& pushButton );
111 * This is non-virtual since derived Handle types must not contain data or virtual methods.
116 * @brief Create an initialized PushButton.
118 * @return A handle to a newly allocated Dali resource.
120 static PushButton New();
123 * @brief Downcast an Object handle to PushButton.
125 * If handle points to a PushButton the downcast produces valid
126 * handle. If not the returned handle is left uninitialized.
128 * @param[in] handle Handle to an object
129 * @return handle to a PushButton or an uninitialized handle
131 static PushButton DownCast( BaseHandle handle );
134 * @brief Sets the \e autorepeating property.
136 * If the \e autorepeating property is set to \e true, then the \e toggled property is set to false
137 * but no signal is emitted.
139 * @param[in] autoRepeating \e autorepeating property.
141 void SetAutoRepeating( bool autoRepeating );
144 * @return \e true if the \e autorepeating property is set.
146 bool IsAutoRepeating() const;
149 * @brief Sets the initial autorepeating delay.
151 * By default this value is set to 0.15 seconds.
153 * @pre initialAutoRepeatingDelay must be greater than zero.
154 * @param[in] initialAutoRepeatingDelay in seconds.
156 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
159 * @return the initial autorepeating delay in seconds.
161 float GetInitialAutoRepeatingDelay() const;
164 * @brief Sets the next autorepeating delay.
166 * By default this value is set to 0.05 seconds.
168 * @pre nextAutoRepeatingDelay must be greater than zero.
169 * @param[in] nextAutoRepeatingDelay in seconds.
171 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
174 * @return the next autorepeating delay in seconds.
176 float GetNextAutoRepeatingDelay() const;
179 * @brief Sets the \e toggled property.
181 * If the \e toggled property is set to \e true, then the \e autorepeating property is set to false.
183 * @param[in] toggle property.
185 void SetToggleButton( bool toggle );
188 * @return \e true if the \e toggled property is set.
190 bool IsToggleButton() const;
193 * @brief Sets the button as toggled or not toggled.
195 * \e toggled property must be set to \e true.
197 * Emits a Button::StateChangedSignal() signal.
199 * @param[in] toggle state.
201 void SetToggled( bool toggle );
204 * @return \e true if the \e toggled property is set and the button is toggled.
206 bool IsToggled() const;
209 * @brief Sets the button image.
211 * @param[in] image The button image.
213 void SetButtonImage( Image image );
216 * @copydoc SetButtonImage( Image image )
218 void SetButtonImage( Actor image );
221 * @brief Gets the button image.
223 * @return An actor with the button image.
225 Actor GetButtonImage() const;
228 * @brief Sets the background image.
230 * @param[in] image The background image.
232 void SetBackgroundImage( Image image );
235 * @copydoc SetBackgroundImage( Image image )
237 void SetBackgroundImage( Actor image );
240 * @brief Gets the background image.
242 * @return An actor with the background image.
244 Actor GetBackgroundImage() const;
247 * @brief Sets the selected image.
249 * @param[in] image The selected image.
251 void SetSelectedImage( Image image );
254 * @copydoc SetSelectedImage( Image image )
256 void SetSelectedImage( Actor image );
259 * @brief Gets the selected image.
261 * @return An actor with the selected image.
263 Actor GetSelectedImage() const;
266 * @brief Sets the disabled background image.
268 * @param[in] image The disabled background image.
270 void SetDisabledBackgroundImage( Image image );
273 * @copydoc SetDisabledBackgroundImage( Image image )
275 void SetDisabledBackgroundImage( Actor image );
278 * @brief Gets the disabled background image.
280 * @return An actor with the disabled background image.
282 Actor GetDisabledBackgroundImage() const;
285 * @brief Sets the disabled button image.
287 * @param[in] image The disabled button image.
289 void SetDisabledImage( Image image );
292 * @copydoc SetDisabledImage( Image image )
294 void SetDisabledImage( Actor image );
297 * @brief Gets the disabled image.
299 * @return An actor with the disabled image.
301 Actor GetDisabledImage() const;
304 * @brief Sets the button label.
306 * @param[in] label The button label.
308 void SetLabel( const std::string& label );
311 * @copydoc SetLabel( const std::string& label )
313 void SetLabel( Actor label );
316 * @brief Gets the label.
318 * @return An actor with the label.
320 Actor GetLabel() const;
324 /// @brief PushButton Pressed signal type.
325 typedef Signal< bool ( Button ) > PressedSignalType;
327 /// @brief PushButton Released signal type.
328 typedef Signal< bool ( Button ) > ReleasedSignalType;
331 * @brief Signal emitted when the button is touched.
333 PressedSignalType& PressedSignal();
336 * @brief Signal emitted when the button is touched and the touch point leaves the boundary of the button.
338 ReleasedSignalType& ReleasedSignal();
340 public: // Not intended for application developers
343 * @brief Creates a handle using the Toolkit::Internal implementation.
345 * @param[in] implementation The Control implementation.
347 DALI_INTERNAL PushButton( Internal::PushButton& implementation );
350 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
352 * @param[in] internal A pointer to the internal CustomActor.
354 DALI_INTERNAL PushButton( Dali::Internal::CustomActor* internal );
357 } // namespace Toolkit
361 #endif // __DALI_TOOLKIT_PUSH_BUTTON_H__