1 #ifndef DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H
2 #define DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H
5 * Copyright (c) 2021 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-array.h>
24 #include <dali/public-api/object/property-value.h>
27 #include <dali-toolkit/devel-api/controls/buttons/toggle-button.h>
28 #include "button-impl.h"
37 * ToggleButton implementation class.
39 * \sa Dali::Toolkit::ToggleButton
41 class ToggleButton : public Button
45 * Create a new ToggleButton.
46 * @return A smart-pointer to the newly allocated ToggleButton.
48 static Dali::Toolkit::ToggleButton New();
52 * Construct a new ToggleButton.
57 * A reference counted object may only be deleted by calling Unreference()
59 virtual ~ToggleButton();
63 * Called when a property of an object of this type is set.
64 * @param[in] object The object whose property is set.
65 * @param[in] index The property index.
66 * @param[in] value The new property value.
68 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
71 * Called to retrieve a property of an object of this type.
72 * @param[in] object The object whose property is to be retrieved.
73 * @param[in] index The property index.
74 * @return The current value of the property.
76 static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
80 * Called to create all toggle visuals and save them to mToggleVisuals.
81 * @param[in] states The array store toggle states.
82 * @param[out] visuals The created state visual vector.
84 void CreateVisualsForAllStates(const Property::Array& states, std::vector<Toolkit::Visual::Base>& visuals);
87 * Called to set toggle states when TOGGLE_STATES is set in SetProperty function.
88 * @param[in] states The array store toggle states.
90 void SetToggleStates(const Property::Array& states);
93 * Called to retrieve toggle states.
94 * @return The toggle states array.
96 Property::Array GetToggleStates() const;
99 * Called to set toggle tooltips when TOGGLE_TIPS is set in SetProperty function.
100 * @param[in] tips The array store toggle tips.
102 void SetToggleTooltips(std::vector<std::string>& tips);
105 * Called to retrieve toggle tips.
106 * @return The toggle tips array.
108 const std::vector<std::string>& GetToggleTooltips() const;
111 * Called to prepare visual for next state.
112 * @param[in] index The property index to set.
113 * @param[in] visual The visual to set.
115 void PrepareVisual(Property::Index index, Toolkit::Visual::Base& visual);
118 * Called to relayout visual.
119 * @param[in] index The index of visual to relayout.
120 * @param[in] size The size of control.
122 void RelayoutVisual(Property::Index index, const Vector2& size);
124 private: // From Button
126 * @copydoc Toolkit::Internal::Button::OnInitialize
128 void OnInitialize() override;
131 * @copydoc Toolkit::Internal::Button::OnRelayout
133 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
136 * This method is called when the button is pressed.
138 void OnPressed() override;
142 ToggleButton(const ToggleButton&);
145 ToggleButton& operator=(const ToggleButton&);
148 Property::Array mToggleStates; ///< Toggle states, string or map.
149 std::vector<Toolkit::Visual::Base> mToggleVisuals; ///< Save all unselected visuals.
150 std::vector<Toolkit::Visual::Base> mToggleSelectedVisuals; ///< Save all selected visuals.
151 std::vector<Toolkit::Visual::Base> mToggleDisabledVisuals; ///< Save all disabled unselected visuals.
152 std::vector<Toolkit::Visual::Base> mToggleDisabledSelectedVisuals; ///< Save all disabled selected visuals.
153 std::vector<std::string> mToggleTooltips; ///< Toggle tooltips.
154 unsigned int mCurrentToggleIndex; ///< The index of state.
156 struct AccessibleImpl : public Button::AccessibleImpl
158 using Button::AccessibleImpl::AccessibleImpl;
160 Dali::Accessibility::States CalculateStates() override;
161 std::string GetDescriptionRaw() override;
162 Property::Index GetDescriptionPropertyIndex() override;
164 void OnStateChange(State newState) override;
167 } // namespace Internal
169 // Helpers for public-api forwarding methods
171 inline Toolkit::Internal::ToggleButton& GetImplementation(Toolkit::ToggleButton& button)
173 DALI_ASSERT_ALWAYS(button);
175 Dali::RefObject& handle = button.GetImplementation();
177 return static_cast<Toolkit::Internal::ToggleButton&>(handle);
180 inline const Toolkit::Internal::ToggleButton& GetImplementation(const Toolkit::ToggleButton& button)
182 DALI_ASSERT_ALWAYS(button);
184 const Dali::RefObject& handle = button.GetImplementation();
186 return static_cast<const Toolkit::Internal::ToggleButton&>(handle);
189 } // namespace Toolkit
193 #endif // DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H