• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_SHEET_SHEET_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHEET_SHEET_THEME_H
18 
19 #include "core/components/common/properties/color.h"
20 #include "core/components/theme/theme.h"
21 #include "core/components/theme/theme_constants.h"
22 
23 namespace OHOS::Ace::NG {
24 namespace {
25 constexpr Dimension SHEET_BLANK_MINI_HEIGHT = 8.0_vp;
26 constexpr Dimension SHEET_HOVERMODE_UP_HEIGHT = 40.0_vp;
27 constexpr Dimension SHEET_HOVERMODE_DOWN_HEIGHT = 28.0_vp;
28 constexpr Dimension SHEET_BLANK_FLOATING_STATUS_BAR = 32.0_vp;
29 constexpr Dimension SHEET_SPLIT_AI_BAR = 24.0_vp;
30 constexpr Dimension SHEET_SPLIT_STATUS_BAR = 24.0_vp;
31 constexpr Dimension SHEET_OPERATION_AREA_PADDING = 8.0_vp;
32 constexpr Dimension SHEET_OPERATION_AREA_HEIGHT = 56.0_vp;
33 constexpr Dimension SHEET_OPERATION_AREA_HEIGHT_DOUBLE = 72.0_vp;
34 constexpr Dimension SHEET_CLOSE_ICON_WIDTH = 40.0_vp;
35 constexpr Dimension SHEET_CLOSE_ICON_HEIGHT = 40.0_vp;
36 constexpr Dimension SHEET_CLOSE_ICON_IMAGE_HEIGHT = 18.0_vp;
37 constexpr Dimension SHEET_CLOSE_ICON_IMAGE_WIDTH = 18.0_vp;
38 constexpr Dimension SHEET_CLOSE_ICON_TITLE_SPACE = 32.0_vp;
39 constexpr Dimension SHEET_CLOSE_ICON_TITLE_SPACE_NEW = 8.0_vp;
40 constexpr Dimension SHEET_CLOSE_ICON_RADIUS = 20.0_vp;
41 constexpr Dimension SHEET_DRAG_BAR_WIDTH = 64.0_vp;
42 constexpr Dimension SHEET_DRAG_BAR_HEIGHT = 16.0_vp;
43 constexpr Dimension SHEET_LANDSCAPE_WIDTH = 480.0_vp;
44 constexpr Dimension SHEET_POPUP_WIDTH = 360.0_vp;
45 constexpr Dimension SHEET_BIG_WINDOW_WIDTH = 480.0_vp;
46 constexpr Dimension SHEET_BIG_WINDOW_HEIGHT = 560.0_vp;
47 constexpr Dimension SHEET_BIG_WINDOW_MIN_HEIGHT = 320.0_vp;
48 constexpr Dimension SHEET_ARROW_WIDTH = 32.0_vp;
49 constexpr Dimension SHEET_ARROW_HEIGHT = 8.0_vp;
50 constexpr Dimension SHEET_TARGET_SPACE = 8.0_vp;
51 constexpr Dimension SHEET_DEVICE_WIDTH_BREAKPOINT = 600.0_vp;
52 constexpr Dimension SHEET_PC_DEVICE_WIDTH_BREAKPOINT = 840.0_vp;
53 constexpr Dimension SHEET_DOUBLE_TITLE_TOP_PADDING = 16.0_vp;
54 constexpr Dimension SHEET_DOUBLE_TITLE_BOTTON_MARGIN = 4.0_vp;
55 constexpr Dimension SHEET_TITLE_AERA_MARGIN = -8.0_vp;
56 constexpr int32_t SHEET_TITLE_MAX_LINES = 1;
57 constexpr int32_t SHEET_SHADOW_NONE = 6;
58 constexpr Dimension SHEET_TITLE_TEXT_HORIZONTAL_MARGIN = 16.0_vp;
59 } // namespace
60 class SheetTheme : public virtual Theme {
61     DECLARE_ACE_TYPE(SheetTheme, Theme);
62 
63 public:
64     class Builder {
65     public:
66         Builder() = default;
67         ~Builder() = default;
68 
Build(const RefPtr<ThemeConstants> & themeConstants)69         RefPtr<SheetTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
70         {
71             RefPtr<SheetTheme> theme = AceType::Claim(new SheetTheme());
72             if (!themeConstants) {
73                 return theme;
74             }
75 
76             ParsePattern(themeConstants, theme);
77             return theme;
78         }
79 
80     private:
ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SheetTheme> & theme)81         void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SheetTheme>& theme) const
82         {
83             RefPtr<ThemeStyle> sheetPattern = themeConstants->GetPatternByName(THEME_PATTERN_SHEET);
84             if (!sheetPattern) {
85                 TAG_LOGE(AceLogTag::ACE_SHEET, "sheetPattern is null");
86                 return;
87             }
88 
89             theme->sheetRadius_ = sheetPattern->GetAttr<Dimension>("sheet_radius", 32.0_vp);
90             theme->titleTextFontSize_ = sheetPattern->GetAttr<Dimension>("title_text_font_size", 20.0_vp);
91             theme->titleTextMargin_ = sheetPattern->GetAttr<Dimension>("title_text_margin", 16.0_vp);
92             theme->subtitleTextFontSize_ = sheetPattern->GetAttr<Dimension>("subtitle_text_font_size", 14.0_fp);
93             theme->subtitleTextMargin_ = sheetPattern->GetAttr<Dimension>("subtitle_text_margin", 2.0_fp);
94             theme->titleTextFontColor_ = sheetPattern->GetAttr<Color>("title_text_font_color", Color(0xff182431));
95             theme->subtitleTextFontColor_ = sheetPattern->GetAttr<Color>("subtitle_text_font_color", Color(0x99182431));
96             theme->sheetBackgoundColor_ = sheetPattern->GetAttr<Color>("sheet_background_color", Color(0xfff1f3f5));
97             theme->dragBarColor_ = sheetPattern->GetAttr<Color>("drag_bar_color", Color(0x33182431));
98             theme->sheetType_ = sheetPattern->GetAttr<std::string>("sheet_type", "auto");
99             theme->sheetBottom_ = sheetPattern->GetAttr<std::string>("sheet_bottom", "auto");
100             theme->maskColor_ = sheetPattern->GetAttr<Color>("mask_color", Color(0x33182431));
101             theme->closeIconColor_ = sheetPattern->GetAttr<Color>("close_icon_color", Color(0x0c182431));
102             theme->closeIconImageColor_ = sheetPattern->GetAttr<Color>("close_icon_image_color", Color(0xff182431));
103             theme->sheetBackgroundBlurStyle_ = sheetPattern->GetAttr<int>("sheet_background_blur_style", 0);
104             theme->sheetNormalScale_ = sheetPattern->GetAttr<double>("sheet_normal_aging_scale", 1.0f);
105             theme->sheetMaxAgingScale_ = sheetPattern->GetAttr<double>("sheet_max_aging_scale", 1.75f);
106             theme->closeIconSource_ = themeConstants->GetSymbolByName("sys.symbol.xmark");
107             theme->closeIconSymbolColor_ = sheetPattern->GetAttr<Color>("close_icon_symbol_color", Color(0xff182431));
108             theme->sheetShadowConfig_ = sheetPattern->GetAttr<int>("sheet_shadow_config", SHEET_SHADOW_NONE);
109             theme->sheetOuterBorderWidth_ = sheetPattern->GetAttr<Dimension>("sheet_outline_border_width", 0.0_vp);
110             // If the outline border width is valid, outline border, shadow and border are default enable.
111             theme->isOuterBorderEnable_ = theme->sheetOuterBorderWidth_.IsValid();
112             theme->sheetInnerBorderWidth_ = sheetPattern->GetAttr<Dimension>("sheet_inner_border_width", 0.0_vp);
113             theme->sheetOuterBorderColor_ =
114                 sheetPattern->GetAttr<Color>("sheet_outline_border_color", Color::TRANSPARENT);
115             theme->sheetInnerBorderColor_ =
116                 sheetPattern->GetAttr<Color>("sheet_inner_border_color", Color::TRANSPARENT);
117             theme->closeIconWidth_ =
118                 sheetPattern->GetAttr<Dimension>("close_icon_width", SHEET_CLOSE_ICON_IMAGE_HEIGHT);
119             theme->titleTextHorizMargin_ =
120                 sheetPattern->GetAttr<Dimension>("title_text_horizontal_margin", SHEET_TITLE_TEXT_HORIZONTAL_MARGIN);
121             theme->closeIconRadius_ = sheetPattern->GetAttr<Dimension>("close_icon_radius", SHEET_CLOSE_ICON_RADIUS);
122         }
123     };
124     ~SheetTheme() override = default;
125 
GetSheetRadius()126     const Dimension& GetSheetRadius() const
127     {
128         return sheetRadius_;
129     }
130 
GetTitleTextFontSize()131     const Dimension& GetTitleTextFontSize() const
132     {
133         return titleTextFontSize_;
134     }
135 
GetTitleTextMargin()136     const Dimension& GetTitleTextMargin() const
137     {
138         return titleTextMargin_;
139     }
140 
GetSubtitleTextFontSize()141     const Dimension& GetSubtitleTextFontSize() const
142     {
143         return subtitleTextFontSize_;
144     }
145 
GetSubtitleTextMargin()146     const Dimension& GetSubtitleTextMargin() const
147     {
148         return subtitleTextMargin_;
149     }
150 
GetTitleTextFontColor()151     const Color& GetTitleTextFontColor() const
152     {
153         return titleTextFontColor_;
154     }
155 
GetSubtitleTextFontColor()156     const Color& GetSubtitleTextFontColor() const
157     {
158         return subtitleTextFontColor_;
159     }
160 
GetSheetBackgoundColor()161     const Color& GetSheetBackgoundColor() const
162     {
163         return sheetBackgoundColor_;
164     }
165 
GetDragBarColor()166     const Color& GetDragBarColor() const
167     {
168         return dragBarColor_;
169     }
170 
GetMaskColor()171     const Color& GetMaskColor() const
172     {
173         return maskColor_;
174     }
175 
GetCloseIconColor()176     const Color& GetCloseIconColor() const
177     {
178         return closeIconColor_;
179     }
180 
GetCloseIconImageColor()181     const Color& GetCloseIconImageColor() const
182     {
183         return closeIconImageColor_;
184     }
185 
IsOnlyBottom()186     bool IsOnlyBottom() const
187     {
188         return sheetBottom_ == "bottom";
189     }
190 
GetSheetType()191     const std::string& GetSheetType() const
192     {
193         return sheetType_;
194     }
195 
GetSheetBackgroundBlurStyle()196     const int& GetSheetBackgroundBlurStyle() const
197     {
198         return sheetBackgroundBlurStyle_;
199     }
200 
GetSheetNormalScale()201     const double& GetSheetNormalScale() const
202     {
203         return sheetNormalScale_;
204     }
205 
GetSheetMaxAgingScale()206     const double& GetSheetMaxAgingScale() const
207     {
208         return sheetMaxAgingScale_;
209     }
210 
GetCloseIconSymbolColor()211     const Color& GetCloseIconSymbolColor() const
212     {
213         return closeIconSymbolColor_;
214     }
215 
GetCloseIconSource()216     const uint32_t& GetCloseIconSource() const
217     {
218         return closeIconSource_;
219     }
220 
GetSheetShadowConfig()221     const int& GetSheetShadowConfig() const
222     {
223         return sheetShadowConfig_;
224     }
225 
GetSheetOuterBorderWidth()226     const Dimension& GetSheetOuterBorderWidth() const
227     {
228         return sheetOuterBorderWidth_;
229     }
230 
GetSheetInnerBorderWidth()231     const Dimension& GetSheetInnerBorderWidth() const
232     {
233         return sheetInnerBorderWidth_;
234     }
235 
GetSheetOuterBorderColor()236     const Color& GetSheetOuterBorderColor() const
237     {
238         return sheetOuterBorderColor_;
239     }
240 
GetSheetInnerBorderColor()241     const Color& GetSheetInnerBorderColor() const
242     {
243         return sheetInnerBorderColor_;
244     }
245 
IsOuterBorderEnable()246     bool IsOuterBorderEnable() const
247     {
248         return isOuterBorderEnable_;
249     }
250 
GetCloseIconWidth()251     const Dimension& GetCloseIconWidth() const
252     {
253         return closeIconWidth_;
254     }
255 
GetTitleTextHorizMargin()256     const Dimension& GetTitleTextHorizMargin() const
257     {
258         return titleTextHorizMargin_;
259     }
260 
GetCloseIconRadius()261     const Dimension& GetCloseIconRadius() const
262     {
263         return closeIconRadius_;
264     }
265 
266 protected:
267     SheetTheme() = default;
268 
269 private:
270     Dimension sheetRadius_;
271     Dimension titleTextFontSize_;
272     Dimension titleTextMargin_;
273     Dimension subtitleTextFontSize_;
274     Dimension subtitleTextMargin_;
275     Color titleTextFontColor_;
276     Color subtitleTextFontColor_;
277     Color sheetBackgoundColor_;
278     Color dragBarColor_;
279     Color maskColor_;
280     Color closeIconColor_;
281     Color closeIconImageColor_;
282     Color closeIconSymbolColor_;
283     std::string sheetBottom_;
284     std::string sheetType_;
285     int sheetBackgroundBlurStyle_;
286     double sheetNormalScale_;
287     double sheetMaxAgingScale_;
288     uint32_t closeIconSource_ = 0;
289     int sheetShadowConfig_;
290     Dimension sheetOuterBorderWidth_;
291     Dimension sheetInnerBorderWidth_;
292     bool isOuterBorderEnable_;
293     Color sheetOuterBorderColor_;
294     Color sheetInnerBorderColor_;
295     Dimension closeIconWidth_;
296     Dimension titleTextHorizMargin_;
297     Dimension closeIconRadius_;
298 };
299 } // namespace OHOS::Ace::NG
300 
301 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHEET_SHEET_THEME_H
302