• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOGGLE_TOGGLE_MODEL_NG_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOGGLE_TOGGLE_MODEL_NG_H
17 
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components_ng/pattern/toggle/toggle_model.h"
20 
21 namespace OHOS::Ace::NG {
22 
23 class ACE_EXPORT ToggleModelNG : public OHOS::Ace::ToggleModel {
24 public:
25     void Create(ToggleType toggleType, bool isOn) override;
26     void SetSelectedColor(const std::optional<Color>& selectedColor) override;
27     void SetSwitchPointColor(const Color& switchPointColor) override;
28     void OnChange(ChangeEvent&& onChange) override;
29     void SetWidth(const Dimension& width) override;
30     void SetHeight(const Dimension& height) override;
31     void SetBackgroundColor(const Color& color) override;
32     bool IsToggle() override;
33     void SetPadding(const NG::PaddingPropertyF& args, const NG::PaddingProperty& newArgs) override;
34     void OnChangeEvent(ChangeEvent&& onChangeEvent) override;
35     void SetResponseRegion(const std::vector<DimensionRect>& responseRegion) override;
36     void SetHoverEffect(HoverEffectType hoverEffect) override;
37     void Pop() override;
38     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, ToggleType toggleType, bool isOn);
39     static void SetSelectedColor(FrameNode* frameNode, const std::optional<Color>& selectedColor);
40     static void SetSwitchPointColor(FrameNode* frameNode, const Color& switchPointColor);
41     static void SetBackgroundColor(FrameNode* frameNode, const Color& color);
42     static void OnChange(FrameNode* frameNode, ChangeEvent&& onChange);
43     static void SetHeight(FrameNode* frameNode, const Dimension& height);
44     static void SetResponseRegion(FrameNode* frameNode, const std::vector<DimensionRect>& responseRegion);
45     static void SetPadding(FrameNode* frameNode, const NG::PaddingPropertyF& args, const NG::PaddingProperty& newArgs);
46     static void SetHoverEffect(FrameNode* frameNode, HoverEffectType hoverEffect);
47 
48 private:
49     static void CreateCheckbox(int32_t nodeId);
50     static void CreateSwitch(int32_t nodeId);
51     static void CreateButton(int32_t nodeId);
52     static RefPtr<FrameNode> CreateCheckboxFrameNode(int32_t nodeId, bool isOn);
53     static RefPtr<FrameNode> CreateSwitchFrameNode(int32_t nodeId, bool isOn);
54     static RefPtr<FrameNode> CreateButtonFrameNode(int32_t nodeId, bool isOn);
55     static void AddNewChild(const RefPtr<UINode>& parentFrame, int32_t nodeId, int32_t index);
56     static int32_t RemoveNode(const RefPtr<FrameNode>& childFrameNode, int32_t nodeId);
57     static void SetSwitchSelected(RefPtr<FrameNode>& childFrameNode, bool isOn);
58 };
59 
60 } // namespace OHOS::Ace::NG
61 
62 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TOGGLE_TOGGLE_MODEL_NG_H
63