• 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_STEPPER_STEPPER_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STEPPER_STEPPER_THEME_H
18 
19 #include "core/components/common/properties/color.h"
20 #include "core/components/common/properties/text_style.h"
21 #include "core/components/theme/theme.h"
22 #include "core/components/theme/theme_constants.h"
23 #include "core/components/theme/theme_constants_defines.h"
24 #include "core/components/theme/theme_manager.h"
25 
26 namespace OHOS::Ace {
27 namespace {
28 constexpr double DEFAULT_ALPHA_VALUE = 0.9;
29 constexpr Dimension STEPPER_FOCUSED_BORDER_WIDTH = 2.0_vp;
30 constexpr Dimension STEPPER_SCREEN_MARGIN = 4.0_vp;
31 } // namespace
32 /**
33  * StepperTheme defines color and styles of StepperComponent. StepperTheme should be built
34  * using StepperTheme::Builder.
35  */
36 class StepperTheme : public virtual Theme {
37     DECLARE_ACE_TYPE(StepperTheme, Theme);
38 
39 public:
40     class Builder {
41     public:
42         Builder() = default;
43         ~Builder() = default;
44 
Build(const RefPtr<ThemeConstants> & themeConstants)45         RefPtr<StepperTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
46         {
47             RefPtr<StepperTheme> theme = AceType::MakeRefPtr<StepperTheme>();
48             if (!themeConstants) {
49                 return theme;
50             }
51 
52             auto themeStyle = themeConstants->GetThemeStyle();
53             if (themeStyle) {
54                 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("stepper_pattern", nullptr);
55                 if (pattern) {
56                     theme->textStyle_.SetTextColor(pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color::RED));
57                     theme->textStyle_.SetFontSize(pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 16.0_vp));
58                     theme->radius_ = pattern->GetAttr<Dimension>("border_radius", 8.0_vp);
59                     theme->buttonPressedColor_ = pattern->GetAttr<Color>("button_bg_color_pressed", Color::RED);
60                     theme->mouseHoverColor_ = pattern->GetAttr<Color>("button_bg_color_hovered", Color::RED);
61                     theme->defaultPaddingStart_ = pattern->GetAttr<Dimension>("padding_left", 12.0_vp);
62                     theme->defaultPaddingEnd_ = pattern->GetAttr<Dimension>("padding_right", 12.0_vp);
63                     theme->arrowColor_ = pattern->GetAttr<Color>("arrorw_color", Color::RED);
64                     theme->progressColor_ = pattern->GetAttr<Color>("progress_color", Color::RED);
65                     theme->disabledColor_ = pattern->GetAttr<Color>("button_bg_color_disabled", Color::RED);
66                     theme->disabledAlpha_ = pattern->GetAttr<double>("button_bg_color_disabled_alpha", 0.0);
67                     theme->defaultAlpha_ =
68                         pattern->GetAttr<double>("attribute_alpha_content_primary", DEFAULT_ALPHA_VALUE);
69                     theme->focusColor_ = pattern->GetAttr<Color>(STEPPER_FOCUS_COLOR, Color::RED);
70                     theme->focusBorderWidth_ = STEPPER_FOCUSED_BORDER_WIDTH;
71                     theme->controlMargin_ = STEPPER_SCREEN_MARGIN;
72 
73                     theme->textStyle_.SetFontWeight(FontWeight(pattern->GetAttr<int>("stepper_text_fontweight",
74                         static_cast<int32_t>(FontWeight::W500))));
75                     theme->textStyle_.SetFontStyle(FontStyle::NORMAL);
76                     theme->textStyle_.SetTextDecoration(TextDecoration::NONE);
77                     std::vector<std::string> families;
78                     families.emplace_back("sans-serif");
79                     theme->textStyle_.SetFontFamilies(families);
80                     theme->minFontSize_ = pattern->GetAttr<Dimension>("text_fontsize_min", 9.0_fp);
81                     uint32_t maxlines = static_cast<uint32_t>(pattern->GetAttr<int>("text_max_lines", 2));
82                     theme->textMaxLines_ = maxlines < 0 ? theme->textMaxLines_ : maxlines;
83                     theme->progressDiameter_ = pattern->GetAttr<Dimension>("progress_diameter", 24.0_vp);
84                     theme->arrowWidth_ = pattern->GetAttr<Dimension>("arrow_width_diameter", 12.0_vp);
85                     theme->arrowHeight_ = pattern->GetAttr<Dimension>("arrow_height_diameter", 24.0_vp);
86                     theme->buttonPressedHeight_ = pattern->GetAttr<Dimension>("button_pressed_height", 40.0_vp);
87                     theme->controlHeight_ = pattern->GetAttr<Dimension>("control_height", 48.0_vp);
88                     theme->controlPadding_ = pattern->GetAttr<Dimension>("control_padding", 8.0_vp);
89                     theme->stepperBack_ = pattern->GetAttr<std::string>("stepper_back", "");
90                     theme->stepperSkip_ = pattern->GetAttr<std::string>("stepper_skip", "");
91                     theme->stepperStart_ = pattern->GetAttr<std::string>("stepper_start", "");
92                     theme->stepperNext_ = pattern->GetAttr<std::string>("stepper_next", "");
93                 }
94             }
95             return theme;
96         }
97     };
98 
99     ~StepperTheme() override = default;
100 
GetTextStyle()101     const TextStyle& GetTextStyle() const
102     {
103         return textStyle_;
104     }
105 
GetMinFontSize()106     const Dimension& GetMinFontSize() const
107     {
108         return minFontSize_;
109     }
110 
GetTextMaxLines()111     uint32_t GetTextMaxLines() const
112     {
113         return textMaxLines_;
114     }
115 
GetDefaultPaddingStart()116     const Dimension& GetDefaultPaddingStart() const
117     {
118         return defaultPaddingStart_;
119     }
120 
GetDefaultPaddingEnd()121     const Dimension& GetDefaultPaddingEnd() const
122     {
123         return defaultPaddingEnd_;
124     }
125 
GetProgressColor()126     const Color& GetProgressColor() const
127     {
128         return progressColor_;
129     }
130 
GetProgressDiameter()131     const Dimension& GetProgressDiameter() const
132     {
133         return progressDiameter_;
134     }
135 
GetArrowWidth()136     const Dimension& GetArrowWidth() const
137     {
138         return arrowWidth_;
139     }
140 
GetArrowHeight()141     const Dimension& GetArrowHeight() const
142     {
143         return arrowHeight_;
144     }
145 
GetArrowColor()146     const Color& GetArrowColor() const
147     {
148         return arrowColor_;
149     }
150 
GetDisabledColor()151     const Color& GetDisabledColor() const
152     {
153         return disabledColor_;
154     }
155 
GetRadius()156     const Dimension& GetRadius() const
157     {
158         return radius_;
159     }
160 
GetButtonPressedColor()161     const Color& GetButtonPressedColor() const
162     {
163         return buttonPressedColor_;
164     }
165 
GetButtonPressedHeight()166     const Dimension& GetButtonPressedHeight() const
167     {
168         return buttonPressedHeight_;
169     }
170 
GetControlHeight()171     const Dimension& GetControlHeight() const
172     {
173         return controlHeight_;
174     }
175 
GetControlMargin()176     const Dimension& GetControlMargin() const
177     {
178         return controlMargin_;
179     }
180 
GetControlPadding()181     const Dimension& GetControlPadding() const
182     {
183         return controlPadding_;
184     }
185 
GetFocusColor()186     const Color& GetFocusColor() const
187     {
188         return focusColor_;
189     }
190 
GetFocusBorderWidth()191     const Dimension& GetFocusBorderWidth() const
192     {
193         return focusBorderWidth_;
194     }
195 
GetMouseHoverColor()196     const Color& GetMouseHoverColor() const
197     {
198         return mouseHoverColor_;
199     }
200 
GetDisabledAlpha()201     double GetDisabledAlpha() const
202     {
203         return disabledAlpha_;
204     }
205 
GetDefaultAlpha()206     double GetDefaultAlpha() const
207     {
208         return defaultAlpha_;
209     }
210 
GetStepperBack()211     const std::string& GetStepperBack() const
212     {
213         return stepperBack_;
214     }
215 
GetStepperSkip()216     const std::string& GetStepperSkip() const
217     {
218         return stepperSkip_;
219     }
220 
GetStepperStart()221     const std::string& GetStepperStart() const
222     {
223         return stepperStart_;
224     }
225 
GetStepperNext()226     const std::string& GetStepperNext() const
227     {
228         return stepperNext_;
229     }
230 protected:
231     StepperTheme() = default;
232 
233 private:
234     TextStyle textStyle_;
235     Dimension minFontSize_;
236     uint32_t textMaxLines_ = 1;
237     Dimension defaultPaddingStart_;
238     Dimension defaultPaddingEnd_;
239     Color progressColor_;
240     Dimension progressDiameter_;
241     Dimension arrowWidth_;
242     Dimension arrowHeight_;
243     Color arrowColor_;
244     Color disabledColor_;
245     Dimension radius_;
246     Color buttonPressedColor_;
247     Dimension buttonPressedHeight_;
248     Dimension controlHeight_;
249     Dimension controlMargin_;
250     Dimension controlPadding_;
251     Color focusColor_;
252     Dimension focusBorderWidth_;
253     Color mouseHoverColor_;
254     double disabledAlpha_ = 0.4;
255     double defaultAlpha_ = 0.9;
256     std::string stepperBack_ = "";
257     std::string stepperSkip_ = "";
258     std::string stepperStart_ = "";
259     std::string stepperNext_ = "";
260 };
261 
262 } // namespace OHOS::Ace
263 
264 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STEPPER_STEPPER_THEME_H
265