1 /* 2 * Copyright (c) 2025 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 FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PROGRESS_PROGRESS_THEME_WRAPPER_H 17 #define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PROGRESS_PROGRESS_THEME_WRAPPER_H 18 19 #include <memory> 20 21 #include "base/memory/ace_type.h" 22 #include "core/components/progress/progress_theme.h" 23 #include "core/components_ng/token_theme/token_theme_wrapper.h" 24 25 namespace OHOS::Ace::NG { 26 27 /** 28 * ProgressThemeWrapper defines colors and styles for Progress and LoadingProgress components 29 * basing on TokenTheme's data. 30 * ProgressThemeWrapper should be built using ProgressThemeWrapper::WrapperBuilder. 31 */ 32 class ProgressThemeWrapper : public ProgressTheme, public TokenThemeWrapper { 33 DECLARE_ACE_TYPE(ProgressThemeWrapper, ProgressTheme); 34 35 public: 36 class WrapperBuilder : public Builder { 37 public: 38 WrapperBuilder() = default; 39 ~WrapperBuilder() override = default; 40 BuildWrapper(const RefPtr<ThemeConstants> & themeConstants)41 RefPtr<TokenThemeWrapper> BuildWrapper(const RefPtr<ThemeConstants>& themeConstants) const 42 { 43 auto wrapper = AceType::MakeRefPtr<ProgressThemeWrapper>(); 44 ParsePattern(themeConstants, AceType::DynamicCast<ProgressTheme>(wrapper)); 45 return wrapper; 46 } 47 }; 48 49 ~ProgressThemeWrapper() override = default; 50 ApplyTokenTheme(const TokenTheme & theme)51 void ApplyTokenTheme(const TokenTheme& theme) override 52 { 53 if (auto themeColors = theme.Colors(); themeColors) { 54 // update only required attributes by TokenTheme tokens 55 loadingColor_ = themeColors->IconSecondary(); 56 57 capsuleBgColor_ = themeColors->CompBackgroundTertiary(); 58 ringProgressBackgroundColor_ = themeColors->CompBackgroundTertiary(); 59 trackBgColor_ = themeColors->CompBackgroundTertiary(); 60 61 capsuleSelectColor_ = themeColors->CompEmphasizeSecondary(); 62 trackSelectedColor_ = themeColors->BackgroundEmphasize(); 63 borderColor_ = themeColors->CompEmphasizeSecondary(); 64 } 65 } 66 67 protected: 68 ProgressThemeWrapper() = default; 69 }; 70 71 } // namespace 72 #endif 73