1 #ifndef __DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H__
5 * Copyright (c) 2017 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 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/property-value.h>
24 #include <dali/public-api/object/property-array.h>
28 #include <dali-toolkit/devel-api/controls/buttons/toggle-button.h>
29 #include "button-impl.h"
41 * ToggleButton implementation class.
43 * \sa Dali::Toolkit::ToggleButton
45 class ToggleButton : public Button
50 * Create a new ToggleButton.
51 * @return A smart-pointer to the newly allocated ToggleButton.
53 static Dali::Toolkit::ToggleButton New();
58 * Construct a new ToggleButton.
63 * A reference counted object may only be deleted by calling Unreference()
65 virtual ~ToggleButton();
70 * Called when a property of an object of this type is set.
71 * @param[in] object The object whose property is set.
72 * @param[in] index The property index.
73 * @param[in] value The new property value.
75 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
78 * Called to retrieve a property of an object of this type.
79 * @param[in] object The object whose property is to be retrieved.
80 * @param[in] index The property index.
81 * @return The current value of the property.
83 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
88 * Called to create all toggle visuals and save them to mToggleVisuals.
89 * @param[in] states The array store toggle states.
90 * @param[out] visuals The created state visual vector.
92 void CreateVisualsForAllStates( const Property::Array& states, std::vector<Toolkit::Visual::Base>& visuals );
95 * Called to set toggle states when TOGGLE_STATES is set in SetProperty function.
96 * @param[in] states The array store toggle states.
98 void SetToggleStates( const Property::Array& states );
101 * Called to retrieve toggle states.
102 * @return The toggle states array.
104 Property::Array GetToggleStates() const;
107 * Called to set toggle tooltips when TOGGLE_TIPS is set in SetProperty function.
108 * @param[in] tips The array store toggle tips.
110 void SetToggleTooltips( std::vector<std::string>& tips );
113 * Called to retrieve toggle tips.
114 * @return The toggle tips array.
116 const std::vector<std::string>& GetToggleTooltips() const;
119 * Called to prepare visual for next state.
120 * @param[in] index The property index to set.
121 * @param[in] visual The visual to set.
123 void PrepareVisual(Property::Index index, Toolkit::Visual::Base& visual);
126 * Called to relayout visual.
127 * @param[in] index The index of visual to relayout.
128 * @param[in] size The size of control.
130 void RelayoutVisual( Property::Index index, const Vector2& size );
132 private: // From Button
135 * @copydoc Toolkit::Internal::Button::OnInitialize
137 virtual void OnInitialize();
140 * @copydoc Toolkit::Internal::Button::OnRelayout
142 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
145 * This method is called when the button is pressed.
147 virtual void OnPressed();
152 ToggleButton( const ToggleButton& );
155 ToggleButton& operator=( const ToggleButton& );
159 Property::Array mToggleStates; ///< Toggle states, string or map.
160 std::vector<Toolkit::Visual::Base> mToggleVisuals; ///< Save all unselected visuals.
161 std::vector<Toolkit::Visual::Base> mToggleSelectedVisuals; ///< Save all selected visuals.
162 std::vector<Toolkit::Visual::Base> mToggleDisabledVisuals; ///< Save all disabled unselected visuals.
163 std::vector<Toolkit::Visual::Base> mToggleDisabledSelectedVisuals; ///< Save all disabled selected visuals.
164 std::vector<std::string> mToggleTooltips; ///< Toggle tooltips.
165 unsigned int mCurrentToggleIndex; ///< The index of state.
168 } // namespace Internal
170 // Helpers for public-api forwarding methods
172 inline Toolkit::Internal::ToggleButton& GetImplementation( Toolkit::ToggleButton& button )
174 DALI_ASSERT_ALWAYS( button );
176 Dali::RefObject& handle = button.GetImplementation();
178 return static_cast<Toolkit::Internal::ToggleButton&>( handle );
181 inline const Toolkit::Internal::ToggleButton& GetImplementation( const Toolkit::ToggleButton& button )
183 DALI_ASSERT_ALWAYS( button );
185 const Dali::RefObject& handle = button.GetImplementation();
187 return static_cast<const Toolkit::Internal::ToggleButton&>( handle );
190 } // namespace Toolkit
194 #endif // __DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H__