1 /* 2 * Copyright (c) 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_PATTERN_SELECT_SELECT_MODEL_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_MODEL_NG_H 18 19 #include "core/components_ng/base/common_configuration.h" 20 #include "core/components_ng/base/symbol_modifier.h" 21 #include "core/components_ng/pattern/select/select_model.h" 22 23 namespace OHOS::Ace::NG { 24 class MenuItemConfiguration : public CommonConfiguration { 25 public: MenuItemConfiguration(const std::string & value,const std::string & icon,RefPtr<SymbolModifier> symbolModifier,int index,bool selected,bool enabled)26 MenuItemConfiguration(const std::string& value, const std::string& icon, 27 RefPtr<SymbolModifier> symbolModifier, int index, bool selected, bool enabled) 28 : CommonConfiguration(enabled), value_(value), icon_(icon), symbolModifier_(symbolModifier), 29 index_(index), selected_(selected) {} 30 std::string value_; 31 std::string icon_; 32 RefPtr<SymbolModifier> symbolModifier_; 33 int index_; 34 bool selected_; 35 }; 36 using SelectMakeCallback = 37 std::function<RefPtr<FrameNode>(const MenuItemConfiguration menuItemConfiguration)>; 38 class ACE_EXPORT SelectModelNG : public OHOS::Ace::SelectModel { 39 public: 40 void Create(const std::vector<SelectParam>& params) override; 41 void SetSelected(int32_t idx) override; 42 void SetValue(const std::string& value) override; 43 void SetFontSize(const Dimension& value) override; 44 void SetFontWeight(const FontWeight& value) override; 45 void SetFontFamily(const std::vector<std::string>& value) override; 46 void SetItalicFontStyle(const Ace::FontStyle& value) override; 47 void SetFontColor(const Color& color) override; 48 void SetSelectedOptionBgColor(const Color& color) override; 49 void SetSelectedOptionFontSize(const Dimension& value) override; 50 void SetSelectedOptionFontWeight(const FontWeight& value) override; 51 void SetSelectedOptionFontFamily(const std::vector<std::string>& value) override; 52 void SetSelectedOptionItalicFontStyle(const Ace::FontStyle& value) override; 53 void SetSelectedOptionFontColor(const Color& color) override; 54 void SetOptionBgColor(const Color& color) override; 55 void SetOptionFontSize(const Dimension& value) override; 56 void SetOptionFontWeight(const FontWeight& value) override; 57 void SetOptionFontFamily(const std::vector<std::string>& value) override; 58 void SetOptionItalicFontStyle(const Ace::FontStyle& value) override; 59 void SetOptionFontColor(const Color& color) override; 60 void SetOnSelect(NG::SelectEvent&& onSelect) override; 61 void SetWidth(Dimension& value) override; 62 void SetHeight(Dimension& value) override; 63 void SetSize(Dimension& width, Dimension& height) override; 64 void SetPaddings(const std::optional<CalcDimension>& top, const std::optional<CalcDimension>& bottom, 65 const std::optional<CalcDimension>& left, const std::optional<CalcDimension>& right) override; 66 void SetPadding(const CalcDimension& value) override; 67 void SetPaddingLeft(const CalcDimension& value) override; 68 void SetPaddingTop(const CalcDimension& value) override; 69 void SetPaddingRight(const CalcDimension& value) override; 70 void SetPaddingBottom(const CalcDimension& value) override; 71 void SetSpace(const Dimension& value) override; 72 void SetArrowPosition(const ArrowPosition value) override; 73 void SetMenuAlign(const MenuAlign& menuAlign) override; 74 void SetSelectChangeEvent(NG::SelectChangeEvent&& selectChangeEvent) override; 75 void SetValueChangeEvent(NG::ValueChangeEvent&& valueChangeEvent) override; 76 void SetHasOptionWidth(bool hasOptionWidth) override; 77 void SetMenuBackgroundColor(const Color& color) override; 78 void SetMenuBackgroundBlurStyle(const BlurStyleOption& blurStyle) override; 79 void SetDivider(const NG::SelectDivider& divider) override; 80 static void SetDivider(FrameNode* frameNode, const NG::SelectDivider& divider); 81 void SetControlSize(const std::optional<ControlSize>& controlSize) override; 82 void SetLayoutDirection(TextDirection value) override; 83 static void SetBuilderFunc(FrameNode* frameNode, NG::SelectMakeCallback&& makeFunc); 84 static void ResetBuilderFunc(FrameNode* frameNode); 85 static void SetChangeValue(FrameNode* frameNode, int index, const std::string& value); 86 ControlSize GetControlSize() override; 87 88 static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId); 89 static void InitSelect(FrameNode* frameNode, const std::vector<SelectParam>& params); 90 static void SetControlSize(FrameNode* frameNode, const std::optional<ControlSize>& controlSize); 91 static ControlSize GetControlSize(FrameNode* frameNode); 92 static void SetArrowPosition(FrameNode* frameNode, const ArrowPosition value); 93 static void SetSpace(FrameNode* frameNode, const Dimension& value); 94 static void SetMenuAlign(FrameNode* frameNode, const MenuAlign& menuAlign); 95 static void SetValue(FrameNode* frameNode, const std::string& value); 96 static void SetSelected(FrameNode* frameNode, int32_t idx); 97 static void SetFontSize(FrameNode* frameNode, const Dimension& value); 98 static void SetFontWeight(FrameNode* frameNode, const FontWeight& value); 99 static void SetFontFamily(FrameNode* frameNode, const std::vector<std::string>& value); 100 static void SetItalicFontStyle(FrameNode* frameNode, const Ace::FontStyle& value); 101 static void SetFontColor(FrameNode* frameNode, const Color& color); 102 static void SetSelectedOptionBgColor(FrameNode* frameNode, const Color& color); 103 static void SetOptionFontSize(FrameNode* frameNode, const Dimension& value); 104 static void SetOptionFontWeight(FrameNode* frameNode, const FontWeight& value); 105 static void SetOptionFontFamily(FrameNode* frameNode, const std::vector<std::string>& value); 106 static void SetOptionItalicFontStyle(FrameNode* frameNode, const Ace::FontStyle& value); 107 static void SetOptionFontColor(FrameNode* frameNode, const Color& color); 108 static void SetOptionBgColor(FrameNode* frameNode, const Color& color); 109 static void SetSelectedOptionFontColor(FrameNode* frameNode, const Color& color); 110 static void SetSelectedOptionFontSize(FrameNode* frameNode, const Dimension& value); 111 static void SetSelectedOptionFontWeight(FrameNode* frameNode, const FontWeight& value); 112 static void SetSelectedOptionFontFamily(FrameNode* frameNode, const std::vector<std::string>& value); 113 static void SetSelectedOptionItalicFontStyle(FrameNode* frameNode, const Ace::FontStyle& value); 114 void SetOptionWidth(const Dimension& value) override; 115 void SetOptionHeight(const Dimension& value) override; 116 void SetOptionWidthFitTrigger(bool isFitTrigger) override; 117 static void SetOptionWidth(FrameNode* frameNode, const Dimension& value); 118 static void SetHasOptionWidth(FrameNode* frameNode, bool hasOptionWidth); 119 static void SetOptionHeight(FrameNode* frameNode, const Dimension& value); 120 static void SetOptionWidthFitTrigger(FrameNode* frameNode, bool isFitTrigger); 121 static void SetMenuBackgroundColor(FrameNode* frameNode, const Color& color); 122 static void SetMenuBackgroundBlurStyle(FrameNode* frameNode, const BlurStyleOption& blurStyle); 123 static void SetOnSelect(FrameNode* frameNode, NG::SelectEvent&& onSelect); 124 }; 125 } // namespace OHOS::Ace::NG 126 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_MODEL_NG_H 127