• 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_SWIPER_SWIPER_INDICATOR_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_INDICATOR_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 namespace {
25 constexpr double SWIPER_ARROW_ALPHA_DISABLED = 0.4;
26 constexpr Dimension SWIPER_ARROW_SCALE = 24.0_vp;
27 constexpr Dimension SWIPER_ARROW_SMALL_ARROW_BACKGROUND_SIZE = 24.0_vp;
28 constexpr Dimension SWIPER_ARROW_SMALL_ARROW_SIZE = 18.0_vp;
29 constexpr Dimension SWIPER_ARROW_BIG_ARROW_BACKGROUND_SIZE = 32.0_vp;
30 constexpr Dimension SWIPER_ARROW_BIG_ARROW_SIZE = 24.0_vp;
31 constexpr Dimension SWIPER_ARROW_HORIZONTAL_MARGIN_DEFAULT = 8.0_vp;
32 constexpr Dimension SWIPER_ARROW_VERTICAL_MARGIN_DEFAULT = 8.0_vp;
33 constexpr Dimension SWIPER_FOCUSED_BORDER_WIDTH = 2.0_vp;
34 constexpr Dimension SWIPER_INDICATOR_DIGIT_PADDING_DEFAULT = 8.0_vp;
35 constexpr Dimension SWIPER_INDICATOR_DIGIT_VERTICAL_PADDING_DEFAULT = 8.0_vp;
36 constexpr Dimension SWIPER_INDICATOR_DIGIT_HEIGHT = 32.0_vp;
37 constexpr Dimension SWIPER_INDICATOR_DOT_PADDING_DEFAULT = 12.0_vp;
38 constexpr Dimension SWIPER_INDICATOR_DOT_ITEM_SPACE = 8.0_vp;
39 } // namespace
40 class SwiperIndicatorTheme : public virtual Theme {
41     DECLARE_ACE_TYPE(SwiperIndicatorTheme, Theme);
42 
43 public:
44     class Builder {
45     public:
46         Builder() = default;
47         ~Builder() = default;
48 
Build(const RefPtr<ThemeConstants> & themeConstants)49         RefPtr<SwiperIndicatorTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
50         {
51             RefPtr<SwiperIndicatorTheme> theme = AceType::Claim(new SwiperIndicatorTheme());
52             if (!themeConstants) {
53                 return theme;
54             }
55             theme->color_ = themeConstants->GetColor(THEME_SWIPER_INDICATOR_NORMAL_COLOR);
56             theme->selectedColor_ = themeConstants->GetColor(THEME_SWIPER_INDICATOR_SELECTED_COLOR);
57             theme->size_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_SIZE);
58             theme->selectedSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_SELECTED_SIZE);
59             theme->isHasMask_ = themeConstants->GetInt(THEME_SWIPER_INDICATOR_MASK);
60             theme->indicatorPointPadding_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_POINT_PADDING);
61             theme->digitalIndicatorTextStyle_.SetFontSize(
62                 themeConstants->GetDimension(THEME_SWIPER_DIGITAL_INDICATOR_FONT_SIZE));
63             theme->digitalIndicatorTextStyle_.SetTextColor(
64                 themeConstants->GetColor(THEME_SWIPER_DIGITAL_INDICATOR_TEXT_COLOR));
65             theme->startEndPadding_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_START_END_PADDING);
66             theme->pressPadding_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_PRESS_PADDING);
67             theme->pressPointPadding_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_PRESS_POINT_PADDING);
68             theme->pressSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_PRESS_SIZE);
69             theme->hoverSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_HOVER_SIZE);
70             theme->hotZoneSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_HOTZONE_SIZE);
71             theme->hotZoneColor_ = themeConstants->GetColor(THEME_SWIPER_INDICATOR_HOTZONE_COLOR);
72             theme->hotZoneSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_HOTZONE_SIZE);
73             theme->indicatorTextFocusColor_ = themeConstants->GetColor(THEME_SWIPER_DIGITAL_INDICATOR_FOCUS_TEXT_COLOR);
74             theme->isIndicatorDisabled_ = themeConstants->GetInt(THEME_SWIPER_INDICATOR_DISABLED);
75             theme->animationCurve_ = AnimationCurve(themeConstants->GetInt(THEME_SWIPER_ANIMATION_CURVE));
76             theme->animationOpacity_ = themeConstants->GetInt(THEME_SWIPER_ANIMATION_OPACITY);
77             ParsePattern(themeConstants->GetThemeStyle(), theme);
78             return theme;
79         }
80 
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<SwiperIndicatorTheme> & theme)81         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<SwiperIndicatorTheme>& theme) const
82         {
83             if (!themeStyle) {
84                 return;
85             }
86             auto swiperPattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_SWIPER, nullptr);
87             if (!swiperPattern) {
88                 LOGW("find pattern of swiper fail");
89                 return;
90             }
91             theme->color_ = swiperPattern->GetAttr<Color>("indicator_color", Color::TRANSPARENT);
92             theme->hotZoneColor_ = swiperPattern->GetAttr<Color>("indicator_hotzone_color", Color::TRANSPARENT);
93             theme->indicatorTextFocusColor_ =
94                 swiperPattern->GetAttr<Color>("indicator_text_color_focused", Color::TRANSPARENT);
95             theme->digitalIndicatorTextStyle_.SetTextColor(
96                 swiperPattern->GetAttr<Color>("indicator_text_font_color", Color::TRANSPARENT));
97             theme->digitalIndicatorTextStyle_.SetFontSize(
98                 swiperPattern->GetAttr<Dimension>("indicator_text_font_size", 14.0_vp));
99             theme->selectedColor_ = swiperPattern->GetAttr<Color>("indicator_color_selected", Color::TRANSPARENT);
100             theme->hoverColor_ = swiperPattern->GetAttr<Color>("indicator_color_hover", Color::TRANSPARENT);
101             theme->pressedColor_ = swiperPattern->GetAttr<Color>("indicator_color_pressed", Color::TRANSPARENT);
102             theme->focusedColor_ = swiperPattern->GetAttr<Color>("indicator_color_focused", Color::TRANSPARENT);
103             theme->focusedBorderWidth_ = SWIPER_FOCUSED_BORDER_WIDTH;
104             theme->hoverArrowBackgroundColor_ =
105                 swiperPattern->GetAttr<Color>(ARROW_COLOR_BOARDCOLOR_HOVER, Color::TRANSPARENT);
106             theme->clickArrowBackgroundColor_ =
107                 swiperPattern->GetAttr<Color>(ARROW_COLOR_BOARDCOLOR_CLICK, Color::TRANSPARENT);
108             theme->arrowColorPrimary_ = swiperPattern->GetAttr<Color>(ARROW_COLOR_PRIMARY, Color::TRANSPARENT);
109             theme->arrowColorPrimaryContrary_ =
110                 swiperPattern->GetAttr<Color>(ARROW_COLOR_PRIMARY_CONTRARY, Color::TRANSPARENT);
111             theme->arrowDisabledAlpha_ =
112                 swiperPattern->GetAttr<double>(ARROW_DISABLED_ALPHA, SWIPER_ARROW_ALPHA_DISABLED);
113             theme->arrowScale_ = SWIPER_ARROW_SCALE;
114             theme->arrowHorizontalMargin_ =
115                 swiperPattern->GetAttr<Dimension>(ARROW_HORIZONTAL_MARGIN, SWIPER_ARROW_HORIZONTAL_MARGIN_DEFAULT);
116             theme->arrowVerticalMargin_ =
117                 swiperPattern->GetAttr<Dimension>(ARROW_VERTICAL_MARGIN, SWIPER_ARROW_VERTICAL_MARGIN_DEFAULT);
118             theme->smallArrowBackgroundSize_ = SWIPER_ARROW_SMALL_ARROW_BACKGROUND_SIZE;
119             theme->smallArrowSize_ = SWIPER_ARROW_SMALL_ARROW_SIZE;
120             theme->smallArrowBackgroundColor_ = Color::TRANSPARENT;
121             theme->smallArrowColor_ = swiperPattern->GetAttr<Color>(ARROW_COLOR_PRIMARY, Color::TRANSPARENT);
122             theme->bigArrowBackgroundSize_ = SWIPER_ARROW_BIG_ARROW_BACKGROUND_SIZE;
123             theme->bigArrowSize_ = SWIPER_ARROW_BIG_ARROW_SIZE;
124             theme->bigArrowBackgroundColor_ =
125                 swiperPattern->GetAttr<Color>(ARROW_COLOR_COMPONENT_NORMAL, Color::TRANSPARENT);
126             theme->bigArrowColor_ = swiperPattern->GetAttr<Color>(ARROW_COLOR_PRIMARY, Color::TRANSPARENT);
127             theme->indicatorDigitPadding_ = SWIPER_INDICATOR_DIGIT_PADDING_DEFAULT;
128             theme->indicatorDigitVerticalPadding_ = SWIPER_INDICATOR_DIGIT_VERTICAL_PADDING_DEFAULT;
129             theme->indicatorDotPadding_ = SWIPER_INDICATOR_DOT_PADDING_DEFAULT;
130             theme->indicatorDigitHeight_ = SWIPER_INDICATOR_DIGIT_HEIGHT;
131             theme->indicatorDotItemSpace_ = SWIPER_INDICATOR_DOT_ITEM_SPACE;
132         }
133     };
134 
135     ~SwiperIndicatorTheme() override = default;
136 
GetColor()137     const Color& GetColor() const
138     {
139         return color_;
140     }
141 
GetSelectedColor()142     const Color& GetSelectedColor() const
143     {
144         return selectedColor_;
145     }
146 
GetHoverColor()147     const Color& GetHoverColor() const
148     {
149         return hoverColor_;
150     }
151 
GetPressedColor()152     const Color& GetPressedColor() const
153     {
154         return pressedColor_;
155     }
156 
GetFocusedColor()157     const Color& GetFocusedColor() const
158     {
159         return focusedColor_;
160     }
161 
GetFocusedBorderWidth()162     const Dimension& GetFocusedBorderWidth() const
163     {
164         return focusedBorderWidth_;
165     }
166 
GetSize()167     const Dimension& GetSize() const
168     {
169         return size_;
170     }
171 
GetSelectedSize()172     const Dimension& GetSelectedSize() const
173     {
174         return selectedSize_;
175     }
176 
GetIndicatorMask()177     bool GetIndicatorMask() const
178     {
179         return isHasMask_;
180     }
181 
GetIndicatorPointPadding()182     const Dimension& GetIndicatorPointPadding() const
183     {
184         return indicatorPointPadding_;
185     }
186 
GetDigitalIndicatorTextStyle()187     const TextStyle& GetDigitalIndicatorTextStyle() const
188     {
189         return digitalIndicatorTextStyle_;
190     }
191 
GetStartEndPadding()192     const Dimension& GetStartEndPadding() const
193     {
194         return startEndPadding_;
195     }
196 
GetPressPadding()197     const Dimension& GetPressPadding() const
198     {
199         return pressPadding_;
200     }
201 
GetPressPointPadding()202     const Dimension& GetPressPointPadding() const
203     {
204         return pressPointPadding_;
205     }
206 
GetPressSize()207     const Dimension& GetPressSize() const
208     {
209         return pressSize_;
210     }
211 
GetHoverSize()212     const Dimension& GetHoverSize() const
213     {
214         return hoverSize_;
215     }
216 
GetHotZoneSize()217     const Dimension& GetHotZoneSize() const
218     {
219         return hotZoneSize_;
220     }
221 
GetHotZoneColor()222     const Color& GetHotZoneColor() const
223     {
224         return hotZoneColor_;
225     }
226 
GetIndicatorTextFocusColor()227     const Color& GetIndicatorTextFocusColor() const
228     {
229         return indicatorTextFocusColor_;
230     }
231 
GetIndicatorDisabled()232     bool GetIndicatorDisabled() const
233     {
234         return isIndicatorDisabled_;
235     }
236 
GetAnimationCurve()237     AnimationCurve GetAnimationCurve() const
238     {
239         return animationCurve_;
240     }
241 
IsAnimationOpacity()242     bool IsAnimationOpacity() const
243     {
244         return animationOpacity_;
245     }
246 
GetHoverArrowBackgroundColor()247     const Color& GetHoverArrowBackgroundColor() const
248     {
249         return hoverArrowBackgroundColor_;
250     }
251 
GetClickArrowBackgroundColor()252     const Color& GetClickArrowBackgroundColor() const
253     {
254         return clickArrowBackgroundColor_;
255     }
256 
GetArrowColorPrimary()257     const Color& GetArrowColorPrimary() const
258     {
259         return arrowColorPrimary_;
260     }
261 
GetArrowColorPrimaryContrary()262     const Color& GetArrowColorPrimaryContrary() const
263     {
264         return arrowColorPrimaryContrary_;
265     }
266 
GetIsShowArrowBackground()267     bool GetIsShowArrowBackground() const
268     {
269         return isShowArrowBackground_;
270     }
271 
GetIsSidebarMiddle()272     bool GetIsSidebarMiddle() const
273     {
274         return isSidebarMiddle_;
275     }
276 
GetSmallArrowBackgroundSize()277     const Dimension& GetSmallArrowBackgroundSize() const
278     {
279         return smallArrowBackgroundSize_;
280     }
281 
GetSmallArrowSize()282     const Dimension& GetSmallArrowSize() const
283     {
284         return smallArrowSize_;
285     }
GetSmallArrowBackgroundColor()286     const Color& GetSmallArrowBackgroundColor() const
287     {
288         return smallArrowBackgroundColor_;
289     }
290 
GetSmallArrowColor()291     const Color& GetSmallArrowColor() const
292     {
293         return smallArrowColor_;
294     }
GetBigArrowBackgroundSize()295     const Dimension& GetBigArrowBackgroundSize() const
296     {
297         return bigArrowBackgroundSize_;
298     }
299 
GetBigArrowSize()300     const Dimension& GetBigArrowSize() const
301     {
302         return bigArrowSize_;
303     }
GetBigArrowBackgroundColor()304     const Color& GetBigArrowBackgroundColor() const
305     {
306         return bigArrowBackgroundColor_;
307     }
308 
GetBigArrowColor()309     const Color& GetBigArrowColor() const
310     {
311         return bigArrowColor_;
312     }
313 
GetArrowDisabledAlpha()314     double GetArrowDisabledAlpha() const
315     {
316         return arrowDisabledAlpha_;
317     }
318 
GetArrowScale()319     const Dimension& GetArrowScale() const
320     {
321         return arrowScale_;
322     }
323 
GetArrowHorizontalMargin()324     const Dimension& GetArrowHorizontalMargin() const
325     {
326         return arrowHorizontalMargin_;
327     }
328 
GetArrowVerticalMargin()329     const Dimension& GetArrowVerticalMargin() const
330     {
331         return arrowVerticalMargin_;
332     }
333 
GetIndicatorDigitPadding()334     const Dimension& GetIndicatorDigitPadding() const
335     {
336         return indicatorDigitPadding_;
337     }
338 
GetIndicatorDotPadding()339     const Dimension& GetIndicatorDotPadding() const
340     {
341         return indicatorDotPadding_;
342     }
343 
GetIndicatorDigitHeight()344     const Dimension& GetIndicatorDigitHeight() const
345     {
346         return indicatorDigitHeight_;
347     }
348 
GetIndicatorDigitVerticalPadding()349     const Dimension& GetIndicatorDigitVerticalPadding() const
350     {
351         return indicatorDigitVerticalPadding_;
352     }
353 
GetIndicatorDotItemSpace()354     const Dimension& GetIndicatorDotItemSpace() const
355     {
356         return indicatorDotItemSpace_;
357     }
358 protected:
359     SwiperIndicatorTheme() = default;
360 
361 private:
362     Color color_;
363     Color selectedColor_;
364     Color hoverColor_;
365     Color pressedColor_;
366     Color focusedColor_;
367     Dimension focusedBorderWidth_;
368     Dimension size_;
369     Dimension selectedSize_;
370     Dimension indicatorPointPadding_;
371     bool isHasMask_ = false;
372     TextStyle digitalIndicatorTextStyle_;
373     Dimension startEndPadding_;
374     Dimension pressPadding_;
375     Dimension pressPointPadding_;
376     Dimension pressSize_;
377     Dimension hoverSize_;
378     Dimension hotZoneSize_;
379     Color hotZoneColor_;
380     Color indicatorTextFocusColor_;
381     bool isIndicatorDisabled_ = false;
382     AnimationCurve animationCurve_ = { AnimationCurve::FRICTION };
383     bool animationOpacity_ = true;
384     Color hoverArrowBackgroundColor_;
385     Color clickArrowBackgroundColor_;
386     Color arrowColorPrimary_;
387     Color arrowColorPrimaryContrary_;
388     bool isShowArrowBackground_ = false;
389     bool isSidebarMiddle_ = false;
390     Dimension smallArrowBackgroundSize_;
391     Dimension smallArrowSize_;
392     Color smallArrowBackgroundColor_;
393     Color smallArrowColor_;
394     Dimension bigArrowBackgroundSize_;
395     Dimension bigArrowSize_;
396     Color bigArrowBackgroundColor_;
397     Color bigArrowColor_;
398     double arrowDisabledAlpha_ = 0.4;
399     Dimension arrowScale_;
400     Dimension arrowHorizontalMargin_;
401     Dimension arrowVerticalMargin_;
402     Dimension indicatorDigitPadding_;
403     Dimension indicatorDigitVerticalPadding_;
404     Dimension indicatorDotPadding_;
405     Dimension indicatorDigitHeight_;
406     Dimension indicatorDotItemSpace_;
407 };
408 
409 } // namespace OHOS::Ace
410 
411 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_INDICATOR_THEME_H
412