• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LINEAR_INDICATOR_LINEAR_INDICATOR_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LINEAR_INDICATOR_LINEAR_INDICATOR_THEME_H
18 
19 #include "base/geometry/dimension.h"
20 #include "core/components/common/layout/constants.h"
21 #include "core/components/common/properties/color.h"
22 #include "core/components/theme/theme.h"
23 #include "core/components/theme/theme_constants.h"
24 #include "core/components/theme/theme_constants_defines.h"
25 
26 namespace OHOS::Ace::NG {
27 
28 class LinearIndicatorTheme : public virtual Theme {
29     DECLARE_ACE_TYPE(LinearIndicatorTheme, Theme);
30 
31 public:
32     class Builder {
33     public:
34         Builder() = default;
35         ~Builder() = default;
36 
Build(const RefPtr<ThemeConstants> & themeConstants)37         RefPtr<LinearIndicatorTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
38         {
39             RefPtr<LinearIndicatorTheme> theme = AceType::MakeRefPtr<LinearIndicatorTheme>();
40             if (!themeConstants) {
41                 return theme;
42             }
43             ParsePattern(themeConstants, theme);
44             return theme;
45         }
46 
47     private:
ParsePattern(const RefPtr<ThemeConstants> & themeStyle,const RefPtr<LinearIndicatorTheme> & theme)48         void ParsePattern(const RefPtr<ThemeConstants>& themeStyle, const RefPtr<LinearIndicatorTheme>& theme) const
49         {
50             if (!themeStyle) {
51                 return;
52             }
53             auto pattern = themeStyle->GetPatternByName(THEME_PATTERN_LINEAR_INDICATOR);
54             if (!pattern) {
55                 return;
56             }
57             theme->trackBackgroundColor_ = pattern->GetAttr<Color>("comp_background_tertiary", Color(0X0C182431));
58             theme->trackColor_ = pattern->GetAttr<Color>("comp_background_emphasize", Color(0xFF007DFF));
59             theme->paddingLeft_ = pattern->GetAttr<Dimension>("padding_level8", 16.0_vp);
60             theme->paddingRight_ = pattern->GetAttr<Dimension>("padding_level8", 16.0_vp);
61         }
62     };
63     LinearIndicatorTheme() = default;
64     ~LinearIndicatorTheme() override = default;
65 
GetTrackBackgroundColor()66     const Color& GetTrackBackgroundColor() const
67     {
68         return trackBackgroundColor_;
69     }
70 
GetTrackColor()71     const Color& GetTrackColor() const
72     {
73         return trackColor_;
74     }
75 
GetPaddingLeft()76     const Dimension& GetPaddingLeft() const
77     {
78         return paddingLeft_;
79     }
80 
GetPaddingRight()81     const Dimension& GetPaddingRight() const
82     {
83         return paddingRight_;
84     }
85 
GetPaddingTop()86     const Dimension& GetPaddingTop() const
87     {
88         return paddingTop_;
89     }
90 
GetPaddingBottom()91     const Dimension& GetPaddingBottom() const
92     {
93         return paddingBottom_;
94     }
95 
GetDefaultSpace()96     const Dimension& GetDefaultSpace() const
97     {
98         return defaultSpace_;
99     }
100 
GetDefaultProgressCount()101     int GetDefaultProgressCount() const
102     {
103         return defaultProgressCount_;
104     }
105 
GetDefaultProgressMin()106     int GetDefaultProgressMin() const
107     {
108         return defaultProgressMin_;
109     }
110 
GetDefaultLoop()111     bool GetDefaultLoop() const
112     {
113         return defaultLoop_;
114     }
115 
GetDefaultStrokeWidth()116     const Dimension& GetDefaultStrokeWidth() const
117     {
118         return defaultStrokeWidth_;
119     }
120 
GetDefaultStrokeWidthMin()121     const Dimension& GetDefaultStrokeWidthMin() const
122     {
123         return defaultStrokeWidthMin_;
124     }
125 
GetDefaultStrokeRadius()126     const Dimension& GetDefaultStrokeRadius() const
127     {
128         return defaultStrokeRadius_;
129     }
130 
GetDefaultIntervalTime()131     int GetDefaultIntervalTime() const
132     {
133         return defaultIntervalTime_;
134     }
135 
GetDefaultDurationTime()136     int GetDefaultDurationTime() const
137     {
138         return defaultDurationTime_;
139     }
140 
GetDefaultHeight()141     const Dimension& GetDefaultHeight() const
142     {
143         return defaultHeight_;
144     }
145 
146 private:
147     Color trackBackgroundColor_ = Color(0X0C182431);
148     Color trackColor_ = Color(0xFF007DFF);
149     Dimension paddingLeft_ = 16.0_vp;
150     Dimension paddingRight_ = 16.0_vp;
151     Dimension paddingTop_ = 0.0_vp;
152     Dimension paddingBottom_ = 0.0_vp;
153     Dimension defaultSpace_ = 4.0_vp;
154     int32_t defaultProgressCount_ = 5;
155     int32_t defaultProgressMin_ = 2;
156     bool defaultLoop_ = true;
157     Dimension defaultStrokeWidth_ = 2.0_vp;
158     Dimension defaultStrokeWidthMin_ = 0.0_vp;
159     Dimension defaultStrokeRadius_ = 1.0_vp;
160     int32_t defaultIntervalTime_ = 0;
161     int32_t defaultDurationTime_ = 4000;
162 
163     Dimension defaultHeight_ = 24.0_vp;
164 };
165 } // namespace OHOS::Ace::NG
166 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LINEAR_INDICATOR_LINEAR_INDICATOR_THEME_H
167