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