• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_NG_PATTERNS_MENU_MENU_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_THEME_H
18 
19 #include <cstdint>
20 
21 #include "core/components/theme/theme.h"
22 #include "frameworks/base/geometry/dimension.h"
23 
24 namespace OHOS::Ace::NG {
25 constexpr Dimension GRADIENT_HEIGHT = Dimension(50, DimensionUnit::VP);
26 
27 constexpr uint8_t GRADIENT_END_GRADIENT = 255;
28 constexpr uint32_t DEFAULT_BACKGROUND_COLOR = 0xFFFFFFF;
29 constexpr uint32_t MENU_MIN_GRID_COUNTS = 2;
30 constexpr uint32_t MENU_MAX_GRID_COUNTS = 6;
31 constexpr double OUTBORDER_RADIUS = 19.75; // Default value of outBorderRadius
32 
33 /**
34  * MenuTheme defines styles of menu item. MenuTheme should be built
35  * using MenuTheme::Builder.
36  */
37 class MenuTheme : public virtual Theme {
38     DECLARE_ACE_TYPE(MenuTheme, Theme);
39 
40 public:
41     class Builder {
42     public:
43         Builder() = default;
44         ~Builder() = default;
45 
Build(const RefPtr<ThemeConstants> & themeConstants)46         RefPtr<MenuTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
47         {
48             RefPtr<MenuTheme> theme = AceType::Claim(new MenuTheme());
49             if (!themeConstants) {
50                 return theme;
51             }
52             ParsePattern(themeConstants->GetThemeStyle(), theme);
53             return theme;
54         }
55 
56     private:
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<MenuTheme> & theme)57         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<MenuTheme>& theme) const
58         {
59             if (!themeStyle) {
60                 return;
61             }
62             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_SELECT, nullptr);
63             if (!pattern) {
64                 LOGE("Pattern of menu is null, please check!");
65                 return;
66             }
67             theme->previewMenuMaskColor_ = pattern->GetAttr<Color>("preview_menu_mask_color", Color(0x33182431));
68             theme->bgBlurEffectEnable_ =
69                 StringUtils::StringToInt(pattern->GetAttr<std::string>("menu_bg_blur_effect_enable", "0"));
70             theme->bgEffectSaturation_ = pattern->GetAttr<double>("menu_blur_effect_saturation", 1.0);
71             theme->bgEffectBrightness_ = pattern->GetAttr<double>("menu_blur_effect_brightness", 1.0);
72             theme->bgEffectRadius_ = pattern->GetAttr<Dimension>("menu_blur_effect_radius", 0.0_vp);
73             theme->bgEffectColor_ = pattern->GetAttr<Color>("menu_blur_effect_color", Color::TRANSPARENT);
74             theme->doubleBorderEnable_ =
75                 StringUtils::StringToInt(pattern->GetAttr<std::string>("menu_double_border_enable", "0"));
76             theme->outerBorderWidth_ = pattern->GetAttr<double>("menu_outer_border_width", 1.0);
77             theme->outerBorderRadius_ = pattern->GetAttr<double>("menu_outer_border_radius", OUTBORDER_RADIUS);
78             theme->outerBorderColor_ = pattern->GetAttr<Color>("menu_outer_border_color", Color::TRANSPARENT);
79             theme->innerBorderWidth_ = pattern->GetAttr<double>("menu_inner_border_width", 1.0);
80             theme->innerBorderRadius_ = pattern->GetAttr<Dimension>("menu_inner_border_radius", 0.0_vp);
81             theme->innerBorderColor_ = pattern->GetAttr<Color>("menu_inner_border_color", Color::TRANSPARENT);
82             theme->filterAnimationDuration_ = 250;
83             theme->previewAnimationDuration_ = 300;
84             theme->previewBeforeAnimationScale_ = 0.95f;
85             theme->previewAfterAnimationScale_ = 1.1f;
86             theme->menuAnimationScale_ = 0.4f;
87             theme->menuDragAnimationScale_ = 0.95f;
88             theme->springMotionResponse_ = 0.416f;
89             theme->springMotionDampingFraction_ = 0.73f;
90             theme->contextMenuAppearDuration_ = 250;
91             theme->disappearDuration_ = 250;
92             theme->previewDisappearSpringMotionResponse_ = 0.304f;
93             theme->previewDisappearSpringMotionDampingFraction_ = 0.97f;
94             theme->filterRadius_ = Dimension(100.0f);
95             theme->previewBorderRadius_ = 16.0_vp;
96             theme->previewMenuScaleNumber_ = 0.95f;
97         }
98     };
99 
100     ~MenuTheme() override = default;
101 
GetFilterAnimationDuration()102     int32_t GetFilterAnimationDuration() const
103     {
104         return filterAnimationDuration_;
105     }
106 
GetPreviewAnimationDuration()107     int32_t GetPreviewAnimationDuration() const
108     {
109         return previewAnimationDuration_;
110     }
111 
GetPreviewBeforeAnimationScale()112     float GetPreviewBeforeAnimationScale() const
113     {
114         return previewBeforeAnimationScale_;
115     }
116 
GetPreviewAfterAnimationScale()117     float GetPreviewAfterAnimationScale() const
118     {
119         return previewAfterAnimationScale_;
120     }
121 
GetMenuAnimationScale()122     float GetMenuAnimationScale() const
123     {
124         return menuAnimationScale_;
125     }
126 
GetMenuDragAnimationScale()127     float GetMenuDragAnimationScale() const
128     {
129         return menuDragAnimationScale_;
130     }
131 
GetSpringMotionResponse()132     float GetSpringMotionResponse() const
133     {
134         return springMotionResponse_;
135     }
136 
GetSpringMotionDampingFraction()137     float GetSpringMotionDampingFraction() const
138     {
139         return springMotionDampingFraction_;
140     }
141 
GetContextMenuAppearDuration()142     int32_t GetContextMenuAppearDuration() const
143     {
144         return contextMenuAppearDuration_;
145     }
146 
GetDisappearDuration()147     int32_t GetDisappearDuration() const
148     {
149         return disappearDuration_;
150     }
151 
GetPreviewDisappearSpringMotionResponse()152     float GetPreviewDisappearSpringMotionResponse() const
153     {
154         return previewDisappearSpringMotionResponse_;
155     }
156 
GetPreviewDisappearSpringMotionDampingFraction()157     float GetPreviewDisappearSpringMotionDampingFraction() const
158     {
159         return previewDisappearSpringMotionDampingFraction_;
160     }
161 
GetPreviewMenuScaleNumber()162     float GetPreviewMenuScaleNumber() const
163     {
164         return previewMenuScaleNumber_;
165     }
166 
GetFilterRadius()167     Dimension GetFilterRadius() const
168     {
169         return filterRadius_;
170     }
171 
GetPreviewBorderRadius()172     Dimension GetPreviewBorderRadius() const
173     {
174         return previewBorderRadius_;
175     }
176 
GetPreviewMenuMaskColor()177     Color GetPreviewMenuMaskColor() const
178     {
179         return previewMenuMaskColor_;
180     }
181 
GetBgBlurEffectEnable()182     int32_t GetBgBlurEffectEnable() const
183     {
184         return bgBlurEffectEnable_;
185     }
186 
GetBgEffectSaturation()187     double GetBgEffectSaturation() const
188     {
189         return bgEffectSaturation_;
190     }
191 
GetBgEffectBrightness()192     double GetBgEffectBrightness() const
193     {
194         return bgEffectBrightness_;
195     }
196 
GetBgEffectRadius()197     Dimension GetBgEffectRadius() const
198     {
199         return bgEffectRadius_;
200     }
201 
GetBgEffectColor()202     Color GetBgEffectColor() const
203     {
204         return bgEffectColor_;
205     }
206 
GetDoubleBorderEnable()207     int32_t GetDoubleBorderEnable() const
208     {
209         return doubleBorderEnable_;
210     }
211 
GetOuterBorderWidth()212     double GetOuterBorderWidth() const
213     {
214         return outerBorderWidth_;
215     }
216 
GetOuterBorderRadius()217     double GetOuterBorderRadius() const
218     {
219         return outerBorderRadius_;
220     }
221 
GetOuterBorderColor()222     Color GetOuterBorderColor() const
223     {
224         return outerBorderColor_;
225     }
226 
GetInnerBorderWidth()227     double GetInnerBorderWidth() const
228     {
229         return innerBorderWidth_;
230     }
231 
GetInnerBorderRadius()232     Dimension GetInnerBorderRadius() const
233     {
234         return innerBorderRadius_;
235     }
236 
GetInnerBorderColor()237     Color GetInnerBorderColor() const
238     {
239         return innerBorderColor_;
240     }
241 
242 protected:
243     MenuTheme() = default;
244 
245 private:
246     int32_t filterAnimationDuration_ = 0;
247     int32_t previewAnimationDuration_ = 0;
248     float previewBeforeAnimationScale_ = 1.0f;
249     float previewAfterAnimationScale_ = 1.0f;
250     float menuAnimationScale_ = 1.0f;
251     float menuDragAnimationScale_ = 1.0f;
252     float springMotionResponse_ = 0.0f;
253     float springMotionDampingFraction_ = 0.0f;
254     int32_t contextMenuAppearDuration_ = 0;
255     int32_t disappearDuration_ = 0;
256     float previewDisappearSpringMotionResponse_ = 0.0f;
257     float previewDisappearSpringMotionDampingFraction_ = 0.0f;
258     float previewMenuScaleNumber_ = 0.0f;
259     Dimension filterRadius_;
260     Dimension previewBorderRadius_;
261     Color previewMenuMaskColor_;
262     int32_t bgBlurEffectEnable_ = 0;
263     double bgEffectSaturation_ = 1.0f;
264     double bgEffectBrightness_ = 1.0f;
265     Dimension bgEffectRadius_;
266     Color bgEffectColor_ = Color::TRANSPARENT;
267     int32_t doubleBorderEnable_ = 0;
268     double outerBorderWidth_ = 1.0f;
269     double outerBorderRadius_ = 19.75f;
270     Color outerBorderColor_ = Color::TRANSPARENT;
271     double innerBorderWidth_ = 1.0f;
272     Dimension innerBorderRadius_;
273     Color innerBorderColor_ = Color::TRANSPARENT;
274 };
275 
276 } // namespace OHOS::Ace::NG
277 
278 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_THEME_H
279