• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TOGGLE_TOGGLE_THEME_WRAPPER_H
17 #define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TOGGLE_TOGGLE_THEME_WRAPPER_H
18 
19 #include "core/components/toggle/toggle_theme.h"
20 #include "core/components_ng/token_theme/token_theme_wrapper.h"
21 
22 namespace OHOS::Ace::NG {
23 
24 class ToggleThemeWrapper : public ToggleTheme, public TokenThemeWrapper {
25     DECLARE_ACE_TYPE(ToggleThemeWrapper, ToggleTheme);
26 
27 public:
28     class WrapperBuilder : public Builder {
29     public:
30         WrapperBuilder() = default;
31         ~WrapperBuilder() = default;
32 
BuildWrapper(const RefPtr<ThemeConstants> & themeConstants)33         RefPtr<TokenThemeWrapper> BuildWrapper(const RefPtr<ThemeConstants>& themeConstants) const
34         {
35             auto themeWrapper = AceType::MakeRefPtr<ToggleThemeWrapper>();
36             auto theme = AceType::DynamicCast<ToggleTheme>(themeWrapper);
37             if (!themeConstants) {
38                 return themeWrapper;
39             }
40             ParsePattern(themeConstants, theme);
41             return themeWrapper;
42         }
43     };
44 
45     ~ToggleThemeWrapper() override = default;
46 
ApplyTokenTheme(const TokenTheme & theme)47     void ApplyTokenTheme(const TokenTheme& theme) override
48     {
49         if (auto colors = theme.Colors(); colors) {
50             backgroundColor_ = colors->CompBackgroundTertiary();
51             checkedColor_ = colors->CompEmphasizeSecondary();
52         }
53     }
54 
55 protected:
56     ToggleThemeWrapper() = default;
57 };
58 
59 } // namespace OHOS::Ace::NG
60 #endif // FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TOGGLE_TOGGLE_THEME_WRAPPER_H