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 auto swiperPattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_SWIPER, nullptr); 67 if (!swiperPattern) { 68 LOGW("find pattern of swiper fail"); 69 return theme; 70 } 71 theme->color_ = swiperPattern->GetAttr<Color>("indicator_color", Color::TRANSPARENT); 72 theme->hotZoneColor_ = swiperPattern->GetAttr<Color>("indicator_hotzone_color", Color::TRANSPARENT); 73 theme->indicatorTextFocusColor_ = 74 swiperPattern->GetAttr<Color>("indicator_text_color_focused", Color::TRANSPARENT); 75 theme->digitalIndicatorTextStyle_.SetTextColor( 76 swiperPattern->GetAttr<Color>("indicator_text_color", Color::TRANSPARENT)); 77 theme->selectedColor_ = swiperPattern->GetAttr<Color>("indicator_color_selected", Color::TRANSPARENT); 78 theme->hoverColor_ = swiperPattern->GetAttr<Color>("indicator_color_hover", Color::TRANSPARENT); 79 theme->pressedColor_ = swiperPattern->GetAttr<Color>("indicator_color_pressed", Color::TRANSPARENT); 80 theme->focusedColor_ = swiperPattern->GetAttr<Color>("indicator_color_focused", Color::TRANSPARENT); 81 return theme; 82 } 83 }; 84 85 ~SwiperIndicatorTheme() override = default; 86 GetColor()87 const Color& GetColor() const 88 { 89 return color_; 90 } 91 GetSelectedColor()92 const Color& GetSelectedColor() const 93 { 94 return selectedColor_; 95 } 96 GetHoverColor()97 const Color& GetHoverColor() const 98 { 99 return hoverColor_; 100 } 101 GetPressedColor()102 const Color& GetPressedColor() const 103 { 104 return pressedColor_; 105 } 106 GetFocusedColor()107 const Color& GetFocusedColor() const 108 { 109 return focusedColor_; 110 } 111 GetSize()112 const Dimension& GetSize() const 113 { 114 return size_; 115 } 116 GetSelectedSize()117 const Dimension& GetSelectedSize() const 118 { 119 return selectedSize_; 120 } 121 GetIndicatorMask()122 bool GetIndicatorMask() const 123 { 124 return isHasMask_; 125 } 126 GetIndicatorPointPadding()127 const Dimension& GetIndicatorPointPadding() const 128 { 129 return indicatorPointPadding_; 130 } 131 GetDigitalIndicatorTextStyle()132 const TextStyle& GetDigitalIndicatorTextStyle() const 133 { 134 return digitalIndicatorTextStyle_; 135 } 136 GetStartEndPadding()137 const Dimension& GetStartEndPadding() const 138 { 139 return startEndPadding_; 140 } 141 GetPressPadding()142 const Dimension& GetPressPadding() const 143 { 144 return pressPadding_; 145 } 146 GetPressPointPadding()147 const Dimension& GetPressPointPadding() const 148 { 149 return pressPointPadding_; 150 } 151 GetPressSize()152 const Dimension& GetPressSize() const 153 { 154 return pressSize_; 155 } 156 GetHoverSize()157 const Dimension& GetHoverSize() const 158 { 159 return hoverSize_; 160 } 161 GetHotZoneSize()162 const Dimension& GetHotZoneSize() const 163 { 164 return hotZoneSize_; 165 } 166 GetHotZoneColor()167 const Color& GetHotZoneColor() const 168 { 169 return hotZoneColor_; 170 } 171 GetIndicatorTextFocusColor()172 const Color& GetIndicatorTextFocusColor() const 173 { 174 return indicatorTextFocusColor_; 175 } 176 GetIndicatorDisabled()177 bool GetIndicatorDisabled() const 178 { 179 return isIndicatorDisabled_; 180 } 181 GetAnimationCurve()182 AnimationCurve GetAnimationCurve() const 183 { 184 return animationCurve_; 185 } 186 IsAnimationOpacity()187 bool IsAnimationOpacity() const 188 { 189 return animationOpacity_; 190 } 191 192 protected: 193 SwiperIndicatorTheme() = default; 194 195 private: 196 Color color_; 197 Color selectedColor_; 198 Color hoverColor_; 199 Color pressedColor_; 200 Color focusedColor_; 201 Dimension size_; 202 Dimension selectedSize_; 203 Dimension indicatorPointPadding_; 204 bool isHasMask_ = false; 205 TextStyle digitalIndicatorTextStyle_; 206 Dimension startEndPadding_; 207 Dimension pressPadding_; 208 Dimension pressPointPadding_; 209 Dimension pressSize_; 210 Dimension hoverSize_; 211 Dimension hotZoneSize_; 212 Color hotZoneColor_; 213 Color indicatorTextFocusColor_; 214 bool isIndicatorDisabled_ = false; 215 AnimationCurve animationCurve_ = { AnimationCurve::FRICTION }; 216 bool animationOpacity_ = true; 217 }; 218 219 } // namespace OHOS::Ace 220 221 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_INDICATOR_THEME_H 222