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_RADIO_RADIO_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RADIO_RADIO_MODEL_NG_H
18 
19 #include "core/components_ng/base/common_configuration.h"
20 #include "core/components_ng/base/frame_node.h"
21 #include "core/components_ng/pattern/radio/radio_model.h"
22 
23 namespace OHOS::Ace::NG {
24 class RadioConfiguration : public CommonConfiguration {
25 public:
RadioConfiguration(const std::string & value,bool checked,bool enabled)26     RadioConfiguration(const std::string& value, bool checked, bool enabled)
27         : CommonConfiguration(enabled), value_(value), checked_(checked)
28     {}
29     std::string value_;
30     bool checked_;
31 };
32 using RadioMakeCallback = std::function<RefPtr<FrameNode>(RadioConfiguration& radioConfiguration)>;
33 
34 class ACE_EXPORT RadioModelNG : public OHOS::Ace::RadioModel {
35 public:
36     void Create(const std::optional<std::string>& value, const std::optional<std::string>& group,
37         const std::optional<int32_t>& indicator) override;
38     void SetChecked(bool isChecked) override;
39     void SetOnChange(ChangeEvent&& onChange) override;
40     void SetWidth(const Dimension& width) override;
41     void SetHeight(const Dimension& height) override;
42     void SetPadding(const NG::PaddingPropertyF& args, const NG::PaddingProperty& newArgs) override;
43     void SetCheckedBackgroundColor(const Color& color) override;
44     void SetUncheckedBorderColor(const Color& color) override;
45     void SetIndicatorColor(const Color& color) override;
46     void SetOnChangeEvent(ChangeEvent&& onChangeEvent) override;
47     void SetResponseRegion(const std::vector<DimensionRect>& responseRegion) override;
48     void SetHoverEffect(HoverEffectType hoverEffect) override;
49 
50     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId);
51     void SetBuilder(std::function<void()>&& buildFunc) override;
52     static void SetRadioIndicator(int32_t indicator);
53     static void SetChecked(FrameNode* frameNode, bool isChecked);
54     static void SetCheckedBackgroundColor(FrameNode* frameNode, const Color& color);
55     static void SetUncheckedBorderColor(FrameNode* frameNode, const Color& color);
56     static void SetIndicatorColor(FrameNode* frameNode, const Color& color);
57     static void SetWidth(FrameNode* frameNode, const Dimension& width);
58     static void SetHeight(FrameNode* frameNode, const Dimension& height);
59     static void SetHoverEffect(FrameNode* frameNode, HoverEffectType hoverEffect);
60     static void SetPadding(FrameNode* frameNode, const NG::PaddingProperty& newArgs);
61     static void SetResponseRegion(FrameNode* frameNode, const std::vector<DimensionRect>& responseRegion);
62     static void SetBuilderFunc(FrameNode* frameNode, NG::RadioMakeCallback&& jsMake);
63     static void SetChangeValue(FrameNode* frameNode, bool value);
64     static void SetOnChange(FrameNode* frameNode, ChangeEvent&& onChange);
65     static bool GetChecked(FrameNode* frameNode);
66     static Color GetCheckedBackgroundColor(FrameNode* frameNode);
67     static Color GetUncheckedBorderColor(FrameNode* frameNode);
68     static Color GetIndicatorColor(FrameNode* frameNode);
69     static void SetRadioValue(FrameNode* frameNode, const std::string& value);
70     static std::string GetRadioValue(FrameNode* frameNode);
71     static void SetRadioGroup(FrameNode* frameNode, const std::string& value);
72     static std::string GetRadioGroup(FrameNode* frameNode);
73 };
74 } // namespace OHOS::Ace::NG
75 
76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RADIO_RADIO_MODEL_NG_H
77