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_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_MODEL_H 18 19 #include <optional> 20 #include <string_view> 21 22 #include "base/utils/macros.h" 23 #include "core/components/common/properties/color.h" 24 #include "core/components_ng/base/symbol_modifier.h" 25 #include "core/components_ng/pattern/select/select_event_hub.h" 26 #include "core/components_ng/pattern/select/select_properties.h" 27 #include "core/components_ng/pattern/text/text_styles.h" 28 29 namespace OHOS::Ace { 30 enum class ArrowPosition { 31 END = 0, 32 START, 33 }; 34 35 enum class MenuAlignType { 36 START = 0, 37 CENTER, 38 END, 39 }; 40 41 struct MenuAlign { 42 MenuAlignType alignType = MenuAlignType::START; 43 DimensionOffset offset = DimensionOffset(Dimension(0, DimensionUnit::VP), Dimension(0, DimensionUnit::VP)); 44 }; 45 46 enum class AvoidanceMode { 47 COVER_TARGET = 0, 48 AVOID_AROUND_TARGET, 49 }; 50 51 struct Avoidance { 52 AvoidanceMode mode = AvoidanceMode::COVER_TARGET; 53 }; 54 55 struct SelectParam { 56 std::string text; 57 std::string icon; 58 std::function<void(WeakPtr<NG::FrameNode>)> symbolIcon = nullptr; 59 RefPtr<SymbolModifier> symbolModifier = nullptr; 60 }; 61 62 class ACE_FORCE_EXPORT SelectModel { 63 public: 64 static SelectModel* GetInstance(); 65 virtual ~SelectModel() = default; 66 67 virtual void Create(const std::vector<SelectParam>& params); 68 virtual void SetSelected(int32_t idx); 69 virtual void SetValue(const std::string& value); 70 virtual void SetFontSize(const Dimension& value); 71 virtual void SetFontWeight(const FontWeight& value); 72 virtual void SetFontFamily(const std::vector<std::string>& value); 73 virtual void SetItalicFontStyle(const Ace::FontStyle& value); 74 virtual void SetFontColor(const Color& color); 75 virtual void SetSelectedOptionBgColor(const Color& color); 76 virtual void SetSelectedOptionFontSize(const Dimension& value); 77 virtual void SetSelectedOptionFontWeight(const FontWeight& value); 78 virtual void SetSelectedOptionFontFamily(const std::vector<std::string>& value); 79 virtual void SetSelectedOptionItalicFontStyle(const Ace::FontStyle& value); 80 virtual void SetSelectedOptionFontColor(const Color& color); 81 virtual void SetOptionBgColor(const Color& color); 82 virtual void SetOptionFontSize(const Dimension& value); 83 virtual void SetOptionFontWeight(const FontWeight& value); 84 virtual void SetOptionFontFamily(const std::vector<std::string>& value); 85 virtual void SetOptionItalicFontStyle(const Ace::FontStyle& value); 86 virtual void SetOptionFontColor(const Color& color); 87 virtual void SetOnSelect(NG::SelectEvent&& onSelect); 88 virtual void SetWidth(Dimension& value); 89 virtual void SetHeight(Dimension& value); 90 virtual void SetSize(Dimension& width, Dimension& height); 91 virtual void SetPaddings(const std::optional<CalcDimension>& top, const std::optional<CalcDimension>& bottom, 92 const std::optional<CalcDimension>& left, const std::optional<CalcDimension>& right); 93 virtual void SetPadding(const CalcDimension& value); 94 virtual void SetPaddingLeft(const CalcDimension& value); 95 virtual void SetPaddingTop(const CalcDimension& value); 96 virtual void SetPaddingRight(const CalcDimension& value); 97 virtual void SetPaddingBottom(const CalcDimension& value); 98 virtual void SetSpace(const Dimension& value); 99 virtual void SetArrowPosition(const ArrowPosition value); 100 virtual void SetMenuAlign(const MenuAlign& menuAlign); 101 virtual void SetAvoidance(const Avoidance& avoidance); 102 virtual void SetSelectChangeEvent(NG::SelectChangeEvent&& selectChangeEvent); 103 virtual void SetValueChangeEvent(NG::ValueChangeEvent&& valueChangeEvent); 104 virtual void SetOptionWidth(const Dimension& value); 105 virtual void SetOptionHeight(const Dimension& value); 106 virtual void SetOptionWidthFitTrigger(bool isFitTrigger); 107 virtual void SetHasOptionWidth(bool hasOptionWidth); 108 virtual void SetMenuBackgroundColor(const Color& color); 109 virtual void SetMenuBackgroundBlurStyle(const BlurStyleOption& blurStyle); 110 virtual void SetDivider(const NG::SelectDivider& divider); 111 virtual void SetDividerStyle(const NG::SelectDivider& divider, const DividerMode& mode); 112 virtual void SetControlSize(const std::optional<ControlSize>& controlSize); 113 virtual void SetLayoutDirection(TextDirection value); 114 virtual ControlSize GetControlSize(); 115 virtual void BackgroundColor(const Color& color) = 0; 116 virtual void ResetBackgroundColor() = 0; ResetFontColor()117 virtual void ResetFontColor() {}; 118 119 private: 120 static std::unique_ptr<SelectModel> instance_; 121 static std::mutex mutex_; 122 }; 123 } // namespace OHOS::Ace 124 125 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_MODEL_H 126