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