• 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_NAVIGATION_BAR_NAVIGATION_BAR_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_BAR_THEME_H
18 
19 #include "core/components/theme/theme.h"
20 #include "core/components/theme/theme_constants.h"
21 #include "core/components/theme/theme_constants_defines.h"
22 
23 namespace OHOS::Ace {
24 
25 class NavigationBarTheme : public virtual Theme {
26     DECLARE_ACE_TYPE(NavigationBarTheme, Theme);
27 
28 public:
29     class Builder {
30     public:
31         Builder() = default;
32         ~Builder() = default;
33 
Build(const RefPtr<ThemeConstants> & themeConstants)34         RefPtr<NavigationBarTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
35         {
36             RefPtr<NavigationBarTheme> theme = AceType::Claim(new NavigationBarTheme());
37             if (!themeConstants) {
38                 return theme;
39             }
40             theme->titleColor_ = themeConstants->GetColor(THEME_NAVIGATION_BAR_TITLE_COLOR);
41             theme->titleFontSize_ = Dimension(
42                 themeConstants->GetDimension(THEME_NAVIGATION_BAR_TITLE_FONT_SIZE).Value(), DimensionUnit::VP);
43             theme->titleFontSizeBig_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_TITLE_FONT_SIZE_BIG);
44             theme->subTitleColor_ = themeConstants->GetColor(THEME_NAVIGATION_BAR_SUBTITLE_COLOR);
45             theme->subTitleFontSize_ = Dimension(
46                 themeConstants->GetDimension(THEME_NAVIGATION_BAR_SUBTITLE_FONT_SIZE).Value(), DimensionUnit::VP);
47             theme->height_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_HEIGHT);
48             theme->heightEmphasize_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_HEIGHT_EMPHASIZE);
49             theme->backResourceId_ = themeConstants->GetResourceId(THEME_NAVIGATION_BAR_RESOURCE_ID_BACK);
50             theme->moreResourceId_ = themeConstants->GetResourceId(THEME_NAVIGATION_BAR_RESOURCE_ID_MORE);
51             theme->menuZoneSize_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_MENU_ZONE_SIZE);
52             theme->menuIconSize_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_MENU_ICON_SIZE);
53             theme->logoIconSize_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_LOGO_ICON_SIZE);
54             theme->buttonNormalColor_ = themeConstants->GetColor(THEME_NAVIGATION_BAR_BUTTON_NORMAL_COLOR);
55             theme->buttonPressedColor_ = themeConstants->GetColor(THEME_NAVIGATION_BAR_BUTTON_PRESSED_COLOR);
56             theme->buttonFocusColor_ = themeConstants->GetColor(THEME_NAVIGATION_BAR_BUTTON_FOCUS_COLOR);
57             theme->buttonCornerRadius_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_BUTTON_CORNER_RADIUS);
58             theme->maxPaddingStart_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_MAX_PADDING_START);
59             theme->maxPaddingEnd_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_MAX_PADDING_END);
60             theme->defaultPaddingStart_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_DEFAULT_PADDING_START);
61             theme->defaultPaddingEnd_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_DEFAULT_PADDING_END);
62             theme->menuItemPadding_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_MENU_ITEM_PADDING);
63             theme->titleMinPadding_ = themeConstants->GetDimension(THEME_NAVIGATION_BAR_TITLE_MIN_PADDING);
64             auto menuCount = themeConstants->GetInt(THEME_NAVIGATION_BAR_MOST_MENU_ITEM_COUNT_IN_BAR);
65             theme->mostMenuItemCountInBar_ =
66                 menuCount < 0 ? theme->mostMenuItemCountInBar_ : static_cast<uint32_t>(menuCount);
67 
68             auto themeStyle = themeConstants->GetThemeStyle();
69             if (!themeStyle) {
70                 return theme;
71             }
72             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_NAVIGATION_BAR, nullptr);
73             if (pattern) {
74                 theme->titleColor_ = pattern->GetAttr<Color>("title_color", Color::WHITE);
75                 theme->titleFontSize_  = pattern->GetAttr<Dimension>("title_text_font_size", 0.0_vp);
76                 theme->titleFontSizeMin_ = pattern->GetAttr<Dimension>("title_text_font_size_min", 0.0_vp);
77                 theme->titleFontSizeBig_  = pattern->GetAttr<Dimension>("title_text_font_size_big", 0.0_vp);
78                 theme->subTitleColor_ = pattern->GetAttr<Color>("sub_title_text_color", Color::WHITE);
79                 theme->subTitleFontSize_  = pattern->GetAttr<Dimension>("sub_title_text_font_size", 0.0_vp);
80                 theme->menuIconColor_ = pattern->GetAttr<Color>("menu_icon_color", Color::WHITE);
81                 theme->buttonPressedColor_ = pattern->GetAttr<Color>("button_bg_color_pressed", Color::WHITE);
82                 theme->buttonFocusColor_ = pattern->GetAttr<Color>("button_bg_color_focused", Color::WHITE);
83                 theme->buttonHoverColor_ = pattern->GetAttr<Color>("button_bg_color_hovered", Color::WHITE);
84                 theme->buttonCornerRadius_  = pattern->GetAttr<Dimension>("button_corner_radius", 0.0_vp);
85                 theme->maxPaddingStart_ = pattern->GetAttr<Dimension>("title_left_spacing", 0.0_vp);
86                 theme->maxPaddingEnd_ = pattern->GetAttr<Dimension>("title_right_spacing", 0.0_vp);
87                 theme->defaultPaddingStart_ = pattern->GetAttr<Dimension>("back_button_left_spacing", 0.0_vp);
88                 theme->backButtonIconColor_ = pattern->GetAttr<Color>("back_button_icon_color", Color::WHITE);
89                 theme->alphaDisabled_ = pattern->GetAttr<double>("button_alpha_disabled", 0.0);
90             }
91             return theme;
92         }
93     };
94 
95     ~NavigationBarTheme() override = default;
96 
GetTitleColor()97     const Color& GetTitleColor() const
98     {
99         return titleColor_;
100     }
101 
GetSubTitleColor()102     const Color& GetSubTitleColor() const
103     {
104         return subTitleColor_;
105     }
GetTitleFontSizeBig()106     const Dimension& GetTitleFontSizeBig() const
107     {
108         return titleFontSizeBig_;
109     }
110 
GetTitleFontSize()111     const Dimension& GetTitleFontSize() const
112     {
113         return titleFontSize_;
114     }
115 
GetTitleFontSizeMin()116     const Dimension& GetTitleFontSizeMin() const
117     {
118         return titleFontSizeMin_;
119     }
120 
GetSubTitleFontSize()121     const Dimension& GetSubTitleFontSize() const
122     {
123         return subTitleFontSize_;
124     }
GetHeight()125     const Dimension& GetHeight() const
126     {
127         return height_;
128     }
GetHeightEmphasize()129     const Dimension& GetHeightEmphasize() const
130     {
131         return heightEmphasize_;
132     }
GetBackResourceId()133     InternalResource::ResourceId GetBackResourceId() const
134     {
135         return backResourceId_;
136     }
GetMoreResourceId()137     InternalResource::ResourceId GetMoreResourceId() const
138     {
139         return moreResourceId_;
140     }
GetMenuZoneSize()141     const Dimension& GetMenuZoneSize() const
142     {
143         return menuZoneSize_;
144     }
GetMenuIconSize()145     const Dimension& GetMenuIconSize() const
146     {
147         return menuIconSize_;
148     }
GetLogoIconSize()149     const Dimension& GetLogoIconSize() const
150     {
151         return logoIconSize_;
152     }
GetMenuIconColor()153     const Color& GetMenuIconColor() const
154     {
155         return menuIconColor_;
156     }
GetButtonNormalColor()157     const Color& GetButtonNormalColor() const
158     {
159         return buttonNormalColor_;
160     }
GetButtonPressedColor()161     const Color& GetButtonPressedColor() const
162     {
163         return buttonPressedColor_;
164     }
GetButtonFocusColor()165     const Color& GetButtonFocusColor() const
166     {
167         return buttonFocusColor_;
168     }
GetButtonHoverColor()169     const Color& GetButtonHoverColor() const
170     {
171         return buttonHoverColor_;
172     }
GetButtonCornerRadius()173     const Dimension& GetButtonCornerRadius() const
174     {
175         return buttonCornerRadius_;
176     }
GetMaxPaddingStart()177     const Dimension& GetMaxPaddingStart() const
178     {
179         return maxPaddingStart_;
180     }
GetDefaultPaddingStart()181     const Dimension& GetDefaultPaddingStart() const
182     {
183         return defaultPaddingStart_;
184     }
GetDefaultPaddingEnd()185     const Dimension& GetDefaultPaddingEnd() const
186     {
187         return defaultPaddingEnd_;
188     }
GetMaxPaddingEnd()189     const Dimension& GetMaxPaddingEnd() const
190     {
191         return maxPaddingEnd_;
192     }
GetMenuItemPadding()193     const Dimension& GetMenuItemPadding() const
194     {
195         return menuItemPadding_;
196     }
GetTitleMinPadding()197     const Dimension& GetTitleMinPadding() const
198     {
199         return titleMinPadding_;
200     }
GetMostMenuItemCountInBar()201     uint32_t GetMostMenuItemCountInBar() const
202     {
203         return mostMenuItemCountInBar_;
204     }
GetBackButtonIconColor()205     const Color& GetBackButtonIconColor() const
206     {
207         return backButtonIconColor_;
208     }
GetAlphaDisabled()209     double GetAlphaDisabled() const
210     {
211         return alphaDisabled_;
212     }
213 
214 protected:
215     NavigationBarTheme() = default;
216 
217 private:
218     Color titleColor_;
219     Color subTitleColor_;
220     Dimension titleFontSizeBig_;
221     Dimension titleFontSize_;
222     Dimension titleFontSizeMin_;
223     Dimension subTitleFontSize_;
224     Dimension height_;
225     Dimension heightEmphasize_;
226     InternalResource::ResourceId backResourceId_ = InternalResource::ResourceId::NO_ID;
227     InternalResource::ResourceId moreResourceId_ = InternalResource::ResourceId::NO_ID;
228     Dimension menuZoneSize_;
229     Dimension menuIconSize_;
230     Dimension logoIconSize_;
231     Color menuIconColor_;
232     Color buttonNormalColor_;
233     Color buttonPressedColor_;
234     Color buttonFocusColor_;
235     Color buttonHoverColor_;
236     Dimension buttonCornerRadius_;
237     Dimension maxPaddingStart_;
238     Dimension maxPaddingEnd_;
239     Dimension defaultPaddingStart_;
240     Dimension defaultPaddingEnd_;
241     Dimension menuItemPadding_;
242     Dimension titleMinPadding_;
243     uint32_t mostMenuItemCountInBar_ = 0;
244     Color backButtonIconColor_;
245     double alphaDisabled_ = 0.0;
246 };
247 
248 } // namespace OHOS::Ace
249 
250 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATION_BAR_NAVIGATION_BAR_THEME_H
251