1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOGGLE_TOGGLE_MODEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOGGLE_TOGGLE_MODEL_H 18 19 #include <memory> 20 #include <mutex> 21 22 #include "base/geometry/dimension.h" 23 #include "core/common/resource/resource_object.h" 24 #include "core/components/common/properties/color.h" 25 #include "core/components_ng/pattern/toggle/switch_event_hub.h" 26 #include "frameworks/core/components_ng/property/measure_property.h" 27 28 namespace OHOS::Ace::NG { 29 30 enum class ToggleType { 31 CHECKBOX = 0, 32 SWITCH, 33 BUTTON, 34 }; 35 36 } // namespace OHOS::Ace::NG 37 38 namespace OHOS::Ace { 39 enum class ToggleColorType { 40 SELECTED_COLOR, 41 SWITCH_POINT_COLOR, 42 UN_SELECTED_COLOR, 43 BACKGROUND_COLOR 44 }; 45 enum class ToggleDimensionType { 46 POINT_RADIUS, 47 TRACK_BORDER_RADIUS 48 }; 49 class ACE_FORCE_EXPORT ToggleModel { 50 public: 51 static ToggleModel* GetInstance(); 52 virtual ~ToggleModel() = default; 53 54 virtual void Create(NG::ToggleType toggleType, bool isOn) = 0; 55 virtual void SetSelectedColor(const std::optional<Color>& selectedColor) = 0; 56 virtual void SetSwitchPointColor(const std::optional<Color>& switchPointColor) = 0; 57 virtual void OnChange(NG::ChangeEvent&& onChange) = 0; 58 virtual void SetWidth(const Dimension& width) = 0; 59 virtual void SetHeight(const Dimension& height) = 0; SetBackgroundColor(const Color & color,bool flag)60 virtual void SetBackgroundColor(const Color& color, bool flag) {}; 61 virtual bool IsToggle() = 0; 62 virtual void SetPadding(const NG::PaddingPropertyF& args, const NG::PaddingProperty& newArgs) = 0; SetIsUserSetMargin(bool isUserSet)63 virtual void SetIsUserSetMargin(bool isUserSet) {}; 64 virtual void OnChangeEvent(NG::ChangeEvent&& onChangeEvent) = 0; 65 virtual void SetResponseRegion(const std::vector<DimensionRect>& responseRegion) = 0; 66 virtual void SetHoverEffect(HoverEffectType hoverEffect) = 0; SetPointRadius(const Dimension & switchPointRadius)67 virtual void SetPointRadius(const Dimension& switchPointRadius) {}; ResetPointRadius()68 virtual void ResetPointRadius() {}; SetUnselectedColor(const Color & unselectedColor)69 virtual void SetUnselectedColor(const Color& unselectedColor) {}; SetTrackBorderRadius(const Dimension & borderRadius)70 virtual void SetTrackBorderRadius(const Dimension& borderRadius) {}; ResetTrackBorderRadius()71 virtual void ResetTrackBorderRadius() {}; 72 virtual void Pop(); CreateWithColorResourceObj(const RefPtr<ResourceObject> & resObj,const ToggleColorType toggleColorType)73 virtual void CreateWithColorResourceObj(const RefPtr<ResourceObject>& resObj, 74 const ToggleColorType toggleColorType) {}; CreateWithDimensionVpResourceObj(const RefPtr<ResourceObject> & resObj,const ToggleDimensionType toggleDimensionType)75 virtual void CreateWithDimensionVpResourceObj(const RefPtr<ResourceObject>& resObj, 76 const ToggleDimensionType toggleDimensionType) {}; SetSwitchPointColorSetByUser(const bool flag)77 virtual void SetSwitchPointColorSetByUser(const bool flag) {}; SetUnselectedColorSetByUser(const bool flag)78 virtual void SetUnselectedColorSetByUser(const bool flag) {}; 79 80 private: 81 static std::unique_ptr<ToggleModel> instance_; 82 static std::mutex mutex_; 83 }; 84 85 } // namespace OHOS::Ace 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOGGLE_TOGGLE_MODEL_H 87