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/components/common/properties/color.h"
24 #include "core/components_ng/pattern/toggle/switch_event_hub.h"
25 #include "frameworks/core/components_ng/property/measure_property.h"
26 
27 namespace OHOS::Ace::NG {
28 
29 enum class ToggleType {
30     CHECKBOX = 0,
31     SWITCH,
32     BUTTON,
33 };
34 
35 } // namespace OHOS::Ace::NG
36 
37 namespace OHOS::Ace {
38 
39 class ACE_FORCE_EXPORT ToggleModel {
40 public:
41     static ToggleModel* GetInstance();
42     virtual ~ToggleModel() = default;
43 
44     virtual void Create(NG::ToggleType toggleType, bool isOn) = 0;
45     virtual void SetSelectedColor(const std::optional<Color>& selectedColor) = 0;
46     virtual void SetSwitchPointColor(const Color& switchPointColor) = 0;
47     virtual void OnChange(NG::ChangeEvent&& onChange) = 0;
48     virtual void SetWidth(const Dimension& width) = 0;
49     virtual void SetHeight(const Dimension& height) = 0;
SetBackgroundColor(const Color & color,bool flag)50     virtual void SetBackgroundColor(const Color& color, bool flag) {};
51     virtual bool IsToggle() = 0;
52     virtual void SetPadding(const NG::PaddingPropertyF& args, const NG::PaddingProperty& newArgs) = 0;
53     virtual void OnChangeEvent(NG::ChangeEvent&& onChangeEvent) = 0;
54     virtual void SetResponseRegion(const std::vector<DimensionRect>& responseRegion) = 0;
55     virtual void SetHoverEffect(HoverEffectType hoverEffect) = 0;
56     virtual void Pop() = 0;
SetPointRadius(const Dimension & switchPointRadius)57     virtual void SetPointRadius(const Dimension& switchPointRadius) {};
ResetPointRadius()58     virtual void ResetPointRadius() {};
SetUnselectedColor(const Color & unselectedColor)59     virtual void SetUnselectedColor(const Color& unselectedColor) {};
SetTrackBorderRadius(const Dimension & borderRadius)60     virtual void SetTrackBorderRadius(const Dimension& borderRadius) {};
ResetTrackBorderRadius()61     virtual void ResetTrackBorderRadius() {};
62 
63 private:
64     static std::unique_ptr<ToggleModel> instance_;
65     static std::mutex mutex_;
66 };
67 
68 } // namespace OHOS::Ace
69 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOGGLE_TOGGLE_MODEL_H
70