1 /* 2 * Copyright (c) 2024 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_SLIDER_SLIDER_THEME_WRAPPER_H 17 #define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SLIDER_SLIDER_THEME_WRAPPER_H 18 19 #include <memory> 20 21 #include "base/memory/ace_type.h" 22 #include "core/components/slider/slider_theme.h" 23 #include "core/components_ng/token_theme/token_theme_wrapper.h" 24 25 namespace OHOS::Ace::NG { 26 27 /** 28 * SliderThemeWrapper defines colors and styles for Slider and Slider components 29 * basing on TokenTheme's data. 30 * SliderThemeWrapper should be built using SliderThemeWrapper::WrapperBuilder. 31 */ 32 class SliderThemeWrapper : public SliderTheme, public TokenThemeWrapper { 33 DECLARE_ACE_TYPE(SliderThemeWrapper, SliderTheme); 34 35 public: 36 class WrapperBuilder : public Builder { 37 public: 38 WrapperBuilder() = default; 39 ~WrapperBuilder() = default; 40 BuildWrapper(const RefPtr<ThemeConstants> & themeConstants)41 RefPtr<TokenThemeWrapper> BuildWrapper(const RefPtr<ThemeConstants>& themeConstants) const 42 { 43 auto wrapper = AceType::MakeRefPtr<SliderThemeWrapper>(); 44 if (!themeConstants) { 45 LOGE("Build AppTheme error, themeConstants is null!"); 46 return wrapper; 47 } 48 ParsePattern(themeConstants, AceType::DynamicCast<SliderTheme>(wrapper)); 49 return wrapper; 50 } 51 }; 52 53 ~SliderThemeWrapper() override = default; 54 ApplyTokenTheme(const TokenTheme & theme)55 void ApplyTokenTheme(const TokenTheme& theme) override 56 { 57 if (auto themeColors = theme.Colors(); themeColors) { 58 trackBgColor_ = themeColors->CompBackgroundSecondary(); 59 trackSelectedColor_ = themeColors->BackgroundEmphasize(); 60 blockColor_ = themeColors->CompBackgroundPrimaryContrary(); 61 outsetModeSelectedTrackColor_ = themeColors->BackgroundEmphasize(); 62 markerColor_ = themeColors->CompBackgroundSecondary(); 63 } 64 } 65 66 protected: 67 SliderThemeWrapper() = default; 68 }; 69 70 } // namespace 71 #endif