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::Control::CreateAccessibleObject()
133 DevelControl::ControlAccessible* CreateAccessibleObject() override;
136 * @copydoc Toolkit::Internal::Button::OnRelayout
138 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
141 * This method is called when the button is pressed.
143 void OnPressed() override;
147 ToggleButton(const ToggleButton&);
150 ToggleButton& operator=(const ToggleButton&);
153 Property::Array mToggleStates; ///< Toggle states, string or map.
154 std::vector<Toolkit::Visual::Base> mToggleVisuals; ///< Save all unselected visuals.
155 std::vector<Toolkit::Visual::Base> mToggleSelectedVisuals; ///< Save all selected visuals.
156 std::vector<Toolkit::Visual::Base> mToggleDisabledVisuals; ///< Save all disabled unselected visuals.
157 std::vector<Toolkit::Visual::Base> mToggleDisabledSelectedVisuals; ///< Save all disabled selected visuals.
158 std::vector<std::string> mToggleTooltips; ///< Toggle tooltips.
159 unsigned int mCurrentToggleIndex; ///< The index of state.
162 class ToggleButtonAccessible : public Button::ButtonAccessible
165 using Button::ButtonAccessible::ButtonAccessible;
168 * @copydoc Dali::Toolkit::DevelControl::ControlAccessible::CalculateStates()
170 Dali::Accessibility::States CalculateStates() override;
173 * @copydoc Dali::Toolkit::DevelControl::ControlAccessible::GetDescriptionRaw()
175 std::string GetDescriptionRaw() const override;
178 * @copydoc Dali::Toolkit::DevelControl::ControlAccessible::GetDescriptionPropertyIndex()
180 Property::Index GetDescriptionPropertyIndex() override;
183 void OnStateChange(State newState) override;
186 } // namespace Internal
188 // Helpers for public-api forwarding methods
190 inline Toolkit::Internal::ToggleButton& GetImplementation(Toolkit::ToggleButton& button)
192 DALI_ASSERT_ALWAYS(button);
194 Dali::RefObject& handle = button.GetImplementation();
196 return static_cast<Toolkit::Internal::ToggleButton&>(handle);
199 inline const Toolkit::Internal::ToggleButton& GetImplementation(const Toolkit::ToggleButton& button)
201 DALI_ASSERT_ALWAYS(button);
203 const Dali::RefObject& handle = button.GetImplementation();
205 return static_cast<const Toolkit::Internal::ToggleButton&>(handle);
208 } // namespace Toolkit
212 #endif // DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H