• 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_SCROLL_SCROLL_BAR_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_SCROLL_BAR_THEME_H
18 
19 #include "core/components/common/properties/scroll_bar.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 /**
27  * ScrollBarTheme defines styles of scrollBar. ScrollBarTheme should be built
28  * using ScrollBarTheme::Builder.
29  */
30 class ScrollBarTheme : public virtual Theme {
31     DECLARE_ACE_TYPE(ScrollBarTheme, Theme);
32 
33 public:
34     class Builder {
35     public:
36         Builder() = default;
37         ~Builder() = default;
38 
Build(const RefPtr<ThemeConstants> & themeConstants)39         RefPtr<ScrollBarTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
40         {
41             RefPtr<ScrollBarTheme> theme = AceType::Claim(new ScrollBarTheme());
42             if (!themeConstants) {
43                 return theme;
44             }
45             theme->shapeMode_ = ShapeMode(themeConstants->GetInt(THEME_SCROLL_BAR_SHAPE_MODE));
46             theme->normalWidth_ = themeConstants->GetDimension(THEME_SCROLL_BAR_NORMAL_WIDTH);
47             theme->activeWidth_ = themeConstants->GetDimension(THEME_SCROLL_BAR_ACTIVE_WIDTH);
48             theme->minHeight_ = themeConstants->GetDimension(THEME_SCROLL_BAR_MIN_HEIGHT);
49             theme->minDynamicHeight_ = themeConstants->GetDimension(THEME_SCROLL_BAR_MIN_DYNAMIC_HEIGHT);
50             theme->reservedHeight_ = themeConstants->GetDimension(THEME_SCROLL_BAR_RESERVED_HEIGHT);
51             theme->touchWidth_ = themeConstants->GetDimension(THEME_SCROLL_BAR_TOUCH_WIDTH);
52             theme->backgroundColor_ = themeConstants->GetColor(THEME_SCROLL_BAR_BACKGROUND_COLOR);
53             theme->foregroundColor_ = themeConstants->GetColor(THEME_SCROLL_BAR_FOREGROUND_COLOR);
54             Dimension paddingRight = themeConstants->GetDimension(THEME_SCROLL_BAR_PADDING_RIGHT);
55             theme->padding_ = Edge(0.0, 0.0, paddingRight.Value(), 0.0, paddingRight.Unit());
56             ParsePattern(themeConstants->GetThemeStyle(), theme);
57             return theme;
58         }
59 
60     private:
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<ScrollBarTheme> & theme)61         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<ScrollBarTheme>& theme) const
62         {
63             if (!themeStyle) {
64                 LOGI("scroll bar theme style is null");
65                 return;
66             }
67             theme->foregroundColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_FOREGROUND,
68                 Color::TRANSPARENT).BlendOpacity(0.4);
69         }
70     };
71 
72     ~ScrollBarTheme() override = default;
73 
GetNormalWidth()74     const Dimension& GetNormalWidth() const
75     {
76         return normalWidth_;
77     }
78 
GetActiveWidth()79     const Dimension& GetActiveWidth() const
80     {
81         return activeWidth_;
82     }
83 
GetMinHeight()84     const Dimension& GetMinHeight() const
85     {
86         return minHeight_;
87     }
88 
GetMinDynamicHeight()89     const Dimension& GetMinDynamicHeight() const
90     {
91         return minDynamicHeight_;
92     }
93 
GetReservedHeight()94     const Dimension& GetReservedHeight() const
95     {
96         return reservedHeight_;
97     }
98 
GetTouchWidth()99     const Dimension& GetTouchWidth() const
100     {
101         return touchWidth_;
102     }
103 
GetBackgroundColor()104     const Color& GetBackgroundColor() const
105     {
106         return backgroundColor_;
107     }
108 
GetForegroundColor()109     const Color& GetForegroundColor() const
110     {
111         return foregroundColor_;
112     }
113 
GetShapeMode()114     ShapeMode GetShapeMode() const
115     {
116         return shapeMode_;
117     }
118 
GetPadding()119     const Edge& GetPadding() const
120     {
121         return padding_;
122     }
123 
124 protected:
125     ScrollBarTheme() = default;
126 
127 private:
128     ShapeMode shapeMode_ = ShapeMode::DEFAULT;
129     Dimension normalWidth_;
130     Dimension activeWidth_;
131     Dimension minHeight_;
132     Dimension minDynamicHeight_;
133     Dimension reservedHeight_;
134     Dimension touchWidth_;
135     Color backgroundColor_;
136     Color foregroundColor_;
137     Edge padding_;
138 };
139 
140 } // namespace OHOS::Ace
141 
142 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_SCROLL_BAR_THEME_H
143