• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_COUNTER_COUNTER_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_COUNTER_COUNTER_THEME_H
18 
19 #include "core/components/common/properties/color.h"
20 #include "core/components/common/properties/edge.h"
21 #include "core/components/common/properties/radius.h"
22 #include "core/components/common/properties/text_style.h"
23 #include "core/components/theme/theme.h"
24 #include "core/components/theme/theme_constants.h"
25 #include "core/components/theme/theme_constants_defines.h"
26 #include "core/components_ng/property/border_property.h"
27 
28 namespace OHOS::Ace {
29 namespace {
30 constexpr double BUTTON_ALPHA_DISABLED = 0.4;
31 } // namespace
32 class CounterTheme : public virtual Theme {
33     DECLARE_ACE_TYPE(CounterTheme, Theme);
34 
35 public:
36     class Builder {
37     public:
38         Builder() = default;
39         ~Builder() = default;
40 
Build(const RefPtr<ThemeConstants> & themeConstants)41         RefPtr<CounterTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
42         {
43             RefPtr<CounterTheme> theme = AceType::MakeRefPtr<CounterTheme>();
44             if (!themeConstants) {
45                 return theme;
46             }
47 
48             // init theme from global data
49             theme->contentTextStyle_.SetFontSize(themeConstants->GetDimension(THEME_COUNTER_TITLE_FONTSIZE));
50             theme->contentTextStyle_.SetTextColor(themeConstants->GetColor(THEME_COUNTER_FONTCOLOR));
51             theme->backgroundColor_ = themeConstants->GetColor(THEME_COUNTER_BACKGROUND_COLOR);
52             auto themeStyle = themeConstants->GetThemeStyle();
53             if (!themeStyle) {
54                 return theme;
55             }
56             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_COUNTER, nullptr);
57             if (pattern) {
58                 theme->alphaDisabled_ = pattern->GetAttr<double>("button_alpha_disabled", BUTTON_ALPHA_DISABLED);
59             }
60             return theme;
61         }
62     };
63 
64     ~CounterTheme() override = default;
65 
GetContentTextStyle()66     const TextStyle& GetContentTextStyle() const
67     {
68         return contentTextStyle_;
69     }
70 
GetAlphaDisabled()71     double GetAlphaDisabled() const
72     {
73         return alphaDisabled_;
74     }
75 
GetBackGroundColor()76     const Color& GetBackGroundColor() const
77     {
78         return backgroundColor_;
79     }
80 
GetHeight()81     const Dimension& GetHeight() const
82     {
83         return height_;
84     }
85 
GetWidth()86     const Dimension& GetWidth() const
87     {
88         return width_;
89     }
90 
GetControlWidth()91     const Dimension& GetControlWidth() const
92     {
93         return controlWidth_;
94     }
95 
GetContentWidth()96     const Dimension& GetContentWidth() const
97     {
98         return contentWidth_;
99     }
100 
GetBorderRadius()101     const NG::BorderRadiusProperty& GetBorderRadius() const
102     {
103         return borderRadius_;
104     }
105 
GetBorderWidth()106     const NG::BorderWidthProperty& GetBorderWidth() const
107     {
108         return borderWidth_;
109     }
110 
GetContentBorderWidth()111     const NG::BorderWidthProperty& GetContentBorderWidth() const
112     {
113         return contentBorderWidth_;
114     }
115 
GetBorderColor()116     const NG::BorderColorProperty& GetBorderColor() const
117     {
118         return borderColor_;
119     }
120 
GetBorderStyle()121     const NG::BorderStyleProperty& GetBorderStyle() const
122     {
123         return borderStyle_;
124     }
125 
126 private:
127     TextStyle contentTextStyle_;
128     Color backgroundColor_ = Color(0xff191919);
129     Dimension height_ = 32.0_vp;
130     Dimension width_ = 100.0_vp;
131     Dimension controlWidth_ = 32.0_vp;
132     Dimension contentWidth_ = 36.0_vp;
133     double alphaDisabled_ = 0.4;
134     NG::BorderRadiusProperty borderRadius_ = { 4.0_vp, 4.0_vp, 4.0_vp, 4.0_vp };
135     NG::BorderWidthProperty borderWidth_ = { 1.0_vp, 1.0_vp, 1.0_vp, 1.0_vp };
136     NG::BorderWidthProperty contentBorderWidth_ = { 0.0_vp, 1.0_vp, 0.0_vp, 1.0_vp };
137     NG::BorderColorProperty borderColor_ = { Color::GRAY, Color::GRAY, Color::GRAY, Color::GRAY };
138     NG::BorderStyleProperty borderStyle_ = { BorderStyle::SOLID, BorderStyle::SOLID, BorderStyle::SOLID,
139         BorderStyle::SOLID };
140 };
141 
142 } // namespace OHOS::Ace
143 
144 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_COUNTER_COUNTER_THEME_H
145