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