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_LIST_LIST_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_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 
25 /**
26  * ListTheme defines styles of list. ListTheme should be built
27  * using ListTheme::Builder.
28  */
29 class ListTheme : public virtual Theme {
30     DECLARE_ACE_TYPE(ListTheme, Theme);
31 
32 public:
33     class Builder {
34     public:
35         Builder() = default;
36         ~Builder() = default;
37 
Build(const RefPtr<ThemeConstants> & themeConstants)38         RefPtr<ListTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
39         {
40             RefPtr<ListTheme> theme = AceType::Claim(new ListTheme());
41             if (!themeConstants) {
42                 return theme;
43             }
44             ParsePattern(themeConstants, theme);
45             return theme;
46         }
47 
ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<ListTheme> & theme)48         void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<ListTheme>& theme) const
49         {
50             RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_LIST);
51             if (!pattern) {
52                 LOGW("find pattern of list fail");
53                 return;
54             }
55             theme->gradientWidth_ = pattern->GetAttr<Dimension>("gradient_width", 0.0_vp);
56             theme->backgroundColor_ = pattern->GetAttr<Color>("background_color", Color(0x00FFFFFF));
57             theme->scrollDistance_ = pattern->GetAttr<double>("scroll_distance", 50.0f);
58             theme->dividerColor_ = pattern->GetAttr<Color>("divider_color", Color(0x08000000));
59             theme->chainMinSpace_ = pattern->GetAttr<Dimension>("chain_min_space", 15.0_vp);
60             theme->chainMaxSpace_ = pattern->GetAttr<Dimension>("chain_max_space", 40.0_vp);
61             theme->chainConductivity_ = pattern->GetAttr<double>("chain_conductivity", 0.7f);
62             theme->chainIntensity_ = pattern->GetAttr<double>("chain_intensity", 0.3f);
63             theme->chainStiffness_ = pattern->GetAttr<double>("chain_stiffness", 228.0f);
64             theme->chainDamping_ = pattern->GetAttr<double>("chain_damping", 30.0f);
65         }
66     };
67 
68     ~ListTheme() override = default;
69 
GetGradientWidth()70     const Dimension& GetGradientWidth() const
71     {
72         return gradientWidth_;
73     }
74 
GetBackgroundColor()75     const Color& GetBackgroundColor() const
76     {
77         return backgroundColor_;
78     }
79 
GetDividerColor()80     const Color& GetDividerColor() const
81     {
82         return dividerColor_;
83     }
84 
GetScrollDistance()85     double GetScrollDistance() const
86     {
87         return scrollDistance_;
88     }
89 
GetChainMinSpace()90     Dimension GetChainMinSpace() const
91     {
92         return chainMinSpace_;
93     }
GetChainMaxSpace()94     Dimension GetChainMaxSpace() const
95     {
96         return chainMaxSpace_;
97     }
GetChainConductivity()98     double GetChainConductivity() const
99     {
100         return chainConductivity_;
101     }
GetChainIntensity()102     double GetChainIntensity() const
103     {
104         return chainIntensity_;
105     }
GetChainStiffness()106     double GetChainStiffness() const
107     {
108         return chainStiffness_;
109     }
GetChainDamping()110     double GetChainDamping() const
111     {
112         return chainDamping_;
113     }
114 
115 protected:
116     ListTheme() = default;
117 
118 private:
119     Dimension gradientWidth_;
120     Color backgroundColor_;
121     Color dividerColor_;
122     double scrollDistance_ = 0.0;
123     Dimension chainMinSpace_;
124     Dimension chainMaxSpace_;
125     double chainConductivity_ = 0.0;
126     double chainIntensity_ = 0.0;
127     double chainStiffness_ = 0.0;
128     double chainDamping_ = 0.0;
129 };
130 
131 } // namespace OHOS::Ace
132 
133 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_THEME_H
134