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_FRAMEWORK
28 namespace Dali DALI_IMPORT_API
34 // Forward declarations
36 namespace Internal DALI_INTERNAL
38 // Forward declarations
44 * PushButton provides a button functionality. 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;
88 static const char* const SIGNAL_PRESSED;
89 static const char* const SIGNAL_RELEASED;
92 static const char* const ACTION_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_BUTTON_IMAGE; ///< name "button-image", @see SetButtonImage(Image), type STRING
101 static const Property::Index PROPERTY_PRESSED_IMAGE; ///< name "pressed-image", @see SetPressedImage(Image), type STRING
102 static const Property::Index PROPERTY_DIMMED_IMAGE; ///< name "dimmed-image", @see SetDimmedImage(Image), type STRING
103 static const Property::Index PROPERTY_LABEL_TEXT; ///< name "label-text", @see SetLabelText(const std::string&), type STRING
108 * Create an uninitialized PushButton; this can be initialized with PushButton::New()
109 * Calling member functions with an uninitialized Dali::Object is not allowed.
116 PushButton( const PushButton& pushButton );
119 * Assignment operator.
121 PushButton& operator=( const PushButton& pushButton );
124 * Virtual destructor.
125 * Dali::Object derived classes typically do not contain member data.
127 virtual ~PushButton();
130 * Create an initialized PushButton.
131 * @return A handle to a newly allocated Dali resource.
133 static PushButton New();
136 * Downcast an Object handle to PushButton. If handle points to a PushButton the
137 * downcast produces valid handle. If not the returned handle is left uninitialized.
138 * @param[in] handle Handle to an object
139 * @return handle to a PushButton or an uninitialized handle
141 static PushButton DownCast( BaseHandle handle );
144 * Sets the \e autorepeating property.
146 * If the \e autorepeating property is set to \e true, then the \e toggle property is set to false
147 * but no signal is emitted.
149 * @param[in] autoRepeating \e autorepeating property.
151 void SetAutoRepeating( bool autoRepeating );
154 * @return \e true if the \e autorepeating property is set.
156 bool IsAutoRepeating() const;
159 * Sets the initial autorepeating delay.
161 * By default this value is set to 0.15 seconds.
163 * @pre initialAutoRepeatingDelay must be greater than zero.
164 * @param[in] initialAutoRepeatingDelay in seconds.
166 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
169 * @return the initial autorepeating delay in seconds.
171 float GetInitialAutoRepeatingDelay() const;
174 * Sets the next autorepeating delay.
176 * By default this value is set to 0.05 seconds.
178 * @pre nextAutoRepeatingDelay must be greater than zero.
179 * @param[in] nextAutoRepeatingDelay in seconds.
181 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
184 * @return the next autorepeating delay in seconds.
186 float GetNextAutoRepeatingDelay() const;
189 * Sets the \e toggle property.
191 * If the \e toggle property is set to \e true, then the \e autorepeating property is set to false.
193 * @param[in] toggle property.
195 void SetToggleButton( bool toggle );
198 * @return \e true if the \e toggle property is set.
200 bool IsToggleButton() const;
203 * Sets the button as toggled or not toggled.
205 * \e toggle property must be set to \e true.
207 * Emits a PushButton::ToggledSignal() signal.
209 * @param[in] toggle state.
211 void SetToggled( bool toggle );
214 * @return \e true if the \e toggle property is set and the button is toggled.
216 bool IsToggled() const;
219 * Sets the button image.
221 * @param[in] image The button image.
223 void SetButtonImage( Image image );
226 * @copydoc SetButtonImage( Image image )
228 void SetButtonImage( Actor image );
231 * Gets the button image.
232 * @return An actor with the button image.
234 Actor GetButtonImage() const;
237 * Sets the background image.
239 * @param[in] image The background image.
241 void SetBackgroundImage( Image image );
244 * @copydoc SetBackgroundImage( Image image )
246 void SetBackgroundImage( Actor image );
249 * Gets the background image.
250 * @return An actor with the background image.
252 Actor GetBackgroundImage() const;
255 * Sets the pressed image.
257 * @param[in] image The pressed image.
259 void SetPressedImage( Image image );
262 * @copydoc SetPressedImage( Image image )
264 void SetPressedImage( Actor image );
267 * Gets the pressed image.
268 * @return An actor with the pressed image.
270 Actor GetPressedImage() const;
273 * Sets the dimmed background image.
275 * @param[in] image The dimmed background image.
277 void SetDimmedBackgroundImage( Image image );
280 * @copydoc SetDimmedBackgroundImage( Image image )
282 void SetDimmedBackgroundImage( Actor image );
285 * Gets the dimmed background image.
286 * @return An actor with the dimmed background image.
288 Actor GetDimmedBackgroundImage() const;
291 * Sets the dimmed button image.
293 * @param[in] image The dimmed button image.
295 void SetDimmedImage( Image image );
298 * @copydoc SetDimmedImage( Image image )
300 void SetDimmedImage( Actor image );
303 * Gets the dimmed image.
304 * @return An actor with the dimmed image.
306 Actor GetDimmedImage() const;
309 * Sets the text label.
311 * @param[in] text Label text.
313 void SetLabelText( const std::string& text );
316 * @copydoc SetLabelText( const std::string& text )
318 void SetLabelText( Actor text );
321 * Gets the label text.
322 * @return An actor with the label text.
324 Actor GetLabelText() const;
328 // PushButton Toggled
330 typedef SignalV2< bool ( Button, bool ) > ToggledSignalV2;
332 // PushButton Pressed
334 typedef SignalV2< bool ( Button ) > PressedSignalV2;
336 // PushButton Released
338 typedef SignalV2< bool ( Button ) > ReleasedSignalV2;
341 * Signal emitted when the \e toggle property is set and the button is touched.
343 ToggledSignalV2& ToggledSignal();
346 * Signal emitted when the button is touched.
348 PressedSignalV2& PressedSignal();
351 * Signal emitted when the button is touched and the touch point leaves the boundary of the button.
353 ReleasedSignalV2& ReleasedSignal();
355 public: // Not intended for application developers
358 * Creates a handle using the Toolkit::Internal implementation.
359 * @param[in] implementation The Control implementation.
361 PushButton( Internal::PushButton& implementation );
364 * Allows the creation of this Control from an Internal::CustomActor pointer.
365 * @param[in] internal A pointer to the internal CustomActor.
367 PushButton( Dali::Internal::CustomActor* internal );
370 } // namespace Toolkit
377 #endif // __DALI_TOOLKIT_PUSH_BUTTON_H__