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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_BUTTON_MODEL_IMPL_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_BUTTON_MODEL_IMPL_H
18 
19 #include "core/components/button/button_component.h"
20 #include "core/components/text/text_component.h"
21 #include "core/components_ng/pattern/button/button_model.h"
22 
23 namespace OHOS::Ace::Framework {
24 class ButtonModelImpl : public OHOS::Ace::ButtonModel {
25 public:
26     void SetFontSize(const Dimension& fontSize) override;
27     void SetFontWeight(const Ace::FontWeight& fontWeight) override;
28     void SetFontStyle(const Ace::FontStyle& fontStyle) override;
29     void SetFontFamily(const std::vector<std::string>& fontFamily) override;
30     void SetFontColor(const Color& textColor) override;
31     void SetType(const int value) override;
32     void SetStateEffect(const bool stateEffect) override;
33     void CreateWithLabel(const CreateWithPara& para, std::list<RefPtr<Component>>& buttonChildren) override;
34     void Create(const CreateWithPara& para, std::list<RefPtr<Component>>& buttonChildren) override;
35     void CreateWithChild(const CreateWithPara& para) override;
36     void Padding(const NG::PaddingProperty& paddingNew, const Edge& paddingOld) override;
37     void OnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc) override;
38     void BackgroundColor(const Color& color, const bool& colorFlag) override;
39     void SetWidth(const Dimension& width) override;
40     void SetHeight(const Dimension& height) override;
41     void SetAspectRatio(const double& ratio) override;
42     void SetSize(const std::optional<Dimension>& width, const std::optional<Dimension>& height) override;
43     void SetBorderRadius(const Dimension& radius) override;
SetBorderRadius(const std::optional<Dimension> & radiusTopLeft,const std::optional<Dimension> & radiusTopRight,const std::optional<Dimension> & radiusBottomLeft,const std::optional<Dimension> & radiusBottomRight)44     void SetBorderRadius(const std::optional<Dimension>& radiusTopLeft, const std::optional<Dimension>& radiusTopRight,
45         const std::optional<Dimension>& radiusBottomLeft,
46         const std::optional<Dimension>& radiusBottomRight) override {};
47     void SetRemoteMessage(RemoteCallback&& remoteCallback) override;
48 
49 private:
50     static RefPtr<TextComponent> GetTextComponent();
51     static void ResetButtonHeight();
52     static void SetTypeAndStateEffect(const std::optional<ButtonType>& type, const std::optional<bool>& stateEffect,
53         const RefPtr<ButtonComponent>& buttonComponent);
54     static void SetDefaultAttributes(const RefPtr<ButtonComponent>& buttonComponent);
55 };
56 } // namespace OHOS::Ace::Framework
57 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_BUTTON_MODEL_IMPL_H
58