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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CHECKBOX_CHECKBOX_MODEL_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CHECKBOX_CHECKBOX_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/checkbox/checkbox_model.h" 22 23 namespace OHOS::Ace::NG { 24 class CheckBoxConfiguration : public CommonConfiguration { 25 public: CheckBoxConfiguration(const std::string & name,bool selected,bool enabled)26 CheckBoxConfiguration(const std::string& name, bool selected, bool enabled) 27 : CommonConfiguration(enabled), name_(name), selected_(selected) 28 {} 29 std::string name_; 30 bool selected_; 31 }; 32 using CheckBoxMakeCallback = 33 std::function<RefPtr<FrameNode>(const CheckBoxConfiguration& checkBoxConfiguration)>; 34 class ACE_EXPORT CheckBoxModelNG : public OHOS::Ace::CheckBoxModel { 35 public: 36 void Create(const std::optional<std::string>& name, const std::optional<std::string>& groupName, 37 const std::string& tagName) override; 38 void SetSelect(bool isSelected) override; 39 void SetSelectedColor(const Color& color) override; 40 void SetUnSelectedColor(const Color& color) override; 41 void SetBuilder(std::optional<std::function<void(void)>>& buildFunc) override; 42 void SetCheckMarkColor(const Color& color) override; 43 void SetCheckMarkSize(const Dimension& size) override; 44 void SetCheckMarkWidth(const Dimension& width) override; 45 void SetOnChange(ChangeEvent&& onChange) override; 46 void SetWidth(const Dimension& width) override; 47 void SetHeight(const Dimension& height) override; 48 void SetPadding(const NG::PaddingPropertyF& args, const NG::PaddingProperty& newArgs, bool flag) override; 49 void SetChangeEvent(ChangeEvent&& changeEvent) override; 50 void SetResponseRegion(const std::vector<DimensionRect>& responseRegion) override; 51 void SetCheckboxStyle(CheckBoxStyle checkboxStyle) override; 52 53 static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId); 54 static void SetSelect(FrameNode* frameNode, bool isSelected); 55 static void SetSelectedColor(FrameNode* frameNode, const Color& color); 56 static void SetUnSelectedColor(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 SetCheckMarkColor(FrameNode* frameNode, const Color& color); 60 static void SetCheckMarkSize(FrameNode* frameNode, const Dimension& size); 61 static void SetCheckMarkWidth(FrameNode* frameNode, const Dimension& width); 62 static void SetPadding(FrameNode* frameNode, const NG::PaddingProperty& padding); 63 static void SetResponseRegion(FrameNode* frameNode, const std::vector<DimensionRect>& responseRegion); 64 static void SetBuilderFunc(FrameNode* frameNode, NG::CheckBoxMakeCallback&& jsMake); 65 static void SetChangeValue(FrameNode* frameNode, bool value); 66 static void SetCheckboxStyle(FrameNode* frameNode, CheckBoxStyle checkboxStyle); 67 68 static bool GetSelect(FrameNode* frameNode); 69 static Color GetSelectedColor(FrameNode* frameNode); 70 static Color GetUnSelectedColor(FrameNode* frameNode); 71 static Color GetCheckMarkColor(FrameNode* frameNode); 72 static Dimension GetCheckMarkSize(FrameNode* frameNode); 73 static Dimension GetCheckMarkWidth(FrameNode* frameNode); 74 static CheckBoxStyle GetCheckboxStyle(FrameNode* frameNode); 75 76 static void SetOnChange(FrameNode* frameNode, ChangeEvent&& onChange); 77 }; 78 } // namespace OHOS::Ace::NG 79 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CHECKBOX_CHECKBOX_MODEL_NG_H 80