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.
22 * @addtogroup CAPI_DALI_TOOLKIT_BUTTONS_MODULE
29 namespace Dali DALI_IMPORT_API
35 // Forward declarations
37 namespace Internal DALI_INTERNAL
39 // Forward declarations
45 * @brief A PushButton changes its appearance when is pressed and returns to its original when is released.
47 * By default a PushButton emits a PushButton::PressedSignal() signal when the button is pressed, a Button::ClickedSignal() signal when it's clicked
48 * and a PushButton::ReleasedSignal() signal when it's released or having pressed it, the touch point leaves the boundary of the button.
50 * PushButton provides the following properties which modify signals emitted:
52 * <li>\e autorepeating
54 * When \e autorepeating is set to \e true, a PushButton::PressedSignal(), PushButton::ReleasedSignal() and Button::ClickedSignal() signals are emitted at regular
55 * intervals while the button is touched.
57 * The intervals could be modified with the PushButton::SetInitialAutoRepeatingDelay and PushButton::SetNextAutoRepeatingDelay methods.
59 * 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
60 * false but no signal is emitted.
64 * 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
65 * of emit PushButton::PressedSignal(), Button::ClickedSignal() and PushButton::ReleasedSignal() signals.
67 * 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.
70 * The button's appearance could be modified by setting images or actors with PushButton::SetButtonImage, PushButton::SetBackgroundImage,
71 * PushButton::SetPressedImage, PushButton::SetDimmedBackgroundImage and PushButton::SetDimmedImage or setting a text with
72 * PushButton::SetLabelText.
74 * 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
75 * 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.
77 * When the button is dimmed, \e background, \e button and \e pressed images are replaced by their \e dimmed images.
79 * The methods used to modify the button's appearance could receive Dali::Actor objects as a parameter, so more complex images could be defined.
81 * 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.
83 class PushButton : public Button
88 static const char* const SIGNAL_TOGGLED; ///< name "toggled"
89 static const char* const SIGNAL_PRESSED; ///< name "pressed"
90 static const char* const SIGNAL_RELEASED; ///< name "released"
93 static const char* const ACTION_PUSH_BUTTON_CLICK; ///< name "push-button-click"
96 static const Property::Index PROPERTY_AUTO_REPEATING; ///< name "auto-repeating", @see SetAutoRepeating(), type BOOLEAN
97 static const Property::Index PROPERTY_INITIAL_AUTO_REPEATING_DELAY; ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type FLOAT
98 static const Property::Index PROPERTY_NEXT_AUTO_REPEATING_DELAY; ///< name "next-auto-repeating-delay", @see SetNextAutoRepeatingDelay(), type FLOAT
99 static const Property::Index PROPERTY_TOGGLABLE; ///< name "togglable", @see SetToggleButton(), type BOOLEAN
100 static const Property::Index PROPERTY_TOGGLE; ///< name "toggle", @see SetToggled(), type BOOLEAN
101 static const Property::Index PROPERTY_NORMAL_STATE_ACTOR; ///< name "button-state-actor", @see SetButtonImage(), type MAP
102 static const Property::Index PROPERTY_PRESSED_STATE_ACTOR; ///< name "pressed-state-actor", @see SetPressedImage(), type MAP
103 static const Property::Index PROPERTY_DIMMED_STATE_ACTOR; ///< name "dimmed-state-actor", @see SetDimmedImage(), type MAP
104 static const Property::Index PROPERTY_LABEL_ACTOR; ///< name "label-actor", @see SetLabelText(), type STRING
109 * @brief Create an uninitialized PushButton; this can be initialized with PushButton::New().
111 * Calling member functions with an uninitialized Dali::Object is not allowed.
116 * @brief Copy constructor.
118 PushButton( const PushButton& pushButton );
121 * @brief Assignment operator.
123 PushButton& operator=( const PushButton& pushButton );
128 * This is non-virtual since derived Handle types must not contain data or virtual methods.
133 * @brief Create an initialized PushButton.
135 * @return A handle to a newly allocated Dali resource.
137 static PushButton New();
140 * @brief Downcast an Object handle to PushButton.
142 * If handle points to a PushButton the downcast produces valid
143 * handle. If not the returned handle is left uninitialized.
145 * @param[in] handle Handle to an object
146 * @return handle to a PushButton or an uninitialized handle
148 static PushButton DownCast( BaseHandle handle );
151 * @brief Sets the \e autorepeating property.
153 * If the \e autorepeating property is set to \e true, then the \e toggle property is set to false
154 * but no signal is emitted.
156 * @param[in] autoRepeating \e autorepeating property.
158 void SetAutoRepeating( bool autoRepeating );
161 * @return \e true if the \e autorepeating property is set.
163 bool IsAutoRepeating() const;
166 * @brief Sets the initial autorepeating delay.
168 * By default this value is set to 0.15 seconds.
170 * @pre initialAutoRepeatingDelay must be greater than zero.
171 * @param[in] initialAutoRepeatingDelay in seconds.
173 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
176 * @return the initial autorepeating delay in seconds.
178 float GetInitialAutoRepeatingDelay() const;
181 * @brief Sets the next autorepeating delay.
183 * By default this value is set to 0.05 seconds.
185 * @pre nextAutoRepeatingDelay must be greater than zero.
186 * @param[in] nextAutoRepeatingDelay in seconds.
188 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
191 * @return the next autorepeating delay in seconds.
193 float GetNextAutoRepeatingDelay() const;
196 * @brief Sets the \e toggle property.
198 * If the \e toggle property is set to \e true, then the \e autorepeating property is set to false.
200 * @param[in] toggle property.
202 void SetToggleButton( bool toggle );
205 * @return \e true if the \e toggle property is set.
207 bool IsToggleButton() const;
210 * @brief Sets the button as toggled or not toggled.
212 * \e toggle property must be set to \e true.
214 * Emits a PushButton::ToggledSignal() signal.
216 * @param[in] toggle state.
218 void SetToggled( bool toggle );
221 * @return \e true if the \e toggle property is set and the button is toggled.
223 bool IsToggled() const;
226 * @brief Sets the button image.
228 * @param[in] image The button image.
230 void SetButtonImage( Image image );
233 * @copydoc SetButtonImage( Image image )
235 void SetButtonImage( Actor image );
238 * @brief Gets the button image.
240 * @return An actor with the button image.
242 Actor GetButtonImage() const;
245 * @brief Sets the background image.
247 * @param[in] image The background image.
249 void SetBackgroundImage( Image image );
252 * @copydoc SetBackgroundImage( Image image )
254 void SetBackgroundImage( Actor image );
257 * @brief Gets the background image.
259 * @return An actor with the background image.
261 Actor GetBackgroundImage() const;
264 * @brief Sets the pressed image.
266 * @param[in] image The pressed image.
268 void SetPressedImage( Image image );
271 * @copydoc SetPressedImage( Image image )
273 void SetPressedImage( Actor image );
276 * @brief Gets the pressed image.
278 * @return An actor with the pressed image.
280 Actor GetPressedImage() const;
283 * @brief Sets the dimmed background image.
285 * @param[in] image The dimmed background image.
287 void SetDimmedBackgroundImage( Image image );
290 * @copydoc SetDimmedBackgroundImage( Image image )
292 void SetDimmedBackgroundImage( Actor image );
295 * @brief Gets the dimmed background image.
297 * @return An actor with the dimmed background image.
299 Actor GetDimmedBackgroundImage() const;
302 * @brief Sets the dimmed button image.
304 * @param[in] image The dimmed button image.
306 void SetDimmedImage( Image image );
309 * @copydoc SetDimmedImage( Image image )
311 void SetDimmedImage( Actor image );
314 * @brief Gets the dimmed image.
316 * @return An actor with the dimmed image.
318 Actor GetDimmedImage() const;
321 * @brief Sets the text label.
323 * @param[in] text Label text.
325 void SetLabelText( const std::string& text );
328 * @copydoc SetLabelText( const std::string& text )
330 void SetLabelText( Actor text );
333 * @brief Gets the label text.
335 * @return An actor with the label text.
337 Actor GetLabelText() const;
341 /// @brief PushButton Toggled signal type.
342 typedef SignalV2< bool ( Button, bool ) > ToggledSignalV2;
344 /// @brief PushButton Pressed signal type.
345 typedef SignalV2< bool ( Button ) > PressedSignalV2;
347 /// @brief PushButton Released signal type.
348 typedef SignalV2< bool ( Button ) > ReleasedSignalV2;
351 * @brief Signal emitted when the \e toggle property is set and the button is touched.
353 ToggledSignalV2& ToggledSignal();
356 * @brief Signal emitted when the button is touched.
358 PressedSignalV2& PressedSignal();
361 * @brief Signal emitted when the button is touched and the touch point leaves the boundary of the button.
363 ReleasedSignalV2& ReleasedSignal();
365 public: // Not intended for application developers
368 * @brief Creates a handle using the Toolkit::Internal implementation.
370 * @param[in] implementation The Control implementation.
372 PushButton( Internal::PushButton& implementation );
375 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
377 * @param[in] internal A pointer to the internal CustomActor.
379 PushButton( Dali::Internal::CustomActor* internal );
382 } // namespace Toolkit
389 #endif // __DALI_TOOLKIT_PUSH_BUTTON_H__