• 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_SLIDER_SLIDER_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_SLIDER_THEME_H
18 
19 #include "base/geometry/dimension.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 
25 namespace OHOS::Ace {
26 
27 /**
28  * SliderTheme defines color and styles of SliderComponent. SliderTheme should be built
29  * using SliderTheme::Builder.
30  */
31 class SliderTheme : public virtual Theme {
32     DECLARE_ACE_TYPE(SliderTheme, Theme);
33 
34 public:
35     class Builder {
36     public:
37         Builder() = default;
38         ~Builder() = default;
39 
Build(const RefPtr<ThemeConstants> & themeConstants)40         RefPtr<SliderTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
41         {
42             RefPtr<SliderTheme> theme = AceType::Claim(new SliderTheme());
43             if (!themeConstants) {
44                 return theme;
45             }
46             // init theme from global data
47             theme->outsetBlockSize_ = themeConstants->GetDimension(THEME_SLIDER_OUTSET_BLOCK_SIZE);
48             theme->outsetBlockHotSize_ = themeConstants->GetDimension(THEME_SLIDER_OUTSET_BLOCK_HOT_REGION_SIZE);
49             theme->blockColor_ = themeConstants->GetColor(THEME_SLIDER_BLOCK_COLOR);
50             theme->outsetTrackThickness_ = themeConstants->GetDimension(THEME_SLIDER_OUTSET_TRACK_THICKNESS);
51             theme->insetTrackThickness_ = themeConstants->GetDimension(THEME_SLIDER_INSET_TRACK_THICKNESS);
52             theme->trackSelectedColor_ = themeConstants->GetColor(THEME_SLIDER_TRACK_SELECTED);
53             theme->trackBgColor_ = themeConstants->GetColor(THEME_SLIDER_TRACK_BG);
54             theme->insetBlockSize_ = themeConstants->GetDimension(THEME_SLIDER_INSET_BLOCK_SIZE);
55             theme->insetBlockHotSize_ = themeConstants->GetDimension(THEME_SLIDER_INSET_BLOCK_HOT_REGION_SIZE);
56             theme->markerSize_ = themeConstants->GetDimension(THEME_SLIDER_MARKER_SIZE);
57             theme->markerColor_ = themeConstants->GetColor(THEME_SLIDER_MARKER_COLOR);
58             theme->tipColor_ = themeConstants->GetColor(THEME_SLIDER_TIP_COLOR);
59             theme->tipTextColor_ = themeConstants->GetColor(THEME_SLIDER_TIP_TEXT_COLOR);
60             theme->tipFontSize_ = themeConstants->GetDimension(THEME_SLIDER_TIP_FONT_SIZE);
61             theme->tipTextPadding_ = themeConstants->GetDimension(THEME_SLIDER_TIP_TEXT_PADDING_SIZE);
62             theme->blockHoverColor_ = themeConstants->GetColor(THEME_SLIDER_BLOCK_HOVER_COLOR);
63             ParsePattern(themeConstants->GetThemeStyle(), theme);
64             return theme;
65         }
66 
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<SliderTheme> & theme)67         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<SliderTheme>& theme) const
68         {
69             if (!themeStyle) {
70                 LOGI("progress theme style is null");
71                 return;
72             }
73             theme->trackBgColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_COMPONENT_NORMAL, Color::RED);
74             theme->trackSelectedColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_EMPHASIZE, Color::RED);
75             theme->markerColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_FOREGROUND, Color::RED).BlendOpacity(0.1);
76             theme->tipTextColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_TEXT_COLOR_PRIMARY_INVERSE, Color::RED);
77             theme->tipColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_TIPS_BG, Color::RED);
78             theme->blockHoverColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_HOVER, Color::RED);
79         }
80     };
81 
82     ~SliderTheme() override = default;
83 
GetOutsetBlockSize()84     Dimension GetOutsetBlockSize() const
85     {
86         return outsetBlockSize_;
87     }
88 
GetOutsetBlockHotSize()89     Dimension GetOutsetBlockHotSize() const
90     {
91         return outsetBlockHotSize_;
92     }
93 
GetInsetBlockSize()94     Dimension GetInsetBlockSize() const
95     {
96         return insetBlockSize_;
97     }
98 
GetInsetBlockHotSize()99     Dimension GetInsetBlockHotSize() const
100     {
101         return insetBlockHotSize_;
102     }
103 
GetBlockHoverColor()104     Color GetBlockHoverColor() const
105     {
106         return blockHoverColor_;
107     }
108 
GetBlockColor()109     Color GetBlockColor() const
110     {
111         return blockColor_;
112     }
113 
GetInsetTrackThickness()114     Dimension GetInsetTrackThickness() const
115     {
116         return insetTrackThickness_;
117     }
118 
GetOutsetTrackThickness()119     Dimension GetOutsetTrackThickness() const
120     {
121         return outsetTrackThickness_;
122     }
123 
GetMarkerSize()124     Dimension GetMarkerSize() const
125     {
126         return markerSize_;
127     }
128 
GetTipFontSize()129     Dimension GetTipFontSize() const
130     {
131         return tipFontSize_;
132     }
133 
GetTipTextPadding()134     Dimension GetTipTextPadding() const
135     {
136         return tipTextPadding_;
137     }
138 
GetTipColor()139     Color GetTipColor() const
140     {
141         return tipColor_;
142     }
143 
GetTipTextColor()144     Color GetTipTextColor() const
145     {
146         return tipTextColor_;
147     }
148 
GetMarkerColor()149     Color GetMarkerColor() const
150     {
151         return markerColor_;
152     }
153 
GetTrackBgColor()154     Color GetTrackBgColor() const
155     {
156         return trackBgColor_;
157     }
158 
GetTrackSelectedColor()159     Color GetTrackSelectedColor() const
160     {
161         return trackSelectedColor_;
162     }
163 
164 protected:
165     SliderTheme() = default;
166 
167 private:
168     // outset slider mode
169     Dimension outsetBlockSize_;
170     Dimension outsetBlockHotSize_;
171     Dimension outsetTrackThickness_;
172 
173     // inset slide mode
174     Dimension insetBlockSize_;
175     Dimension insetBlockHotSize_;
176     Dimension insetTrackThickness_;
177 
178     // common
179     Dimension markerSize_;
180     Dimension tipFontSize_;
181     Dimension tipTextPadding_;
182     Color blockColor_;
183     Color blockHoverColor_;
184     Color tipColor_;
185     Color tipTextColor_;
186     Color markerColor_;
187     Color trackBgColor_;
188     Color trackSelectedColor_;
189 };
190 
191 } // namespace OHOS::Ace
192 
193 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_SLIDER_THEME_H
194