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.
24 namespace Dali DALI_IMPORT_API
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 PushButton : public Button
83 static const char* const SIGNAL_TOGGLED; ///< name "toggled"
84 static const char* const SIGNAL_PRESSED; ///< name "pressed"
85 static const char* const SIGNAL_RELEASED; ///< name "released"
88 static const char* const ACTION_PUSH_BUTTON_CLICK; ///< name "push-button-click"
91 static const Property::Index PROPERTY_AUTO_REPEATING; ///< name "auto-repeating", @see SetAutoRepeating(), type BOOLEAN
92 static const Property::Index PROPERTY_INITIAL_AUTO_REPEATING_DELAY; ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type FLOAT
93 static const Property::Index PROPERTY_NEXT_AUTO_REPEATING_DELAY; ///< name "next-auto-repeating-delay", @see SetNextAutoRepeatingDelay(), type FLOAT
94 static const Property::Index PROPERTY_TOGGLABLE; ///< name "togglable", @see SetToggleButton(), type BOOLEAN
95 static const Property::Index PROPERTY_TOGGLE; ///< name "toggle", @see SetToggled(), type BOOLEAN
96 static const Property::Index PROPERTY_NORMAL_STATE_ACTOR; ///< name "button-state-actor", @see SetButtonImage(), type MAP
97 static const Property::Index PROPERTY_PRESSED_STATE_ACTOR; ///< name "pressed-state-actor", @see SetPressedImage(), type MAP
98 static const Property::Index PROPERTY_DIMMED_STATE_ACTOR; ///< name "dimmed-state-actor", @see SetDimmedImage(), type MAP
99 static const Property::Index PROPERTY_LABEL_ACTOR; ///< name "label-actor", @see SetLabelText(), type STRING
104 * @brief Create an uninitialized PushButton; this can be initialized with PushButton::New().
106 * Calling member functions with an uninitialized Dali::Object is not allowed.
111 * @brief Copy constructor.
113 PushButton( const PushButton& pushButton );
116 * @brief Assignment operator.
118 PushButton& operator=( const PushButton& pushButton );
123 * This is non-virtual since derived Handle types must not contain data or virtual methods.
128 * @brief Create an initialized PushButton.
130 * @return A handle to a newly allocated Dali resource.
132 static PushButton New();
135 * @brief Downcast an Object handle to PushButton.
137 * If handle points to a PushButton the downcast produces valid
138 * handle. If not the returned handle is left uninitialized.
140 * @param[in] handle Handle to an object
141 * @return handle to a PushButton or an uninitialized handle
143 static PushButton DownCast( BaseHandle handle );
146 * @brief Sets the \e autorepeating property.
148 * If the \e autorepeating property is set to \e true, then the \e toggle property is set to false
149 * but no signal is emitted.
151 * @param[in] autoRepeating \e autorepeating property.
153 void SetAutoRepeating( bool autoRepeating );
156 * @return \e true if the \e autorepeating property is set.
158 bool IsAutoRepeating() const;
161 * @brief Sets the initial autorepeating delay.
163 * By default this value is set to 0.15 seconds.
165 * @pre initialAutoRepeatingDelay must be greater than zero.
166 * @param[in] initialAutoRepeatingDelay in seconds.
168 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
171 * @return the initial autorepeating delay in seconds.
173 float GetInitialAutoRepeatingDelay() const;
176 * @brief Sets the next autorepeating delay.
178 * By default this value is set to 0.05 seconds.
180 * @pre nextAutoRepeatingDelay must be greater than zero.
181 * @param[in] nextAutoRepeatingDelay in seconds.
183 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
186 * @return the next autorepeating delay in seconds.
188 float GetNextAutoRepeatingDelay() const;
191 * @brief Sets the \e toggle property.
193 * If the \e toggle property is set to \e true, then the \e autorepeating property is set to false.
195 * @param[in] toggle property.
197 void SetToggleButton( bool toggle );
200 * @return \e true if the \e toggle property is set.
202 bool IsToggleButton() const;
205 * @brief Sets the button as toggled or not toggled.
207 * \e toggle property must be set to \e true.
209 * Emits a PushButton::ToggledSignal() signal.
211 * @param[in] toggle state.
213 void SetToggled( bool toggle );
216 * @return \e true if the \e toggle property is set and the button is toggled.
218 bool IsToggled() const;
221 * @brief Sets the button image.
223 * @param[in] image The button image.
225 void SetButtonImage( Image image );
228 * @copydoc SetButtonImage( Image image )
230 void SetButtonImage( Actor image );
233 * @brief Gets the button image.
235 * @return An actor with the button image.
237 Actor GetButtonImage() const;
240 * @brief Sets the background image.
242 * @param[in] image The background image.
244 void SetBackgroundImage( Image image );
247 * @copydoc SetBackgroundImage( Image image )
249 void SetBackgroundImage( Actor image );
252 * @brief Gets the background image.
254 * @return An actor with the background image.
256 Actor GetBackgroundImage() const;
259 * @brief Sets the pressed image.
261 * @param[in] image The pressed image.
263 void SetPressedImage( Image image );
266 * @copydoc SetPressedImage( Image image )
268 void SetPressedImage( Actor image );
271 * @brief Gets the pressed image.
273 * @return An actor with the pressed image.
275 Actor GetPressedImage() const;
278 * @brief Sets the dimmed background image.
280 * @param[in] image The dimmed background image.
282 void SetDimmedBackgroundImage( Image image );
285 * @copydoc SetDimmedBackgroundImage( Image image )
287 void SetDimmedBackgroundImage( Actor image );
290 * @brief Gets the dimmed background image.
292 * @return An actor with the dimmed background image.
294 Actor GetDimmedBackgroundImage() const;
297 * @brief Sets the dimmed button image.
299 * @param[in] image The dimmed button image.
301 void SetDimmedImage( Image image );
304 * @copydoc SetDimmedImage( Image image )
306 void SetDimmedImage( Actor image );
309 * @brief Gets the dimmed image.
311 * @return An actor with the dimmed image.
313 Actor GetDimmedImage() const;
316 * @brief Sets the text label.
318 * @param[in] text Label text.
320 void SetLabelText( const std::string& text );
323 * @copydoc SetLabelText( const std::string& text )
325 void SetLabelText( Actor text );
328 * @brief Gets the label text.
330 * @return An actor with the label text.
332 Actor GetLabelText() const;
336 /// @brief PushButton Toggled signal type.
337 typedef SignalV2< bool ( Button, bool ) > ToggledSignalV2;
339 /// @brief PushButton Pressed signal type.
340 typedef SignalV2< bool ( Button ) > PressedSignalV2;
342 /// @brief PushButton Released signal type.
343 typedef SignalV2< bool ( Button ) > ReleasedSignalV2;
346 * @brief Signal emitted when the \e toggle property is set and the button is touched.
348 ToggledSignalV2& ToggledSignal();
351 * @brief Signal emitted when the button is touched.
353 PressedSignalV2& PressedSignal();
356 * @brief Signal emitted when the button is touched and the touch point leaves the boundary of the button.
358 ReleasedSignalV2& ReleasedSignal();
360 public: // Not intended for application developers
363 * @brief Creates a handle using the Toolkit::Internal implementation.
365 * @param[in] implementation The Control implementation.
367 PushButton( Internal::PushButton& implementation );
370 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
372 * @param[in] internal A pointer to the internal CustomActor.
374 PushButton( Dali::Internal::CustomActor* internal );
377 } // namespace Toolkit
381 #endif // __DALI_TOOLKIT_PUSH_BUTTON_H__