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_PROGRESS_PROGRESS_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_PROGRESS_THEME_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/common/container.h" 21 #include "core/components/common/properties/color.h" 22 #include "core/components/theme/theme.h" 23 #include "core/components/theme/theme_constants.h" 24 #include "core/components/theme/theme_constants_defines.h" 25 26 namespace OHOS::Ace { 27 28 /** 29 * ProgressTheme defines color and styles of ProgressComponent. ProgressTheme should be built 30 * using ProgressTheme::Builder. 31 */ 32 class ProgressTheme : public virtual Theme { 33 DECLARE_ACE_TYPE(ProgressTheme, Theme); 34 35 public: 36 class Builder { 37 public: 38 Builder() = default; 39 ~Builder() = default; 40 Build(const RefPtr<ThemeConstants> & themeConstants)41 RefPtr<ProgressTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 42 { 43 RefPtr<ProgressTheme> theme = AceType::Claim(new ProgressTheme()); 44 if (!themeConstants) { 45 return theme; 46 } 47 // Read style from system. 48 ParsePattern(themeConstants->GetThemeStyle(), theme); 49 return theme; 50 } 51 ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<ProgressTheme> & theme)52 void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<ProgressTheme>& theme) const 53 { 54 if (!themeStyle) { 55 return; 56 } 57 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("progress_pattern", nullptr); 58 if (!pattern) { 59 return; 60 } 61 const double defaultCachedAlpha = 0.4; 62 const double defaultLoadBGAlpha = 0.6; 63 const double defaultRingBackgroundOpacity = 0.03; 64 Color defaultColor = Color::FromRGBO(18, 24, 31, 1.0); 65 theme->trackThickness_ = pattern->GetAttr<Dimension>("progress_thickness", 0.0_vp); 66 theme->trackWidth_ = pattern->GetAttr<Dimension>("progress_default_width", 0.0_vp); 67 theme->ringThickness_ = pattern->GetAttr<Dimension>("progress_ring_thickness", 0.0_vp); 68 theme->ringDiameter_ = pattern->GetAttr<Dimension>("progress_default_diameter", 0.0_vp); 69 theme->loadingDiameter_ = pattern->GetAttr<Dimension>("progress_default_diameter", 0.0_vp); 70 theme->scaleNumber_ = static_cast<int32_t>(pattern->GetAttr<double>("progress_scale_number", 0.0)); 71 theme->scaleWidth_ = pattern->GetAttr<Dimension>("progress_scale_width", 0.0_vp); 72 theme->scaleLength_ = pattern->GetAttr<Dimension>("progress_stroke_width", 0.0_vp); 73 theme->scaleRingDiameter_ = pattern->GetAttr<Dimension>("progress_scale_default_diameter", 0.0_vp); 74 theme->moonDiameter_ = pattern->GetAttr<Dimension>("progress_moon_diameter", 0.0_vp); 75 theme->moveRatio_ = pattern->GetAttr<double>("progress_loading_move_ratio", 0.0); 76 theme->ringRadius_ = pattern->GetAttr<Dimension>("progress_loading_ring_radius", 0.0_vp); 77 theme->orbitRadius_ = pattern->GetAttr<Dimension>("progress_loading_orbit_radius", 0.0_vp); 78 theme->cometTailLen_ = pattern->GetAttr<double>("progress_loading_comet_tail_len", 0.0); 79 theme->bubbleRadius_ = pattern->GetAttr<Dimension>("progress_bubble_radius", 0.0_vp); 80 theme->bubbleDiameter_ = pattern->GetAttr<Dimension>("progress_bubble_diameter", 0.0_vp); 81 theme->progressHeight_ = pattern->GetAttr<Dimension>("progress_button_download_height", 0.0_vp); 82 theme->trackBgColor_ = pattern->GetAttr<Color>("bg_color", Color::RED); 83 theme->trackSelectedColor_ = pattern->GetAttr<Color>("fg_color", Color::RED); 84 theme->trackCachedColor_ = theme->trackSelectedColor_ 85 .BlendOpacity(pattern->GetAttr<double>("fg_color_cached_alpha", defaultCachedAlpha)); 86 theme->progressColor_ = pattern->GetAttr<Color>("fg_progress_color", Color::RED); 87 theme->loadingColor_ = pattern->GetAttr<Color>("fg_progress_color", Color::RED); 88 theme->moonFrontColor_ = pattern->GetAttr<Color>("moon_progress_fg_color", Color::RED) 89 .BlendOpacity(pattern->GetAttr<double>("moon_progress_fg_color_alpha", 1.0)); 90 theme->moonTrackBackgroundColor_ = pattern->GetAttr<Color>("moon_progress_bg_color", Color::RED) 91 .BlendOpacity(pattern->GetAttr<double>("moon_progress_bg_color_alpha", 1.0)) 92 .BlendOpacity(pattern->GetAttr<double>("moon_progress_bg_color_alpha_ex", 1.0)); 93 theme->borderColor_ = pattern->GetAttr<Color>("progress_border_color", Color::RED) 94 .BlendOpacity(pattern->GetAttr<double>("progress_border_color_alpha", 1.0)); 95 theme->maskColor_ = pattern->GetAttr<Color>("progress_mask_color", Color::RED); 96 theme->borderWidth_ = pattern->GetAttr<Dimension>("progress_border_width", 1.0_vp); 97 theme->fontScalePadding_ = pattern->GetAttr<Dimension>("progress_aging_padding_height", 8.0_vp); 98 theme->fontScale_ = pattern->GetAttr<double>("progress_aging_font_scale", 1.75); 99 theme->textColor_ = pattern->GetAttr<Color>("progress_text_color", defaultColor); 100 theme->textSize_ = pattern->GetAttr<Dimension>("progress_text_size", 12.0_fp); 101 theme->capsuleSelectColor_ = pattern->GetAttr<Color>("capsule_progress_select_color", Color::RED); 102 theme->selectColorAlpha_ = pattern->GetAttr<double>("capsule_progress_default_alpha", 1.0); 103 theme->capsuleSelectColor_ = theme->capsuleSelectColor_.BlendOpacity(theme->selectColorAlpha_); 104 theme->progressDisable_ = pattern->GetAttr<double>("progress_disabled_alpha", 1.0); 105 theme->clickEffect_ = pattern->GetAttr<Color>("progress_click_effect", Color::RED); 106 theme->capsuleBgColor_ = pattern->GetAttr<Color>("capsule_progress_bg_color", Color::RED) 107 .BlendOpacity(pattern->GetAttr<double>("capsule_progress_bg_alpha", 1.0)); 108 theme->ringProgressEndSideColor_ = 109 pattern->GetAttr<Color>("ring_progress_fg_color_end", theme->trackSelectedColor_); 110 theme->ringProgressBeginSideColor_ = 111 pattern->GetAttr<Color>("ring_progress_fg_color_begin", theme->trackSelectedColor_); 112 theme->ringProgressBackgroundColor_ = 113 pattern->GetAttr<Color>("ring_progress_bg_color", Color::GRAY); 114 115 if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TEN)) { 116 theme->capsuleBgColor_ = theme->trackBgColor_; 117 theme->capsuleSelectColor_ = theme->trackSelectedColor_; 118 theme->ringProgressBackgroundColor_ = theme->trackBgColor_; 119 theme->ringProgressBeginSideColor_ = theme->trackSelectedColor_; 120 theme->ringProgressEndSideColor_ = theme->trackSelectedColor_; 121 } else if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) { 122 theme->capsuleSelectColor_ = 123 pattern->GetAttr<Color>("progress_select_color", Color::RED).BlendOpacity(theme->selectColorAlpha_); 124 theme->borderColor_ = theme->capsuleSelectColor_; 125 theme->ringProgressBackgroundColor_ = theme->trackBgColor_.ChangeOpacity(defaultRingBackgroundOpacity); 126 theme->loadingColor_ = theme->loadingColor_.BlendOpacity( 127 pattern->GetAttr<double>("loading_progress_bg_color_alpha", defaultLoadBGAlpha)); 128 } 129 } 130 }; 131 132 ~ProgressTheme() override = default; 133 GetTrackThickness()134 const Dimension& GetTrackThickness() const 135 { 136 return trackThickness_; 137 } 138 GetTrackWidth()139 const Dimension& GetTrackWidth() const 140 { 141 return trackWidth_; 142 } 143 GetRingThickness()144 const Dimension& GetRingThickness() const 145 { 146 return ringThickness_; 147 } 148 GetRingDiameter()149 const Dimension& GetRingDiameter() const 150 { 151 return ringDiameter_; 152 } 153 GetTrackBgColor()154 const Color& GetTrackBgColor() const 155 { 156 return trackBgColor_; 157 } 158 GetTrackSelectedColor()159 const Color& GetTrackSelectedColor() const 160 { 161 return trackSelectedColor_; 162 } 163 GetTrackCachedColor()164 Color GetTrackCachedColor() const 165 { 166 return trackCachedColor_; 167 } 168 GetLoadingDiameter()169 const Dimension& GetLoadingDiameter() const 170 { 171 return loadingDiameter_; 172 } 173 GetLoadingColor()174 const Color& GetLoadingColor() const 175 { 176 return loadingColor_; 177 } 178 GetScaleWidth()179 const Dimension& GetScaleWidth() const 180 { 181 return scaleWidth_; 182 } 183 GetScaleNumber()184 int32_t GetScaleNumber() const 185 { 186 return scaleNumber_; 187 } 188 GetScaleLength()189 const Dimension& GetScaleLength() const 190 { 191 return scaleLength_; 192 } 193 GetProgressColor()194 const Color& GetProgressColor() const 195 { 196 return progressColor_; 197 } 198 GetMoveRatio()199 double GetMoveRatio() const 200 { 201 return moveRatio_; 202 } 203 GetRingRadius()204 const Dimension& GetRingRadius() const 205 { 206 return ringRadius_; 207 } 208 GetOrbitRadius()209 const Dimension& GetOrbitRadius() const 210 { 211 return orbitRadius_; 212 } 213 GetCometTailLen()214 double GetCometTailLen() const 215 { 216 return cometTailLen_; 217 } 218 GetScaleRingDiameter()219 const Dimension& GetScaleRingDiameter() const 220 { 221 return scaleRingDiameter_; 222 } 223 GetMoonDiameter()224 const Dimension& GetMoonDiameter() const 225 { 226 return moonDiameter_; 227 } 228 GetMoonBackgroundColor()229 const Color& GetMoonBackgroundColor() const 230 { 231 return moonTrackBackgroundColor_; 232 } 233 GetMoonFrontColor()234 const Color& GetMoonFrontColor() const 235 { 236 return moonFrontColor_; 237 } 238 GetBubbleDiameter()239 const Dimension& GetBubbleDiameter() const 240 { 241 return bubbleDiameter_; 242 } 243 GetBubbleRadius()244 const Dimension& GetBubbleRadius() const 245 { 246 return bubbleRadius_; 247 } 248 GetBorderColor()249 const Color& GetBorderColor() const 250 { 251 return borderColor_; 252 } 253 GetBorderWidth()254 const Dimension& GetBorderWidth() const 255 { 256 return borderWidth_; 257 } 258 GetMaskColor()259 const Color& GetMaskColor() const 260 { 261 return maskColor_; 262 } 263 GetTextColor()264 const Color& GetTextColor() const 265 { 266 return textColor_; 267 } 268 GetTextSize()269 const Dimension& GetTextSize() const 270 { 271 return textSize_; 272 } 273 GetProgressHeight()274 const Dimension& GetProgressHeight() const 275 { 276 return progressHeight_; 277 } 278 GetCapsuleSelectColor()279 const Color& GetCapsuleSelectColor() const 280 { 281 return capsuleSelectColor_; 282 } 283 GetProgressDisable()284 const float& GetProgressDisable() const 285 { 286 return progressDisable_; 287 } 288 GetClickEffect()289 const Color& GetClickEffect() const 290 { 291 return clickEffect_; 292 } 293 GetSelectColorAlpha()294 const float& GetSelectColorAlpha() const 295 { 296 return selectColorAlpha_; 297 } 298 GetTextMargin()299 const Dimension& GetTextMargin() const 300 { 301 return textMargin_; 302 } 303 GetFontScale()304 float GetFontScale() const 305 { 306 return fontScale_; 307 } 308 GetfontScalePadding()309 const Dimension& GetfontScalePadding() const 310 { 311 return fontScalePadding_; 312 } 313 GetCapsuleBgColor()314 const Color& GetCapsuleBgColor() const 315 { 316 return capsuleBgColor_; 317 } 318 GetRingProgressEndSideColor()319 const Color& GetRingProgressEndSideColor() const 320 { 321 return ringProgressEndSideColor_; 322 } 323 GetRingProgressBeginSideColor()324 const Color& GetRingProgressBeginSideColor() const 325 { 326 return ringProgressBeginSideColor_; 327 } 328 GetRingProgressBgColor()329 const Color& GetRingProgressBgColor() const 330 { 331 return ringProgressBackgroundColor_; 332 } 333 334 protected: 335 ProgressTheme() = default; 336 337 private: 338 Dimension trackThickness_; 339 Dimension trackWidth_; 340 Color trackBgColor_; 341 Color trackSelectedColor_; 342 Color trackCachedColor_; 343 344 Dimension ringThickness_; 345 Dimension ringDiameter_; 346 Dimension bubbleDiameter_; 347 Dimension bubbleRadius_; 348 349 Dimension loadingDiameter_; 350 Color loadingColor_; 351 352 Dimension scaleWidth_; 353 int32_t scaleNumber_ = 0; 354 Dimension scaleLength_; 355 Dimension scaleRingDiameter_; 356 357 Dimension moonDiameter_; 358 Color moonTrackBackgroundColor_; 359 Color moonFrontColor_; 360 361 // For loading progress in cycle type. 362 Color progressColor_; 363 double moveRatio_ = 0.0; 364 Dimension ringRadius_; 365 Dimension orbitRadius_; 366 double cometTailLen_ = 0.0; 367 368 Color borderColor_; 369 Dimension borderWidth_; 370 Color maskColor_; 371 372 // For capsule progress. 373 Color textColor_; 374 Dimension textSize_; 375 Dimension progressHeight_; 376 Color capsuleSelectColor_; 377 float progressDisable_ = 0.4; 378 Color clickEffect_; 379 float selectColorAlpha_ = 1.0f; 380 const Dimension textMargin_ = 8.0_vp; 381 Color capsuleBgColor_; 382 383 // For ring progress. 384 Color ringProgressEndSideColor_; 385 Color ringProgressBeginSideColor_; 386 Color ringProgressBackgroundColor_; 387 float fontScale_ = 1.75f; 388 Dimension fontScalePadding_; 389 }; 390 391 } // namespace OHOS::Ace 392 393 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_PROGRESS_THEME_H 394