• 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                 theme->textStyle_.SetTextColor(themeStyle->GetAttr<Color>(THEME_ATTR_TEXT_COLOR_PRIMARY, Color::RED));
79                 theme->radius_ = themeStyle->GetAttr<Dimension>(THEME_ATTR_CLICK_CORNER_RADIUS, 0.0_vp);
80                 theme->buttonPressedColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_CLICK_EFFECT, Color::RED);
81                 theme->mouseHoverColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_HOVER, Color::RED);
82                 theme->defaultPaddingStart_ = themeStyle->GetAttr<Dimension>(THEME_ATTR_DEFAULT_PADDING_START, 0.0_vp);
83                 theme->defaultPaddingEnd_ = themeStyle->GetAttr<Dimension>(THEME_ATTR_DEFAULT_PADDING_END, 0.0_vp);
84                 theme->arrowColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_PRIMARY, Color::RED);
85                 theme->progressColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_PROGRESS, Color::RED);
86                 theme->disabledColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_TEXT_COLOR_PRIMARY, Color::RED);
87                 theme->disabledAlpha_ = themeStyle->GetAttr<double>(THEME_ATTR_DISABLED_ALPHA, 0.0);
88             }
89             return theme;
90         }
91     };
92 
93     ~StepperTheme() override = default;
94 
GetTextStyle()95     const TextStyle& GetTextStyle() const
96     {
97         return textStyle_;
98     }
99 
GetMinFontSize()100     const Dimension& GetMinFontSize() const
101     {
102         return minFontSize_;
103     }
104 
GetTextMaxLines()105     uint32_t GetTextMaxLines() const
106     {
107         return textMaxLines_;
108     }
109 
GetDefaultPaddingStart()110     const Dimension& GetDefaultPaddingStart() const
111     {
112         return defaultPaddingStart_;
113     }
114 
GetDefaultPaddingEnd()115     const Dimension& GetDefaultPaddingEnd() const
116     {
117         return defaultPaddingEnd_;
118     }
119 
GetProgressColor()120     const Color& GetProgressColor() const
121     {
122         return progressColor_;
123     }
124 
GetProgressDiameter()125     const Dimension& GetProgressDiameter() const
126     {
127         return progressDiameter_;
128     }
129 
GetArrowWidth()130     const Dimension& GetArrowWidth() const
131     {
132         return arrowWidth_;
133     }
134 
GetArrowHeight()135     const Dimension& GetArrowHeight() const
136     {
137         return arrowHeight_;
138     }
139 
GetArrowColor()140     const Color& GetArrowColor() const
141     {
142         return arrowColor_;
143     }
144 
GetDisabledColor()145     const Color& GetDisabledColor() const
146     {
147         return disabledColor_;
148     }
149 
GetRadius()150     const Dimension& GetRadius() const
151     {
152         return radius_;
153     }
154 
GetButtonPressedColor()155     const Color& GetButtonPressedColor() const
156     {
157         return buttonPressedColor_;
158     }
159 
GetButtonPressedHeight()160     const Dimension& GetButtonPressedHeight() const
161     {
162         return buttonPressedHeight_;
163     }
164 
GetControlHeight()165     const Dimension& GetControlHeight() const
166     {
167         return controlHeight_;
168     }
169 
GetControlMargin()170     const Dimension& GetControlMargin() const
171     {
172         return controlMargin_;
173     }
174 
GetControlPadding()175     const Dimension& GetControlPadding() const
176     {
177         return controlPadding_;
178     }
179 
GetFocusColor()180     const Color& GetFocusColor() const
181     {
182         return focusColor_;
183     }
184 
GetFocusBorderWidth()185     const Dimension& GetFocusBorderWidth() const
186     {
187         return focusBorderWidth_;
188     }
189 
GetMouseHoverColor()190     const Color& GetMouseHoverColor() const
191     {
192         return mouseHoverColor_;
193     }
194 
GetDisabledAlpha()195     double GetDisabledAlpha() const
196     {
197         return disabledAlpha_;
198     }
199 
200 protected:
201     StepperTheme() = default;
202 
203 private:
204     TextStyle textStyle_;
205     Dimension minFontSize_;
206     uint32_t textMaxLines_ = 1;
207     Dimension defaultPaddingStart_;
208     Dimension defaultPaddingEnd_;
209     Color progressColor_;
210     Dimension progressDiameter_;
211     Dimension arrowWidth_;
212     Dimension arrowHeight_;
213     Color arrowColor_;
214     Color disabledColor_;
215     Dimension radius_;
216     Color buttonPressedColor_;
217     Dimension buttonPressedHeight_;
218     Dimension controlHeight_;
219     Dimension controlMargin_;
220     Dimension controlPadding_;
221     Color focusColor_;
222     Dimension focusBorderWidth_;
223     Color mouseHoverColor_;
224     double disabledAlpha_ = 0.4;
225 };
226 
227 } // namespace OHOS::Ace
228 
229 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STEPPER_STEPPER_THEME_H
230