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 25 class SwiperIndicatorTheme : public virtual Theme { 26 DECLARE_ACE_TYPE(SwiperIndicatorTheme, Theme); 27 28 public: 29 class Builder { 30 public: 31 Builder() = default; 32 ~Builder() = default; 33 Build(const RefPtr<ThemeConstants> & themeConstants)34 RefPtr<SwiperIndicatorTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 35 { 36 RefPtr<SwiperIndicatorTheme> theme = AceType::Claim(new SwiperIndicatorTheme()); 37 if (!themeConstants) { 38 return theme; 39 } 40 theme->color_ = themeConstants->GetColor(THEME_SWIPER_INDICATOR_NORMAL_COLOR); 41 theme->selectedColor_ = themeConstants->GetColor(THEME_SWIPER_INDICATOR_SELECTED_COLOR); 42 theme->size_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_SIZE); 43 theme->selectedSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_SELECTED_SIZE); 44 theme->isHasMask_ = themeConstants->GetInt(THEME_SWIPER_INDICATOR_MASK); 45 theme->indicatorPointPadding_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_POINT_PADDING); 46 theme->digitalIndicatorTextStyle_.SetFontSize( 47 themeConstants->GetDimension(THEME_SWIPER_DIGITAL_INDICATOR_FONT_SIZE)); 48 theme->digitalIndicatorTextStyle_.SetTextColor( 49 themeConstants->GetColor(THEME_SWIPER_DIGITAL_INDICATOR_TEXT_COLOR)); 50 theme->startEndPadding_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_START_END_PADDING); 51 theme->pressPadding_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_PRESS_PADDING); 52 theme->pressPointPadding_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_PRESS_POINT_PADDING); 53 theme->pressSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_PRESS_SIZE); 54 theme->hoverSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_HOVER_SIZE); 55 theme->hotZoneSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_HOTZONE_SIZE); 56 theme->hotZoneColor_ = themeConstants->GetColor(THEME_SWIPER_INDICATOR_HOTZONE_COLOR); 57 theme->hotZoneSize_ = themeConstants->GetDimension(THEME_SWIPER_INDICATOR_HOTZONE_SIZE); 58 theme->indicatorTextFocusColor_ = themeConstants->GetColor(THEME_SWIPER_DIGITAL_INDICATOR_FOCUS_TEXT_COLOR); 59 theme->isIndicatorDisabled_ = themeConstants->GetInt(THEME_SWIPER_INDICATOR_DISABLED); 60 theme->animationCurve_ = AnimationCurve(themeConstants->GetInt(THEME_SWIPER_ANIMATION_CURVE)); 61 theme->animationOpacity_ = themeConstants->GetInt(THEME_SWIPER_ANIMATION_OPACITY); 62 auto themeStyle = themeConstants->GetThemeStyle(); 63 if (!themeStyle) { 64 return theme; 65 } 66 theme->digitalIndicatorTextStyle_.SetFontSize( 67 themeStyle->GetAttr<Dimension>(THEME_ATTR_TEXT_SIZE_BODY2, 0.0_vp)); 68 auto swiperPattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_SWIPER, nullptr); 69 if (!swiperPattern) { 70 LOGE("Pattern of swiper is null, please check!"); 71 return theme; 72 } 73 theme->color_ = swiperPattern->GetAttr<Color>(INDICATOR_COLOR_UNSELECTED, Color::RED); 74 theme->hotZoneColor_ = swiperPattern->GetAttr<Color>(INDICATOR_MASK_COLOR, Color::RED); 75 theme->indicatorTextFocusColor_ = swiperPattern->GetAttr<Color>(INDICATOR_TEXT_COLOR_FOCUS, Color::RED); 76 theme->digitalIndicatorTextStyle_.SetTextColor( 77 swiperPattern->GetAttr<Color>(INDICATOR_TEXT_COLOR, Color::RED)); 78 theme->selectedColor_ = swiperPattern->GetAttr<Color>(INDICATOR_COLOR_SELECTED, Color::RED); 79 return theme; 80 } 81 }; 82 83 ~SwiperIndicatorTheme() override = default; 84 GetColor()85 const Color& GetColor() const 86 { 87 return color_; 88 } 89 GetSelectedColor()90 const Color& GetSelectedColor() const 91 { 92 return selectedColor_; 93 } 94 GetSize()95 const Dimension& GetSize() const 96 { 97 return size_; 98 } 99 GetSelectedSize()100 const Dimension& GetSelectedSize() const 101 { 102 return selectedSize_; 103 } 104 GetIndicatorMask()105 bool GetIndicatorMask() const 106 { 107 return isHasMask_; 108 } 109 GetIndicatorPointPadding()110 const Dimension& GetIndicatorPointPadding() const 111 { 112 return indicatorPointPadding_; 113 } 114 GetDigitalIndicatorTextStyle()115 const TextStyle& GetDigitalIndicatorTextStyle() const 116 { 117 return digitalIndicatorTextStyle_; 118 } 119 GetStartEndPadding()120 const Dimension& GetStartEndPadding() const 121 { 122 return startEndPadding_; 123 } 124 GetPressPadding()125 const Dimension& GetPressPadding() const 126 { 127 return pressPadding_; 128 } 129 GetPressPointPadding()130 const Dimension& GetPressPointPadding() const 131 { 132 return pressPointPadding_; 133 } 134 GetPressSize()135 const Dimension& GetPressSize() const 136 { 137 return pressSize_; 138 } 139 GetHoverSize()140 const Dimension& GetHoverSize() const 141 { 142 return hoverSize_; 143 } 144 GetHotZoneSize()145 const Dimension& GetHotZoneSize() const 146 { 147 return hotZoneSize_; 148 } 149 GetHotZoneColor()150 const Color& GetHotZoneColor() const 151 { 152 return hotZoneColor_; 153 } 154 GetIndicatorTextFocusColor()155 const Color& GetIndicatorTextFocusColor() const 156 { 157 return indicatorTextFocusColor_; 158 } 159 GetIndicatorDisabled()160 bool GetIndicatorDisabled() const 161 { 162 return isIndicatorDisabled_; 163 } 164 GetAnimationCurve()165 AnimationCurve GetAnimationCurve() const 166 { 167 return animationCurve_; 168 } 169 IsAnimationOpacity()170 bool IsAnimationOpacity() const 171 { 172 return animationOpacity_; 173 } 174 175 protected: 176 SwiperIndicatorTheme() = default; 177 178 private: 179 Color color_; 180 Color selectedColor_; 181 Dimension size_; 182 Dimension selectedSize_; 183 Dimension indicatorPointPadding_; 184 bool isHasMask_ = false; 185 TextStyle digitalIndicatorTextStyle_; 186 Dimension startEndPadding_; 187 Dimension pressPadding_; 188 Dimension pressPointPadding_; 189 Dimension pressSize_; 190 Dimension hoverSize_; 191 Dimension hotZoneSize_; 192 Color hotZoneColor_; 193 Color indicatorTextFocusColor_; 194 bool isIndicatorDisabled_ = false; 195 AnimationCurve animationCurve_ = { AnimationCurve::FRICTION }; 196 bool animationOpacity_ = true; 197 }; 198 199 } // namespace OHOS::Ace 200 201 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_INDICATOR_THEME_H 202