• 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_BADGE_BADGE_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BADGE_BADGE_THEME_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "core/components/common/properties/color.h"
21 #include "core/components/theme/theme.h"
22 #include "core/components/theme/theme_constants.h"
23 #include "core/components/theme/theme_constants_defines.h"
24 #include "core/components/theme/theme_manager.h"
25 
26 namespace OHOS::Ace {
27 
28 class BadgeTheme : public virtual Theme {
29     DECLARE_ACE_TYPE(BadgeTheme, Theme);
30 
31 public:
32     class Builder {
33     public:
34         Builder() = default;
35         ~Builder() = default;
36 
Build(const RefPtr<ThemeConstants> & themeConstants)37         RefPtr<BadgeTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
38         {
39             RefPtr<BadgeTheme> theme = AceType::Claim(new BadgeTheme());
40             if (!themeConstants) {
41                 return theme;
42             }
43             ParsePattern(themeConstants, theme);
44             return theme;
45         }
46 
47     private:
ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<BadgeTheme> & theme)48         void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<BadgeTheme>& theme) const
49         {
50             RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_BADGE);
51             if (!pattern) {
52                 LOGW("find pattern of badge fail");
53                 return;
54             }
55             theme->messageCount_ = static_cast<int32_t>(pattern->GetAttr<double>("badge_message_count", 0.0));
56             theme->badgePosition_ =
57                 BadgePosition(static_cast<int32_t>(pattern->GetAttr<double>("badge_position", 0.0)));
58             theme->showMessage_ = static_cast<int32_t>(pattern->GetAttr<double>("badge_show_message", 0.0));
59             theme->badgeColor_ = pattern->GetAttr<Color>(PATTERN_BG_COLOR, Color::BLACK);
60             theme->badgeFontSize_ = pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 0.0_vp);
61             theme->badgeTextColor_ = pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color::BLACK);
62             theme->badgeBorderColor_ = pattern->GetAttr<Color>(BADGE_BORDER_COLOR, Color::BLACK);
63             theme->badgeBorderWidth_ = pattern->GetAttr<Dimension>(BADGE_BORDER_WIDTH, 0.0_vp);
64         }
65     };
66 
67     ~BadgeTheme() override = default;
68 
GetBadgeColor()69     const Color& GetBadgeColor() const
70     {
71         return badgeColor_;
72     }
73 
GetMessageCount()74     int64_t GetMessageCount() const
75     {
76         return messageCount_;
77     }
78 
GetBadgePosition()79     BadgePosition GetBadgePosition() const
80     {
81         return badgePosition_;
82     }
83 
GetBadgePositionX()84     const Dimension& GetBadgePositionX() const
85     {
86         return badgePositionX_;
87     }
88 
GetBadgePositionY()89     const Dimension& GetBadgePositionY() const
90     {
91         return badgePositionY_;
92     }
93 
GetIsPositionXy()94     bool GetIsPositionXy() const
95     {
96         return isPositionXy_;
97     }
98 
GetShowMessage()99     bool GetShowMessage() const
100     {
101         return showMessage_;
102     }
103 
GetBadgeTextColor()104     const Color& GetBadgeTextColor() const
105     {
106         return badgeTextColor_;
107     }
108 
GetBadgeBorderColor()109     const Color& GetBadgeBorderColor() const
110     {
111         return badgeBorderColor_;
112     }
113 
GetBadgeFontSize()114     const Dimension& GetBadgeFontSize() const
115     {
116         return badgeFontSize_;
117     }
118 
GetBadgeCircleSize()119     const Dimension& GetBadgeCircleSize()
120     {
121         return badgeSize_;
122     }
123 
GetLittleBadgeCircleSize()124     const Dimension& GetLittleBadgeCircleSize()
125     {
126         return littleBadgeSize_;
127     }
128 
GetMaxCount()129     int GetMaxCount() const
130     {
131         return maxCount_;
132     }
133 
GetNumericalBadgePadding()134     const Dimension& GetNumericalBadgePadding()
135     {
136         return numericalBadgePadding_;
137     }
138 
GetBadgeBorderWidth()139     const Dimension& GetBadgeBorderWidth()
140     {
141         return badgeBorderWidth_;
142     }
143 
144 protected:
145     BadgeTheme() = default;
146 
147 private:
148     Color badgeColor_;
149     Color badgeTextColor_;
150     Color badgeBorderColor_;
151     int64_t messageCount_;
152     BadgePosition badgePosition_ = BadgePosition::RIGHT_TOP;
153     Dimension badgePositionX_ = 0.0_vp;
154     Dimension badgePositionY_ = 0.0_vp;
155     bool isPositionXy_ = false;
156     bool showMessage_;
157     Dimension badgeFontSize_;
158     Dimension badgeBorderWidth_;
159     Dimension badgeSize_ = 16.0_vp;
160     Dimension littleBadgeSize_ = 6.0_vp;
161     Dimension numericalBadgePadding_ = 6.0_vp;
162     int maxCount_ = 99;
163 };
164 
165 } // namespace OHOS::Ace
166 
167 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BADGE_BADGE_THEME_H
168