• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_TAB_BAR_TAB_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_THEME_H
18 
19 #include "base/geometry/dimension.h"
20 #include "core/components/common/properties/text_style.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 
25 namespace OHOS::Ace {
26 
27 /**
28  * TabTheme defines color and styles of tab. TabTheme should be built
29  * using TabTheme::Builder.
30  */
31 class TabTheme : public virtual Theme {
32     DECLARE_ACE_TYPE(TabTheme, Theme);
33 
34 public:
35     class Builder {
36     public:
37         Builder() = default;
38         ~Builder() = default;
39 
Build(const RefPtr<ThemeConstants> & themeConstants)40         RefPtr<TabTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
41         {
42             RefPtr<TabTheme> theme = AceType::Claim(new TabTheme());
43             if (!themeConstants) {
44                 return theme;
45             }
46             theme->labelPadding_ = themeConstants->GetDimension(THEME_TAB_LABEL_PADDING);
47             theme->padding_ = themeConstants->GetDimension(THEME_TAB_PADDING);
48             theme->gradientWidth_ = themeConstants->GetDimension(THEME_TAB_GRADIENT_WIDTH);
49             theme->defaultHeight_ = themeConstants->GetDimension(THEME_TAB_DEFAULT_HEIGHT);
50             theme->defaultWidth_ = themeConstants->GetDimension(THEME_TAB_DEFAULT_WIDTH);
51             theme->defaultItemHeight_ = themeConstants->GetDimension(THEME_TAB_DEFAULT_ITEM_HEIGHT);
52             theme->backgroundColor_ = themeConstants->GetColor(THEME_TAB_BACKGROUND_COLOR);
53             theme->activeIndicatorColor_ = themeConstants->GetColor(THEME_TAB_ACTIVE_INDICATOR_COLOR);
54             theme->activeIndicatorWidth_ = themeConstants->GetDimension(THEME_TAB_ACTIVE_INDICATOR_WIDTH);
55             theme->activeIndicatorMinWidth_ = themeConstants->GetDimension(THEME_TAB_ACTIVE_INDICATOR_MIN_WIDTH);
56             theme->activeIndicatorPadding_ = themeConstants->GetDimension(THEME_TAB_ACTIVE_INDICATOR_PADDING);
57             theme->focusIndicatorColor_ = themeConstants->GetColor(THEME_TAB_FOCUS_INDICATOR_COLOR);
58             theme->focusIndicatorRadius_ = themeConstants->GetDimension(THEME_TAB_FOCUS_INDICATOR_RADIUS);
59             theme->focusIndicatorHorizontalPadding_ =
60                 themeConstants->GetDimension(THEME_TAB_FOCUS_INDICATOR_HORIZONTAL_PADDING);
61             theme->focusIndicatorVerticalPadding_ =
62                 themeConstants->GetDimension(THEME_TAB_FOCUS_INDICATOR_VERTICAL_PADDING);
63             theme->dividerColor_ = themeConstants->GetColor(THEME_DIVIDER_COLOR);
64             auto themeStyle = themeConstants->GetThemeStyle();
65             if (!themeStyle) {
66                 return theme;
67             }
68             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_TAB, nullptr);
69             if (pattern) {
70                 theme->backgroundColor_ = pattern->GetAttr<Color>(PATTERN_BG_COLOR, Color::WHITE);
71                 theme->activeIndicatorColor_ = pattern->GetAttr<Color>("active_indicator_color", Color::WHITE);
72                 theme->focusIndicatorColor_ = pattern->GetAttr<Color>("focus_indicator_color", Color::WHITE);
73                 theme->focusIndicatorRadius_ = pattern->GetAttr<Dimension>("focus_indicator_radius", 0.0_vp);
74                 theme->subTabIndicatorHeight_ = pattern->GetAttr<Dimension>("subtab_indicator_height", 0.0_vp);
75                 theme->subTabTextOffColor_ = pattern->GetAttr<Color>("subtab_text_off_color", Color::WHITE);
76                 theme->subTabIndicatorGap_ = pattern->GetAttr<Dimension>("subtab_indicator_gap", 0.0_vp);
77                 theme->subTabHorizontalPadding_ = pattern->GetAttr<Dimension>("subtab_horizontal_padding", 0.0_vp);
78                 theme->subTabTopPadding_ = pattern->GetAttr<Dimension>("subtab_top_padding", 0.0_vp);
79                 theme->subTabBottomPadding_ = pattern->GetAttr<Dimension>("subtab_bottom_padding", 0.0_vp);
80                 theme->subTabBarHoverColor_ = pattern->GetAttr<Color>("subtab_hover_color", Color::WHITE);
81                 theme->subTabBarPressedColor_ = pattern->GetAttr<Color>("subtab_press_color", Color::WHITE);
82                 theme->subtabTextDefaultFontSize_ =
83                     pattern->GetAttr<Dimension>("subtab_text_default_font_size", 0.0_vp);
84                 theme->subtabLandscapeHorizontalPadding_ =
85                     pattern->GetAttr<Dimension>("subtab_landscape_horizontal_padding", 0.0_vp);
86                 theme->bottomTabHorizontalPadding_ =
87                     pattern->GetAttr<Dimension>("bottom_tab_horizontal_padding", 0.0_vp);
88                 theme->bottomTabTextOn_ = pattern->GetAttr<Color>("bottom_tab_text_on", Color::WHITE);
89                 theme->bottomTabTextOff_ = pattern->GetAttr<Color>("bottom_tab_text_off", Color::WHITE);
90                 theme->bottomTabIconOn_ = pattern->GetAttr<Color>("bottom_tab_icon", Color::WHITE);
91                 theme->bottomTabIconOff_ = pattern->GetAttr<Color>("bottom_tab_icon_off", Color::WHITE);
92                 theme->bottomTabImageSize_ = pattern->GetAttr<Dimension>("bottom_tab_image_size", 0.0_vp);
93                 theme->bottomTabTextSize_ = pattern->GetAttr<Dimension>("bottom_tab_text_size", 0.0_vp);
94                 theme->defaultTabBarName_ = pattern->GetAttr<std::string>("default_tab_bar_name", "");
95                 theme->bottomTabBarSpace_ = pattern->GetAttr<Dimension>("bottom_tab_bar_space", 0.0_vp);
96                 theme->horizontalBottomTabBarSpace_ =
97                     pattern->GetAttr<Dimension>("horizontal_bottom_tab_bar_space", 0.0_vp);
98                 theme->subTabBarHoverDuration_ = pattern->GetAttr<double>("sub_tab_bar_hover_duration", 0.0);
99                 theme->subTabBarHoverToPressDuration_ =
100                     pattern->GetAttr<double>("sub_tab_bar_hover_to_press_duration", 0.0);
101                 theme->tabContentAnimationDuration_ =
102                     pattern->GetAttr<double>("tab_content_animation_duration", 0.0);
103                 theme->tabBarDefaultHeight_ = pattern->GetAttr<Dimension>("tab_bar_default_height", 0.0_vp);
104                 theme->tabBarDefaultWidth_ = pattern->GetAttr<Dimension>("tab_bar_default_width", 0.0_vp);
105                 theme->subTabBarMinWidth_ = pattern->GetAttr<Dimension>("sub_tab_bar_min_width", 0.0_vp);
106                 theme->dividerColor_ = pattern->GetAttr<Color>("divider_color", Color::BLACK);
107                 theme->tabBarShadowMargin_ = pattern->GetAttr<Dimension>("tab_bar_shadow_margin", 0.0_vp);
108                 theme->tabBarGradientWidth_ = pattern->GetAttr<Dimension>("tab_bar_gradient_width", 0.0_vp);
109                 theme->colorBottomTabSubBg_ = pattern->GetAttr<Color>("color_bottom_tab_sub_bg", Color::WHITE);
110                 theme->colorBottomTabSubBgBlur_ = pattern->GetAttr<Color>("color_bottom_tab_sub_bg_blur", Color::WHITE);
111                 theme->tabBarColumnGutter_ = pattern->GetAttr<Dimension>("tab_bar_column_gutter", 0.0_vp);
112                 theme->tabBarColumnMargin_ = pattern->GetAttr<Dimension>("tab_bar_column_margin", 0.0_vp);
113                 theme->horizontalBottomTabMinWidth_ =
114                     pattern->GetAttr<Dimension>("horizontal_bottom_tab_min_width", 0.0_vp);
115             } else {
116                 LOGW("find pattern of tab fail");
117             }
118             return theme;
119         }
120     };
121 
122     ~TabTheme() override = default;
123 
GetLabelPadding()124     const Dimension& GetLabelPadding() const
125     {
126         return labelPadding_;
127     }
128 
GetPadding()129     const Dimension& GetPadding() const
130     {
131         return padding_;
132     }
133 
GetGradientWidth()134     const Dimension& GetGradientWidth() const
135     {
136         return gradientWidth_;
137     }
138 
GetDefaultHeight()139     const Dimension& GetDefaultHeight() const
140     {
141         return defaultHeight_;
142     }
143 
GetDefaultWidth()144     const Dimension& GetDefaultWidth() const
145     {
146         return defaultWidth_;
147     }
148 
GetDefaultItemHeight()149     const Dimension& GetDefaultItemHeight() const
150     {
151         return defaultItemHeight_;
152     }
153 
GetBackgroundColor()154     const Color& GetBackgroundColor() const
155     {
156         return backgroundColor_;
157     }
158 
GetActiveIndicatorColor()159     const Color& GetActiveIndicatorColor() const
160     {
161         return activeIndicatorColor_;
162     }
163 
GetActiveIndicatorWidth()164     const Dimension& GetActiveIndicatorWidth() const
165     {
166         return activeIndicatorWidth_;
167     }
168 
GetActiveIndicatorMinWidth()169     const Dimension& GetActiveIndicatorMinWidth() const
170     {
171         return activeIndicatorMinWidth_;
172     }
173 
GetActiveIndicatorPadding()174     const Dimension& GetActiveIndicatorPadding() const
175     {
176         return activeIndicatorPadding_;
177     }
178 
GetFocusIndicatorColor()179     const Color& GetFocusIndicatorColor() const
180     {
181         return focusIndicatorColor_;
182     }
183 
GetFocusIndicatorRadius()184     const Dimension& GetFocusIndicatorRadius() const
185     {
186         return focusIndicatorRadius_;
187     }
188 
GetFocusIndicatorHorizontalPadding()189     const Dimension& GetFocusIndicatorHorizontalPadding() const
190     {
191         return focusIndicatorHorizontalPadding_;
192     }
193 
GetFocusIndicatorVerticalPadding()194     const Dimension& GetFocusIndicatorVerticalPadding() const
195     {
196         return focusIndicatorVerticalPadding_;
197     }
198 
GetSubTabTextOffColor()199     const Color& GetSubTabTextOffColor() const
200     {
201         return subTabTextOffColor_;
202     }
203 
GetSubTabIndicatorHeight()204     const Dimension& GetSubTabIndicatorHeight() const
205     {
206         return subTabIndicatorHeight_;
207     }
208 
GetSubTabIndicatorGap()209     const Dimension& GetSubTabIndicatorGap() const
210     {
211         return subTabIndicatorGap_;
212     }
213 
GetSubTabHorizontalPadding()214     const Dimension& GetSubTabHorizontalPadding() const
215     {
216         return subTabHorizontalPadding_;
217     }
218 
GetSubTabTopPadding()219     const Dimension& GetSubTabTopPadding() const
220     {
221         return subTabTopPadding_;
222     }
223 
GetSubTabBottomPadding()224     const Dimension& GetSubTabBottomPadding() const
225     {
226         return subTabBottomPadding_;
227     }
228 
GetSubTabBarHoverColor()229     const Color& GetSubTabBarHoverColor() const
230     {
231         return subTabBarHoverColor_;
232     }
233 
GetSubTabBarPressedColor()234     const Color& GetSubTabBarPressedColor() const
235     {
236         return subTabBarPressedColor_;
237     }
238 
GetSubTabTextDefaultFontSize()239     const Dimension& GetSubTabTextDefaultFontSize() const
240     {
241         return subtabTextDefaultFontSize_;
242     }
243 
GetSubtabLandscapeHorizontalPadding()244     const Dimension& GetSubtabLandscapeHorizontalPadding() const
245     {
246         return subtabLandscapeHorizontalPadding_;
247     }
248 
GetBottomTabHorizontalPadding()249     const Dimension& GetBottomTabHorizontalPadding() const
250     {
251         return bottomTabHorizontalPadding_;
252     }
253 
GetBottomTabTextOn()254     const Color& GetBottomTabTextOn() const
255     {
256         return bottomTabTextOn_;
257     }
258 
GetBottomTabTextOff()259     const Color& GetBottomTabTextOff() const
260     {
261         return bottomTabTextOff_;
262     }
263 
GetBottomTabIconOn()264     const Color& GetBottomTabIconOn() const
265     {
266         return bottomTabIconOn_;
267     }
268 
GetBottomTabIconOff()269     const Color& GetBottomTabIconOff() const
270     {
271         return bottomTabIconOff_;
272     }
273 
GetBottomTabImageSize()274     const Dimension& GetBottomTabImageSize() const
275     {
276         return bottomTabImageSize_;
277     }
278 
GetBottomTabTextSize()279     const Dimension& GetBottomTabTextSize() const
280     {
281         return bottomTabTextSize_;
282     }
283 
GetDefaultTabBarName()284     const std::string& GetDefaultTabBarName() const
285     {
286         return defaultTabBarName_;
287     }
288 
GetBottomTabBarSpace()289     const Dimension& GetBottomTabBarSpace() const
290     {
291         return bottomTabBarSpace_;
292     }
293 
GetHorizontalBottomTabBarSpace()294     const Dimension& GetHorizontalBottomTabBarSpace() const
295     {
296         return horizontalBottomTabBarSpace_;
297     }
298 
GetSubTabBarHoverDuration()299     double GetSubTabBarHoverDuration() const
300     {
301         return subTabBarHoverDuration_;
302     }
303 
GetSubTabBarHoverToPressDuration()304     double GetSubTabBarHoverToPressDuration() const
305     {
306         return subTabBarHoverToPressDuration_;
307     }
308 
GetTabContentAnimationDuration()309     double GetTabContentAnimationDuration() const
310     {
311         return tabContentAnimationDuration_;
312     }
313 
GetTabBarDefaultHeight()314     const Dimension& GetTabBarDefaultHeight() const
315     {
316         return tabBarDefaultHeight_;
317     }
318 
GetTabBarDefaultWidth()319     const Dimension& GetTabBarDefaultWidth() const
320     {
321         return tabBarDefaultWidth_;
322     }
323 
GetSubTabBarMinWidth()324     const Dimension& GetSubTabBarMinWidth() const
325     {
326         return subTabBarMinWidth_;
327     }
328 
GetDividerColor()329     const Color& GetDividerColor() const
330     {
331         return dividerColor_;
332     }
333 
GetTabBarShadowMargin()334     const Dimension& GetTabBarShadowMargin() const
335     {
336         return tabBarShadowMargin_;
337     }
338 
GetTabBarGradientWidth()339     const Dimension& GetTabBarGradientWidth() const
340     {
341         return tabBarGradientWidth_;
342     }
343 
GetColorBottomTabSubBg()344     const Color& GetColorBottomTabSubBg() const
345     {
346         return colorBottomTabSubBg_;
347     }
348 
GetColorBottomTabSubBgBlur()349     const Color& GetColorBottomTabSubBgBlur() const
350     {
351         return colorBottomTabSubBgBlur_;
352     }
353 
GetTabBarColumnGutter()354     const Dimension& GetTabBarColumnGutter() const
355     {
356         return tabBarColumnGutter_;
357     }
358 
GetTabBarColumnMargin()359     const Dimension& GetTabBarColumnMargin() const
360     {
361         return tabBarColumnMargin_;
362     }
363 
GetHorizontalBottomTabMinWidth()364     const Dimension& GetHorizontalBottomTabMinWidth() const
365     {
366         return horizontalBottomTabMinWidth_;
367     }
368 
369 protected:
370     TabTheme() = default;
371 
372 private:
373     Dimension labelPadding_;
374     Dimension padding_;
375     Dimension gradientWidth_;
376     Dimension defaultHeight_;
377     Dimension defaultWidth_;
378     Dimension defaultItemHeight_;
379     Color backgroundColor_;
380     Color activeIndicatorColor_;
381     Dimension activeIndicatorWidth_;
382     Dimension activeIndicatorMinWidth_;
383     Dimension activeIndicatorPadding_;
384     Color focusIndicatorColor_;
385     Dimension focusIndicatorRadius_;
386     Dimension focusIndicatorHorizontalPadding_;
387     Dimension focusIndicatorVerticalPadding_;
388     Color subTabTextOffColor_;
389     Dimension subTabIndicatorHeight_;
390     Dimension subTabIndicatorGap_;
391     Dimension subTabHorizontalPadding_;
392     Dimension subTabTopPadding_;
393     Dimension subTabBottomPadding_;
394     Color subTabBarHoverColor_;
395     Color subTabBarPressedColor_;
396     Dimension subtabTextDefaultFontSize_;
397     Dimension subtabLandscapeHorizontalPadding_;
398     Dimension bottomTabHorizontalPadding_;
399     Color bottomTabTextOn_;
400     Color bottomTabTextOff_;
401     Color bottomTabIconOn_;
402     Color bottomTabIconOff_;
403     Dimension bottomTabImageSize_;
404     Dimension bottomTabTextSize_;
405     std::string defaultTabBarName_;
406     Dimension bottomTabBarSpace_;
407     Dimension horizontalBottomTabBarSpace_;
408     double subTabBarHoverDuration_;
409     double subTabBarHoverToPressDuration_;
410     double tabContentAnimationDuration_;
411     Dimension tabBarDefaultHeight_;
412     Dimension tabBarDefaultWidth_;
413     Dimension subTabBarMinWidth_;
414     Color dividerColor_;
415     Dimension tabBarShadowMargin_;
416     Dimension tabBarGradientWidth_;
417     Color colorBottomTabSubBg_;
418     Color colorBottomTabSubBgBlur_;
419     Dimension tabBarColumnGutter_;
420     Dimension tabBarColumnMargin_;
421     Dimension horizontalBottomTabMinWidth_;
422 };
423 
424 } // namespace OHOS::Ace
425 
426 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_THEME_H
427