• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::MakeRefPtr<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             theme->fadingEdge_ = pattern->GetAttr<std::string>("list_fadeout_enable", "") == "true";
66         }
67     };
68 
69     ~ListTheme() override = default;
70 
GetGradientWidth()71     const Dimension& GetGradientWidth() const
72     {
73         return gradientWidth_;
74     }
75 
GetBackgroundColor()76     const Color& GetBackgroundColor() const
77     {
78         return backgroundColor_;
79     }
80 
GetDividerColor()81     const Color& GetDividerColor() const
82     {
83         return dividerColor_;
84     }
85 
GetScrollDistance()86     double GetScrollDistance() const
87     {
88         return scrollDistance_;
89     }
90 
GetChainMinSpace()91     Dimension GetChainMinSpace() const
92     {
93         return chainMinSpace_;
94     }
GetChainMaxSpace()95     Dimension GetChainMaxSpace() const
96     {
97         return chainMaxSpace_;
98     }
GetChainConductivity()99     double GetChainConductivity() const
100     {
101         return chainConductivity_;
102     }
GetChainIntensity()103     double GetChainIntensity() const
104     {
105         return chainIntensity_;
106     }
GetChainStiffness()107     double GetChainStiffness() const
108     {
109         return chainStiffness_;
110     }
GetChainDamping()111     double GetChainDamping() const
112     {
113         return chainDamping_;
114     }
GetFadingEdge()115     bool GetFadingEdge() const
116     {
117         return fadingEdge_;
118     }
119 
120 protected:
121     ListTheme() = default;
122 
123 private:
124     Dimension gradientWidth_;
125     Color backgroundColor_;
126     Color dividerColor_;
127     double scrollDistance_ = 0.0;
128     Dimension chainMinSpace_;
129     Dimension chainMaxSpace_;
130     double chainConductivity_ = 0.0;
131     double chainIntensity_ = 0.0;
132     double chainStiffness_ = 0.0;
133     double chainDamping_ = 0.0;
134     bool fadingEdge_ = false;
135 };
136 
137 } // namespace OHOS::Ace
138 
139 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_THEME_H
140