• 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 Dimension STEPPER_FOCUSED_BORDER_WIDTH = 2.0_vp;
29 constexpr Dimension STEPPER_SCREEN_MARGIN = 4.0_vp;
30 } // namespace
31 /**
32  * StepperTheme defines color and styles of StepperComponent. StepperTheme should be built
33  * using StepperTheme::Builder.
34  */
35 class StepperTheme : public virtual Theme {
36     DECLARE_ACE_TYPE(StepperTheme, Theme);
37 
38 public:
39     class Builder {
40     public:
41         Builder() = default;
42         ~Builder() = default;
43 
Build(const RefPtr<ThemeConstants> & themeConstants)44         RefPtr<StepperTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
45         {
46             RefPtr<StepperTheme> theme = AceType::Claim(new StepperTheme());
47             if (!themeConstants) {
48                 return theme;
49             }
50             theme->textStyle_.SetTextColor(themeConstants->GetColor(THEME_STEPPER_TEXT_COLOR));
51             theme->textStyle_.SetFontSize(themeConstants->GetDimension(THEME_STEPPER_TEXT_FONTSIZE));
52             theme->textStyle_.SetFontWeight(FontWeight(themeConstants->GetInt(THEME_STEPPER_TEXT_FONTWEIGHT)));
53             theme->textStyle_.SetFontStyle(FontStyle::NORMAL);
54             theme->textStyle_.SetTextDecoration(TextDecoration::NONE);
55             std::vector<std::string> families;
56             families.emplace_back("sans-serif");
57             theme->textStyle_.SetFontFamilies(families);
58             theme->minFontSize_ = themeConstants->GetDimension(THEME_STEPPER_TEXT_FONTSIZE_MIN);
59             uint32_t maxlines = static_cast<uint32_t>(themeConstants->GetInt(THEME_STEPPER_TEXT_MAX_LINES));
60             theme->textMaxLines_ = maxlines < 0 ? theme->textMaxLines_ : maxlines;
61             theme->defaultPaddingStart_ = themeConstants->GetDimension(THEME_STEPPER_DEFAULT_PADDING_START);
62             theme->defaultPaddingEnd_ = themeConstants->GetDimension(THEME_STEPPER_DEFAULT_PADDING_END);
63             theme->progressColor_ = themeConstants->GetColor(THEME_STEPPER_PROGRESS_COLOR);
64             theme->progressDiameter_ = themeConstants->GetDimension(THEME_STEPPER_PROGRESS_DIAMETER);
65             theme->arrowWidth_ = themeConstants->GetDimension(THEME_STEPPER_ARROW_WIDTH_DIAMETER);
66             theme->arrowHeight_ = themeConstants->GetDimension(THEME_STEPPER_ARROW_HEIGHT_DIAMETER);
67             theme->arrowColor_ = themeConstants->GetColor(THEME_STEPPER_ARROW_COLOR);
68             theme->disabledColor_ = themeConstants->GetColor(THEME_STEPPER_DISABLED_COLOR);
69             theme->radius_ = themeConstants->GetDimension(THEME_STEPPER_RADIUS);
70             theme->buttonPressedColor_ = themeConstants->GetColor(THEME_STEPPER_BUTTON_PRESSED_COLOR);
71             theme->buttonPressedHeight_ = themeConstants->GetDimension(THEME_STEPPER_BUTTON_PRESSED_HEIGHT);
72             theme->controlHeight_ = themeConstants->GetDimension(THEME_STEPPER_CONTROL_HEIGHT);
73             theme->controlMargin_ = themeConstants->GetDimension(THEME_STEPPER_CONTROL_MARGIN);
74             theme->controlPadding_ = themeConstants->GetDimension(THEME_STEPPER_CONTROL_PADDING);
75             theme->focusColor_ = themeConstants->GetColor(THEME_STEPPER_FOCUS_COLOR);
76             theme->focusBorderWidth_ = themeConstants->GetDimension(THEME_STEPPER_FOCUS_BORDER_WIDTH);
77             theme->mouseHoverColor_ = themeConstants->GetColor(THEME_STEPPER_MOUSE_HOVER_COLOR);
78             theme->disabledAlpha_ = themeConstants->GetDouble(THEME_STEPPER_DISABLED_ALPHA);
79             auto themeStyle = themeConstants->GetThemeStyle();
80             if (themeStyle) {
81                 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("stepper_pattern", nullptr);
82                 if (pattern) {
83                     theme->textStyle_.SetTextColor(pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color::RED));
84                     theme->textStyle_.SetFontSize(pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 16.0_vp));
85                     theme->radius_ = pattern->GetAttr<Dimension>("border_radius", 8.0_vp);
86                     theme->buttonPressedColor_ = pattern->GetAttr<Color>("button_bg_color_pressed", Color::RED);
87                     theme->mouseHoverColor_ = pattern->GetAttr<Color>("button_bg_color_hovered", Color::RED);
88                     theme->defaultPaddingStart_ = pattern->GetAttr<Dimension>("padding_left", 12.0_vp);
89                     theme->defaultPaddingEnd_ = pattern->GetAttr<Dimension>("padding_right", 12.0_vp);
90                     theme->arrowColor_ = pattern->GetAttr<Color>("arrorw_color", Color::RED);
91                     theme->progressColor_ = pattern->GetAttr<Color>("progress_color", Color::RED);
92                     theme->disabledColor_ = pattern->GetAttr<Color>("button_bg_color_disabled", Color::RED);
93                     theme->disabledAlpha_ = pattern->GetAttr<double>("button_bg_color_disabled_alpha", 0.0);
94                     theme->defaultAlpha_ = pattern->GetAttr<double>("attribute_alpha_content_primary", 0.9);
95                     theme->focusColor_ = pattern->GetAttr<Color>(STEPPER_FOCUS_COLOR, Color::RED);
96                     theme->focusBorderWidth_ = STEPPER_FOCUSED_BORDER_WIDTH;
97                     theme->controlMargin_ = STEPPER_SCREEN_MARGIN;
98                 }
99             }
100             return theme;
101         }
102     };
103 
104     ~StepperTheme() override = default;
105 
GetTextStyle()106     const TextStyle& GetTextStyle() const
107     {
108         return textStyle_;
109     }
110 
GetMinFontSize()111     const Dimension& GetMinFontSize() const
112     {
113         return minFontSize_;
114     }
115 
GetTextMaxLines()116     uint32_t GetTextMaxLines() const
117     {
118         return textMaxLines_;
119     }
120 
GetDefaultPaddingStart()121     const Dimension& GetDefaultPaddingStart() const
122     {
123         return defaultPaddingStart_;
124     }
125 
GetDefaultPaddingEnd()126     const Dimension& GetDefaultPaddingEnd() const
127     {
128         return defaultPaddingEnd_;
129     }
130 
GetProgressColor()131     const Color& GetProgressColor() const
132     {
133         return progressColor_;
134     }
135 
GetProgressDiameter()136     const Dimension& GetProgressDiameter() const
137     {
138         return progressDiameter_;
139     }
140 
GetArrowWidth()141     const Dimension& GetArrowWidth() const
142     {
143         return arrowWidth_;
144     }
145 
GetArrowHeight()146     const Dimension& GetArrowHeight() const
147     {
148         return arrowHeight_;
149     }
150 
GetArrowColor()151     const Color& GetArrowColor() const
152     {
153         return arrowColor_;
154     }
155 
GetDisabledColor()156     const Color& GetDisabledColor() const
157     {
158         return disabledColor_;
159     }
160 
GetRadius()161     const Dimension& GetRadius() const
162     {
163         return radius_;
164     }
165 
GetButtonPressedColor()166     const Color& GetButtonPressedColor() const
167     {
168         return buttonPressedColor_;
169     }
170 
GetButtonPressedHeight()171     const Dimension& GetButtonPressedHeight() const
172     {
173         return buttonPressedHeight_;
174     }
175 
GetControlHeight()176     const Dimension& GetControlHeight() const
177     {
178         return controlHeight_;
179     }
180 
GetControlMargin()181     const Dimension& GetControlMargin() const
182     {
183         return controlMargin_;
184     }
185 
GetControlPadding()186     const Dimension& GetControlPadding() const
187     {
188         return controlPadding_;
189     }
190 
GetFocusColor()191     const Color& GetFocusColor() const
192     {
193         return focusColor_;
194     }
195 
GetFocusBorderWidth()196     const Dimension& GetFocusBorderWidth() const
197     {
198         return focusBorderWidth_;
199     }
200 
GetMouseHoverColor()201     const Color& GetMouseHoverColor() const
202     {
203         return mouseHoverColor_;
204     }
205 
GetDisabledAlpha()206     double GetDisabledAlpha() const
207     {
208         return disabledAlpha_;
209     }
210 
GetDefaultAlpha()211     double GetDefaultAlpha() const
212     {
213         return defaultAlpha_;
214     }
215 
216 protected:
217     StepperTheme() = default;
218 
219 private:
220     TextStyle textStyle_;
221     Dimension minFontSize_;
222     uint32_t textMaxLines_ = 1;
223     Dimension defaultPaddingStart_;
224     Dimension defaultPaddingEnd_;
225     Color progressColor_;
226     Dimension progressDiameter_;
227     Dimension arrowWidth_;
228     Dimension arrowHeight_;
229     Color arrowColor_;
230     Color disabledColor_;
231     Dimension radius_;
232     Color buttonPressedColor_;
233     Dimension buttonPressedHeight_;
234     Dimension controlHeight_;
235     Dimension controlMargin_;
236     Dimension controlPadding_;
237     Color focusColor_;
238     Dimension focusBorderWidth_;
239     Color mouseHoverColor_;
240     double disabledAlpha_ = 0.4;
241     double defaultAlpha_ = 0.9;
242 };
243 
244 } // namespace OHOS::Ace
245 
246 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STEPPER_STEPPER_THEME_H
247