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 Flora License, Version 1.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://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_TOOLKIT_BUTTONS_MODULE
28 namespace Dali DALI_IMPORT_API
34 // Forward declarations
36 namespace Internal DALI_INTERNAL
38 // Forward declarations
44 * @brief A PushButton changes its appearance when is pressed and returns to its original when is released.
46 * By default a PushButton emits a PushButton::PressedSignal() signal when the button is pressed, a Button::ClickedSignal() signal when it's clicked
47 * and a PushButton::ReleasedSignal() signal when it's released or having pressed it, the touch point leaves the boundary of the button.
49 * PushButton provides the following properties which modify signals emitted:
51 * <li>\e autorepeating
53 * When \e autorepeating is set to \e true, a PushButton::PressedSignal(), PushButton::ReleasedSignal() and Button::ClickedSignal() signals are emitted at regular
54 * intervals while the button is touched.
56 * The intervals could be modified with the PushButton::SetInitialAutoRepeatingDelay and PushButton::SetNextAutoRepeatingDelay methods.
58 * 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
59 * false but no signal is emitted.
63 * 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
64 * of emit PushButton::PressedSignal(), Button::ClickedSignal() and PushButton::ReleasedSignal() signals.
66 * 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.
69 * The button's appearance could be modified by setting images or actors with PushButton::SetButtonImage, PushButton::SetBackgroundImage,
70 * PushButton::SetPressedImage, PushButton::SetDimmedBackgroundImage and PushButton::SetDimmedImage or setting a text with
71 * PushButton::SetLabelText.
73 * 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
74 * 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.
76 * When the button is dimmed, \e background, \e button and \e pressed images are replaced by their \e dimmed images.
78 * The methods used to modify the button's appearance could receive Dali::Actor objects as a parameter, so more complex images could be defined.
80 * 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.
82 class PushButton : public Button
87 static const char* const SIGNAL_TOGGLED; ///< name "toggled"
88 static const char* const SIGNAL_PRESSED; ///< name "pressed"
89 static const char* const SIGNAL_RELEASED; ///< name "released"
92 static const char* const ACTION_PUSH_BUTTON_CLICK; ///< name "push-button-click"
95 static const Property::Index PROPERTY_AUTO_REPEATING; ///< name "auto-repeating", @see SetAutoRepeating(), type BOOLEAN
96 static const Property::Index PROPERTY_INITIAL_AUTO_REPEATING_DELAY; ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type FLOAT
97 static const Property::Index PROPERTY_NEXT_AUTO_REPEATING_DELAY; ///< name "next-auto-repeating-delay", @see SetNextAutoRepeatingDelay(), type FLOAT
98 static const Property::Index PROPERTY_TOGGLABLE; ///< name "togglable", @see SetToggleButton(), type BOOLEAN
99 static const Property::Index PROPERTY_TOGGLE; ///< name "toggle", @see SetToggled(), type BOOLEAN
100 static const Property::Index PROPERTY_NORMAL_STATE_ACTOR; ///< name "button-state-actor", @see SetButtonImage(), type MAP
101 static const Property::Index PROPERTY_PRESSED_STATE_ACTOR; ///< name "pressed-state-actor", @see SetPressedImage(), type MAP
102 static const Property::Index PROPERTY_DIMMED_STATE_ACTOR; ///< name "dimmed-state-actor", @see SetDimmedImage(), type MAP
103 static const Property::Index PROPERTY_LABEL_ACTOR; ///< name "label-actor", @see SetLabelText(), type STRING
108 * @brief Create an uninitialized PushButton; this can be initialized with PushButton::New().
110 * Calling member functions with an uninitialized Dali::Object is not allowed.
115 * @brief Copy constructor.
117 PushButton( const PushButton& pushButton );
120 * @brief Assignment operator.
122 PushButton& operator=( const PushButton& pushButton );
125 * @brief Virtual destructor.
127 * Dali::Object derived classes typically do not contain member data.
129 virtual ~PushButton();
132 * @brief Create an initialized PushButton.
134 * @return A handle to a newly allocated Dali resource.
136 static PushButton New();
139 * @brief Downcast an Object handle to PushButton.
141 * If handle points to a PushButton the downcast produces valid
142 * handle. If not the returned handle is left uninitialized.
144 * @param[in] handle Handle to an object
145 * @return handle to a PushButton or an uninitialized handle
147 static PushButton DownCast( BaseHandle handle );
150 * @brief Sets the \e autorepeating property.
152 * If the \e autorepeating property is set to \e true, then the \e toggle property is set to false
153 * but no signal is emitted.
155 * @param[in] autoRepeating \e autorepeating property.
157 void SetAutoRepeating( bool autoRepeating );
160 * @return \e true if the \e autorepeating property is set.
162 bool IsAutoRepeating() const;
165 * @brief Sets the initial autorepeating delay.
167 * By default this value is set to 0.15 seconds.
169 * @pre initialAutoRepeatingDelay must be greater than zero.
170 * @param[in] initialAutoRepeatingDelay in seconds.
172 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
175 * @return the initial autorepeating delay in seconds.
177 float GetInitialAutoRepeatingDelay() const;
180 * @brief Sets the next autorepeating delay.
182 * By default this value is set to 0.05 seconds.
184 * @pre nextAutoRepeatingDelay must be greater than zero.
185 * @param[in] nextAutoRepeatingDelay in seconds.
187 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
190 * @return the next autorepeating delay in seconds.
192 float GetNextAutoRepeatingDelay() const;
195 * @brief Sets the \e toggle property.
197 * If the \e toggle property is set to \e true, then the \e autorepeating property is set to false.
199 * @param[in] toggle property.
201 void SetToggleButton( bool toggle );
204 * @return \e true if the \e toggle property is set.
206 bool IsToggleButton() const;
209 * @brief Sets the button as toggled or not toggled.
211 * \e toggle property must be set to \e true.
213 * Emits a PushButton::ToggledSignal() signal.
215 * @param[in] toggle state.
217 void SetToggled( bool toggle );
220 * @return \e true if the \e toggle property is set and the button is toggled.
222 bool IsToggled() const;
225 * @brief Sets the button image.
227 * @param[in] image The button image.
229 void SetButtonImage( Image image );
232 * @copydoc SetButtonImage( Image image )
234 void SetButtonImage( Actor image );
237 * @brief Gets the button image.
239 * @return An actor with the button image.
241 Actor GetButtonImage() const;
244 * @brief Sets the background image.
246 * @param[in] image The background image.
248 void SetBackgroundImage( Image image );
251 * @copydoc SetBackgroundImage( Image image )
253 void SetBackgroundImage( Actor image );
256 * @brief Gets the background image.
258 * @return An actor with the background image.
260 Actor GetBackgroundImage() const;
263 * @brief Sets the pressed image.
265 * @param[in] image The pressed image.
267 void SetPressedImage( Image image );
270 * @copydoc SetPressedImage( Image image )
272 void SetPressedImage( Actor image );
275 * @brief Gets the pressed image.
277 * @return An actor with the pressed image.
279 Actor GetPressedImage() const;
282 * @brief Sets the dimmed background image.
284 * @param[in] image The dimmed background image.
286 void SetDimmedBackgroundImage( Image image );
289 * @copydoc SetDimmedBackgroundImage( Image image )
291 void SetDimmedBackgroundImage( Actor image );
294 * @brief Gets the dimmed background image.
296 * @return An actor with the dimmed background image.
298 Actor GetDimmedBackgroundImage() const;
301 * @brief Sets the dimmed button image.
303 * @param[in] image The dimmed button image.
305 void SetDimmedImage( Image image );
308 * @copydoc SetDimmedImage( Image image )
310 void SetDimmedImage( Actor image );
313 * @brief Gets the dimmed image.
315 * @return An actor with the dimmed image.
317 Actor GetDimmedImage() const;
320 * @brief Sets the text label.
322 * @param[in] text Label text.
324 void SetLabelText( const std::string& text );
327 * @copydoc SetLabelText( const std::string& text )
329 void SetLabelText( Actor text );
332 * @brief Gets the label text.
334 * @return An actor with the label text.
336 Actor GetLabelText() const;
340 /// @brief PushButton Toggled signal type.
341 typedef SignalV2< bool ( Button, bool ) > ToggledSignalV2;
343 /// @brief PushButton Pressed signal type.
344 typedef SignalV2< bool ( Button ) > PressedSignalV2;
346 /// @brief PushButton Released signal type.
347 typedef SignalV2< bool ( Button ) > ReleasedSignalV2;
350 * @brief Signal emitted when the \e toggle property is set and the button is touched.
352 ToggledSignalV2& ToggledSignal();
355 * @brief Signal emitted when the button is touched.
357 PressedSignalV2& PressedSignal();
360 * @brief Signal emitted when the button is touched and the touch point leaves the boundary of the button.
362 ReleasedSignalV2& ReleasedSignal();
364 public: // Not intended for application developers
367 * @brief Creates a handle using the Toolkit::Internal implementation.
369 * @param[in] implementation The Control implementation.
371 PushButton( Internal::PushButton& implementation );
374 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
376 * @param[in] internal A pointer to the internal CustomActor.
378 PushButton( Dali::Internal::CustomActor* internal );
381 } // namespace Toolkit
388 #endif // __DALI_TOOLKIT_PUSH_BUTTON_H__