• 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 
51             auto themeStyle = themeConstants->GetThemeStyle();
52             if (themeStyle) {
53                 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("stepper_pattern", nullptr);
54                 if (pattern) {
55                     theme->textStyle_.SetTextColor(pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color::RED));
56                     theme->textStyle_.SetFontSize(pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 16.0_vp));
57                     theme->radius_ = pattern->GetAttr<Dimension>("border_radius", 8.0_vp);
58                     theme->buttonPressedColor_ = pattern->GetAttr<Color>("button_bg_color_pressed", Color::RED);
59                     theme->mouseHoverColor_ = pattern->GetAttr<Color>("button_bg_color_hovered", Color::RED);
60                     theme->defaultPaddingStart_ = pattern->GetAttr<Dimension>("padding_left", 12.0_vp);
61                     theme->defaultPaddingEnd_ = pattern->GetAttr<Dimension>("padding_right", 12.0_vp);
62                     theme->arrowColor_ = pattern->GetAttr<Color>("arrorw_color", Color::RED);
63                     theme->progressColor_ = pattern->GetAttr<Color>("progress_color", Color::RED);
64                     theme->disabledColor_ = pattern->GetAttr<Color>("button_bg_color_disabled", Color::RED);
65                     theme->disabledAlpha_ = pattern->GetAttr<double>("button_bg_color_disabled_alpha", 0.0);
66                     theme->defaultAlpha_ = pattern->GetAttr<double>("attribute_alpha_content_primary", 0.9);
67                     theme->focusColor_ = pattern->GetAttr<Color>(STEPPER_FOCUS_COLOR, Color::RED);
68                     theme->focusBorderWidth_ = STEPPER_FOCUSED_BORDER_WIDTH;
69                     theme->controlMargin_ = STEPPER_SCREEN_MARGIN;
70 
71                     theme->textStyle_.SetFontWeight(FontWeight(pattern->GetAttr<int>("stepper_text_fontweight",
72                         static_cast<int32_t>(FontWeight::W500))));
73                     theme->textStyle_.SetFontStyle(FontStyle::NORMAL);
74                     theme->textStyle_.SetTextDecoration(TextDecoration::NONE);
75                     std::vector<std::string> families;
76                     families.emplace_back("sans-serif");
77                     theme->textStyle_.SetFontFamilies(families);
78                     theme->minFontSize_ = pattern->GetAttr<Dimension>("text_fontsize_min", 9.0_fp);
79                     uint32_t maxlines = static_cast<uint32_t>(pattern->GetAttr<int>("text_max_lines", 2));
80                     theme->textMaxLines_ = maxlines < 0 ? theme->textMaxLines_ : maxlines;
81                     theme->progressDiameter_ = pattern->GetAttr<Dimension>("progress_diameter", 24.0_vp);
82                     theme->arrowWidth_ = pattern->GetAttr<Dimension>("arrow_width_diameter", 12.0_vp);
83                     theme->arrowHeight_ = pattern->GetAttr<Dimension>("arrow_height_diameter", 24.0_vp);
84                     theme->buttonPressedHeight_ = pattern->GetAttr<Dimension>("button_pressed_height", 40.0_vp);
85                     theme->controlHeight_ = pattern->GetAttr<Dimension>("control_height", 48.0_vp);
86                     theme->controlPadding_ = pattern->GetAttr<Dimension>("control_padding", 8.0_vp);
87                 }
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 
GetDefaultAlpha()200     double GetDefaultAlpha() const
201     {
202         return defaultAlpha_;
203     }
204 
205 protected:
206     StepperTheme() = default;
207 
208 private:
209     TextStyle textStyle_;
210     Dimension minFontSize_;
211     uint32_t textMaxLines_ = 1;
212     Dimension defaultPaddingStart_;
213     Dimension defaultPaddingEnd_;
214     Color progressColor_;
215     Dimension progressDiameter_;
216     Dimension arrowWidth_;
217     Dimension arrowHeight_;
218     Color arrowColor_;
219     Color disabledColor_;
220     Dimension radius_;
221     Color buttonPressedColor_;
222     Dimension buttonPressedHeight_;
223     Dimension controlHeight_;
224     Dimension controlMargin_;
225     Dimension controlPadding_;
226     Color focusColor_;
227     Dimension focusBorderWidth_;
228     Color mouseHoverColor_;
229     double disabledAlpha_ = 0.4;
230     double defaultAlpha_ = 0.9;
231 };
232 
233 } // namespace OHOS::Ace
234 
235 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STEPPER_STEPPER_THEME_H
236