• 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_DRAG_BAR_DRAG_BAR_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DRAG_BAR_DRAG_BAR_THEME_H
18 
19 #include "core/components/common/properties/color.h"
20 #include "core/components/theme/theme.h"
21 #include "core/components/theme/theme_constants.h"
22 #include "core/components/theme/theme_constants_defines.h"
23 
24 namespace OHOS::Ace {
25 
26 class DragBarTheme : public virtual Theme {
27     DECLARE_ACE_TYPE(DragBarTheme, Theme);
28 
29 public:
30     class Builder {
31     public:
32         Builder() = default;
33         ~Builder() = default;
34 
Build(const RefPtr<ThemeConstants> & themeConstants)35         RefPtr<DragBarTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
36         {
37             RefPtr<DragBarTheme> theme = AceType::Claim(new DragBarTheme());
38             if (!themeConstants) {
39                 return theme;
40             }
41             theme->barColor_ = themeConstants->GetColor(THEME_DRAG_BAR_COLOR);
42             ParsePattern(themeConstants->GetThemeStyle(), theme);
43             auto themeStyle = themeConstants->GetThemeStyle();
44             if (!themeStyle) {
45                 return theme;
46             }
47             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_DRAG_BAR, nullptr);
48             if (pattern) {
49                 theme->dragBarColor_ = pattern->GetAttr<Color>("drag_bar_bg_color", Color::WHITE);
50                 theme->panelBgColor_ = pattern->GetAttr<Color>("panel_bg_color", Color::WHITE);
51             } else {
52                 LOGW("find pattern of tab fail");
53             }
54             return theme;
55         }
56     private:
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<DragBarTheme> & theme)57         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<DragBarTheme>& theme) const
58         {
59             if (!themeStyle) {
60                 return;
61             }
62             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_DRAG_BAR, nullptr);
63             if (!pattern) {
64                 LOGW("find pattern of drag bar fail");
65                 return;
66             }
67             theme->barColor_ = pattern->GetAttr<Color>(DRAG_BAR_COLOR, Color());
68         }
69     };
70     ~DragBarTheme() override = default;
71 
GetBarColor()72     const Color& GetBarColor() const
73     {
74         return barColor_;
75     }
76 
GetDragBarColor()77     const Color& GetDragBarColor() const
78     {
79         return dragBarColor_;
80     }
81 
GetPanelBgColor()82     const Color& GetPanelBgColor() const
83     {
84         return panelBgColor_;
85     }
86 
87 protected:
88     DragBarTheme() = default;
89 
90 private:
91     Color barColor_;
92     Color dragBarColor_;
93     Color panelBgColor_;
94 };
95 
96 } // namespace OHOS::Ace
97 
98 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DRAG_BAR_DRAG_BAR_THEME_H
99