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