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 toggle property is set to
55 * false but no signal is emitted.
59 * When \e toggle is set to \e true, a PushButton::ToggledSignal() 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 toggle 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::SetPressedImage, PushButton::SetDimmedBackgroundImage and PushButton::SetDimmedImage or setting a text with
67 * PushButton::SetLabelText.
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 pressed image when the button is pressed. The text label is placed always on the top of all images.
72 * When the button is dimmed, \e background, \e button and \e pressed images are replaced by their \e dimmed 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 pressed 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"
90 static const Property::Index PROPERTY_AUTO_REPEATING; ///< name "auto-repeating", @see SetAutoRepeating(), type BOOLEAN
91 static const Property::Index PROPERTY_INITIAL_AUTO_REPEATING_DELAY; ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type FLOAT
92 static const Property::Index PROPERTY_NEXT_AUTO_REPEATING_DELAY; ///< name "next-auto-repeating-delay", @see SetNextAutoRepeatingDelay(), type FLOAT
93 static const Property::Index PROPERTY_TOGGLABLE; ///< name "togglable", @see SetToggleButton(), type BOOLEAN
94 static const Property::Index PROPERTY_TOGGLE; ///< name "toggle", @see SetToggled(), type BOOLEAN
95 static const Property::Index PROPERTY_NORMAL_STATE_ACTOR; ///< name "button-state-actor", @see SetButtonImage(), type MAP
96 static const Property::Index PROPERTY_PRESSED_STATE_ACTOR; ///< name "pressed-state-actor", @see SetPressedImage(), type MAP
97 static const Property::Index PROPERTY_DIMMED_STATE_ACTOR; ///< name "dimmed-state-actor", @see SetDimmedImage(), type MAP
98 static const Property::Index PROPERTY_LABEL_ACTOR; ///< name "label-actor", @see SetLabelText(), type STRING
103 * @brief Create an uninitialized PushButton; this can be initialized with PushButton::New().
105 * Calling member functions with an uninitialized Dali::Object is not allowed.
110 * @brief Copy constructor.
112 PushButton( const PushButton& pushButton );
115 * @brief Assignment operator.
117 PushButton& operator=( const PushButton& pushButton );
122 * This is non-virtual since derived Handle types must not contain data or virtual methods.
127 * @brief Create an initialized PushButton.
129 * @return A handle to a newly allocated Dali resource.
131 static PushButton New();
134 * @brief Downcast an Object handle to PushButton.
136 * If handle points to a PushButton the downcast produces valid
137 * handle. If not the returned handle is left uninitialized.
139 * @param[in] handle Handle to an object
140 * @return handle to a PushButton or an uninitialized handle
142 static PushButton DownCast( BaseHandle handle );
145 * @brief Sets the \e autorepeating property.
147 * If the \e autorepeating property is set to \e true, then the \e toggle property is set to false
148 * but no signal is emitted.
150 * @param[in] autoRepeating \e autorepeating property.
152 void SetAutoRepeating( bool autoRepeating );
155 * @return \e true if the \e autorepeating property is set.
157 bool IsAutoRepeating() const;
160 * @brief Sets the initial autorepeating delay.
162 * By default this value is set to 0.15 seconds.
164 * @pre initialAutoRepeatingDelay must be greater than zero.
165 * @param[in] initialAutoRepeatingDelay in seconds.
167 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
170 * @return the initial autorepeating delay in seconds.
172 float GetInitialAutoRepeatingDelay() const;
175 * @brief Sets the next autorepeating delay.
177 * By default this value is set to 0.05 seconds.
179 * @pre nextAutoRepeatingDelay must be greater than zero.
180 * @param[in] nextAutoRepeatingDelay in seconds.
182 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
185 * @return the next autorepeating delay in seconds.
187 float GetNextAutoRepeatingDelay() const;
190 * @brief Sets the \e toggle property.
192 * If the \e toggle property is set to \e true, then the \e autorepeating property is set to false.
194 * @param[in] toggle property.
196 void SetToggleButton( bool toggle );
199 * @return \e true if the \e toggle property is set.
201 bool IsToggleButton() const;
204 * @brief Sets the button as toggled or not toggled.
206 * \e toggle property must be set to \e true.
208 * Emits a PushButton::ToggledSignal() signal.
210 * @param[in] toggle state.
212 void SetToggled( bool toggle );
215 * @return \e true if the \e toggle property is set and the button is toggled.
217 bool IsToggled() const;
220 * @brief Sets the button image.
222 * @param[in] image The button image.
224 void SetButtonImage( Image image );
227 * @copydoc SetButtonImage( Image image )
229 void SetButtonImage( Actor image );
232 * @brief Gets the button image.
234 * @return An actor with the button image.
236 Actor GetButtonImage() const;
239 * @brief Sets the background image.
241 * @param[in] image The background image.
243 void SetBackgroundImage( Image image );
246 * @copydoc SetBackgroundImage( Image image )
248 void SetBackgroundImage( Actor image );
251 * @brief Gets the background image.
253 * @return An actor with the background image.
255 Actor GetBackgroundImage() const;
258 * @brief Sets the pressed image.
260 * @param[in] image The pressed image.
262 void SetPressedImage( Image image );
265 * @copydoc SetPressedImage( Image image )
267 void SetPressedImage( Actor image );
270 * @brief Gets the pressed image.
272 * @return An actor with the pressed image.
274 Actor GetPressedImage() const;
277 * @brief Sets the dimmed background image.
279 * @param[in] image The dimmed background image.
281 void SetDimmedBackgroundImage( Image image );
284 * @copydoc SetDimmedBackgroundImage( Image image )
286 void SetDimmedBackgroundImage( Actor image );
289 * @brief Gets the dimmed background image.
291 * @return An actor with the dimmed background image.
293 Actor GetDimmedBackgroundImage() const;
296 * @brief Sets the dimmed button image.
298 * @param[in] image The dimmed button image.
300 void SetDimmedImage( Image image );
303 * @copydoc SetDimmedImage( Image image )
305 void SetDimmedImage( Actor image );
308 * @brief Gets the dimmed image.
310 * @return An actor with the dimmed image.
312 Actor GetDimmedImage() const;
315 * @brief Sets the text label.
317 * @param[in] text Label text.
319 void SetLabelText( const std::string& text );
322 * @copydoc SetLabelText( const std::string& text )
324 void SetLabelText( Actor text );
327 * @brief Gets the label text.
329 * @return An actor with the label text.
331 Actor GetLabelText() const;
335 /// @brief PushButton Pressed signal type.
336 typedef Signal< bool ( Button ) > PressedSignalType;
338 /// @brief PushButton Released signal type.
339 typedef Signal< bool ( Button ) > ReleasedSignalType;
342 * @brief Signal emitted when the button is touched.
344 PressedSignalType& PressedSignal();
347 * @brief Signal emitted when the button is touched and the touch point leaves the boundary of the button.
349 ReleasedSignalType& ReleasedSignal();
351 public: // Not intended for application developers
354 * @brief Creates a handle using the Toolkit::Internal implementation.
356 * @param[in] implementation The Control implementation.
358 DALI_INTERNAL PushButton( Internal::PushButton& implementation );
361 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
363 * @param[in] internal A pointer to the internal CustomActor.
365 DALI_INTERNAL PushButton( Dali::Internal::CustomActor* internal );
368 } // namespace Toolkit
372 #endif // __DALI_TOOLKIT_PUSH_BUTTON_H__