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_PATTERNS_BUTTON_BUTTON_MODEL_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUTTON_BUTTON_MODEL_NG_H 18 19 #include "core/components_ng/base/common_configuration.h" 20 #include "core/components_ng/pattern/button/button_model.h" 21 #include "core/components/button/button_theme.h" 22 23 namespace OHOS::Ace::NG { 24 class ButtonConfiguration : public CommonConfiguration { 25 public: ButtonConfiguration(const std::string & label,bool pressed,bool enabled)26 ButtonConfiguration(const std::string& label, bool pressed, bool enabled) 27 : CommonConfiguration(enabled), label_(label), pressed_(pressed) 28 {} 29 std::string label_; 30 bool pressed_; 31 }; 32 using ButtonMakeCallback = 33 std::function<RefPtr<FrameNode>(const ButtonConfiguration& buttonConfiguration)>; 34 class ACE_EXPORT ButtonModelNG : public OHOS::Ace::ButtonModel { 35 public: 36 void SetFontSize(const Dimension& fontSize) override; 37 void SetFontWeight(const Ace::FontWeight& fontWeight) override; 38 void SetFontStyle(const Ace::FontStyle& fontStyle) override; 39 void SetFontFamily(const std::vector<std::string>& fontFamily) override; 40 void SetFontColor(const Color& textColor) override; 41 void SetType(const int value) override; 42 void SetStateEffect(const bool stateEffect) override; 43 void SetLabelStyle(ButtonParameters& buttonParameters) override; 44 void CreateWithLabel(const CreateWithPara& para, std::list<RefPtr<Component>>& buttonChildren) override; 45 void Create(const CreateWithPara& para, std::list<RefPtr<Component>>& buttonChildren) override; 46 void CreateWithChild(const CreateWithPara& para) override; 47 void Padding(const PaddingProperty& paddingNew, const Edge& paddingOld) override; 48 void OnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc, double distanceThreshold) override; 49 void BackgroundColor(const Color& color, const bool& colorFlag) override; 50 void SetSize(const std::optional<Dimension>& width, const std::optional<Dimension>& height) override; 51 void SetBorderRadius(const Dimension& radius) override; 52 void SetBorderRadius(const std::optional<Dimension>& radiusTopLeft, const std::optional<Dimension>& radiusTopRight, 53 const std::optional<Dimension>& radiusBottomLeft, const std::optional<Dimension>& radiusBottomRight) override; 54 void SetLocalizedBorderRadius(const std::optional<Dimension>& radiusTopStart, 55 const std::optional<Dimension>& radiusTopEnd, const std::optional<Dimension>& radiusBottomStart, 56 const std::optional<Dimension>& radiusBottomEnd) override; 57 void ResetBorderRadius() override; 58 void SetButtonStyle(const std::optional<ButtonStyleMode>& buttonStyle) override; 59 void SetControlSize(const std::optional<ControlSize>& controlSize) override; 60 void SetRole(const std::optional<ButtonRole>& buttonRole) override; 61 void SetCreateWithLabel(bool createWithLabel) override; 62 void SetMinFontScale(float minFontScale) override; 63 void SetMaxFontScale(float maxFontScale) override; 64 static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId); 65 static void SetFontSize(FrameNode* frameNode, const Dimension& fontSize); 66 static void SetFontWeight(FrameNode* frameNode, const Ace::FontWeight& fontWeight); 67 static void SetFontStyle(FrameNode* frameNode, const Ace::FontStyle& fontStyle); 68 static void SetFontFamily(FrameNode* frameNode, const std::vector<std::string>& fontFamily); 69 static void SetFontColor(FrameNode* frameNode, const Color& textColor); 70 static void SetType(FrameNode* frameNode, const int value); 71 static void SetStateEffect(FrameNode* frameNode, const bool stateEffect); 72 static void SetLabelStyle(FrameNode* frameNode, const ButtonParameters& buttonParameters); 73 static void BackgroundColor(FrameNode* frameNode, const Color& color, const bool& colorFlag); 74 static void SetBorderRadius(FrameNode* frameNode, const Dimension& radius); 75 static void SetBorderRadius(FrameNode* frameNode, const std::optional<Dimension>& radiusTopLeft, 76 const std::optional<Dimension>& radiusTopRight, const std::optional<Dimension>& radiusBottomLeft, 77 const std::optional<Dimension>& radiusBottomRight); 78 static void SetSize( 79 FrameNode* frameNode, const std::optional<Dimension>& width, const std::optional<Dimension>& height); 80 static void SetLabel(FrameNode* frameNode, const char* label); 81 static std::string GetLabel(FrameNode* frameNode); 82 static Dimension GetFontSize(FrameNode* frameNode); 83 static Ace::FontWeight GetFontWeight(FrameNode* frameNode); 84 static Color GetFontColor(FrameNode* frameNode); 85 static void SetRole(FrameNode* frameNode, const std::optional<ButtonRole>& buttonRole); 86 static void SetButtonStyle(FrameNode* frameNode, const std::optional<ButtonStyleMode>& buttonStyle); 87 static void SetBuilderFunc(FrameNode* frameNode, NG::ButtonMakeCallback&& jsMake); 88 static void TriggerClick(FrameNode* frameNode, double xPos, double yPos); 89 static void SetControlSize(FrameNode* frameNode, const std::optional<ControlSize>& controlSize); 90 static ButtonType GetType(FrameNode* frameNode); 91 static void ApplyTheme(FrameNode* frameNode, ButtonStyleMode buttonStyle, ButtonRole buttonRole); 92 static void SetLabelWithCheck(FrameNode* frameNode, const char* label); 93 static void SetCreateWithLabel(FrameNode* frameNode, bool createWithLabel); 94 static bool GetAutoDisable(FrameNode* frameNode); 95 static void SetMinFontScale(FrameNode* frameNode, float minFontScale); 96 static void SetMaxFontScale(FrameNode* frameNode, float maxFontScale); 97 static float GetMinFontScale(FrameNode* frameNode); 98 static float GetMaxFontScale(FrameNode* frameNode); 99 100 private: 101 static void CreateWithLabel(const std::string& label); 102 static void Create(const std::string& tagName); 103 static void SetTypeAndStateEffect(const std::optional<ButtonType>& type, const std::optional<bool>& stateEffect); 104 static void SetTextDefaultStyle(const RefPtr<FrameNode>& textNode, const std::string& label); 105 static void SetButtonSize(FrameNode* frameNode, const std::optional<ControlSize>& controlSize, 106 RefPtr<ButtonTheme> buttonTheme); 107 }; 108 } // namespace OHOS::Ace::NG 109 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUTTON_BUTTON_MODEL_NG_H 110