• 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_TEXT_OVERLAY_TEXT_OVERLAY_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_OVERLAY_TEXT_OVERLAY_THEME_H
18 
19 #include "base/geometry/dimension.h"
20 #include "core/components/common/properties/border.h"
21 #include "core/components/common/properties/border_edge.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/components/common/properties/edge.h"
24 #include "core/components/common/properties/radius.h"
25 #include "core/components/common/properties/text_style.h"
26 #include "core/components/theme/theme.h"
27 #include "core/components/theme/theme_constants.h"
28 #include "core/components/theme/theme_constants_defines.h"
29 
30 namespace OHOS::Ace {
31 
32 /**
33  * DialogTheme defines color and styles of PopupComponent. PopupTheme should be built
34  * using DialogTheme::Builder.
35  */
36 class TextOverlayTheme : public virtual Theme {
37     DECLARE_ACE_TYPE(TextOverlayTheme, Theme);
38 
39 public:
40     class Builder {
41     public:
42         Builder() = default;
43         ~Builder() = default;
44 
Build(const RefPtr<ThemeConstants> & themeConstants)45         RefPtr<TextOverlayTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
46         {
47             RefPtr<TextOverlayTheme> theme = AceType::Claim(new TextOverlayTheme());
48             if (!themeConstants) {
49                 return theme;
50             }
51             // init theme from global data
52             theme->menuBorder_ = Border(BorderEdge(themeConstants->GetColor(THEME_TEXT_OVERLAY_MENU_BORDER_COLOR),
53                 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BORDER_WIDTH),
54                 BorderStyle(themeConstants->GetInt(THEME_TEXT_OVERLAY_MENU_BORDER_STYLE))));
55             theme->menuBackgroundColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_MENU_BACKGROUND_COLOR);
56             theme->handleColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_HANDLE_COLOR);
57             theme->handleColorInner_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_HANDLE_COLOR_INNER);
58             theme->buttonClickedColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_BUTTON_CLICKED_COLOR);
59             theme->buttonHoverColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_BUTTON_HOVER_COLOR);
60             theme->iconColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_MENU_ICON_COLOR);
61             theme->menuIconColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_MENU_ICON_COLOR);
62             theme->menuPadding_ = Edge(themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_LEFT),
63                 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_TOP),
64                 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_RIGHT),
65                 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_BOTTOM));
66             theme->handleDiameter_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_HANDLE_DIAMETER);
67             theme->handleDiameterInner_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_HANDLE_DIAMETER_INNER);
68             theme->menuSpacingWithText_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_SPACING_WITH_TEXT);
69             theme->menuButtonWidth_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_WIDTH);
70             theme->menuButtonHeight_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_HEIGHT);
71             theme->menuButtonTextStyle_.SetFontSize(
72                 themeConstants->GetDimension(THEME_TEXT_OVERLAY_BUTTON_TEXT_FONTSIZE));
73             theme->menuButtonTextStyle_.SetFontWeight(
74                 FontWeight(themeConstants->GetInt(THEME_TEXT_OVERLAY_BUTTON_TEXT_FONTWEIGHT)));
75             theme->menuButtonTextStyle_.SetTextColor(themeConstants->GetColor(THEME_TEXT_OVERLAY_BUTTON_TEXT_COLOR));
76             theme->menuButtonPadding_ =
77                 Edge(themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_PADDING_LEFT).Value(),
78                     themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_PADDING_TOP).Value(),
79                     themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_PADDING_RIGHT).Value(),
80                     themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_PADDING_BOTTOM).Value(),
81                     themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_LEFT).Unit());
82             theme->backResourceId_ = themeConstants->GetResourceId(THEME_NAVIGATION_BAR_RESOURCE_ID_BACK);
83             theme->moreResourceId_ = themeConstants->GetResourceId(THEME_NAVIGATION_BAR_RESOURCE_ID_MORE);
84             ParsePattern(themeConstants->GetThemeStyle(), theme);
85             return theme;
86         }
87 
88     private:
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<TextOverlayTheme> & theme)89         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<TextOverlayTheme>& theme) const
90         {
91             if (!themeStyle || !theme) {
92                 return;
93             }
94             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("text_overlay_pattern", nullptr);
95             if (pattern) {
96                 const double defaultTertiaryColorAlpha = 0.4;
97 
98                 theme->iconColor_ = pattern->GetAttr<Color>("icon_color", Color());
99                 theme->menuIconColor_ = pattern->GetAttr<Color>("memu_icon_color", Color());
100                 theme->handleColor_ = pattern->GetAttr<Color>("handle_outer_color", Color());
101                 theme->handleColorInner_ = pattern->GetAttr<Color>("handle_inner_color", Color());
102                 theme->menuBackgroundColor_ = pattern->GetAttr<Color>("menu_bg_color", Color());
103                 theme->buttonHoverColor_ = pattern->GetAttr<Color>("button_bg_color_hovered", Color());
104                 theme->buttonClickedColor_ = pattern->GetAttr<Color>("button_bg_color_clicked", Color());
105                 theme->moreOrBackIconColor_ = pattern->GetAttr<Color>("more_or_back_icon_color", Color());
106                 theme->menuButtonTextStyle_.SetTextColor(pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color()));
107                 theme->menuButtonTextStyle_.SetFontSize(pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 0.0_fp));
108                 theme->handleDiameter_ = pattern->GetAttr<Dimension>("handle_outer_diameter", 0.0_vp);
109                 theme->handleDiameterInner_ = pattern->GetAttr<Dimension>("handle_inner_diameter", 0.0_vp);
110                 theme->moreButtonHeight_ = pattern->GetAttr<Dimension>("more_button_height", 24.0_vp);
111                 theme->selectOverlayMaxWidth_ = pattern->GetAttr<Dimension>("select_overlay_max_width", 280.0_vp);
112                 theme->alphaDisabled_ =
113                     pattern->GetAttr<double>(PATTERN_BG_COLOR_DISABLED_ALPHA, defaultTertiaryColorAlpha);
114             } else {
115                 LOGW("find pattern of textoverlay fail");
116             }
117         }
118     };
119 
120     ~TextOverlayTheme() override = default;
121 
GetMenuBorder()122     const Border& GetMenuBorder() const
123     {
124         return menuBorder_;
125     }
126 
GetMenuBackgroundColor()127     const Color& GetMenuBackgroundColor() const
128     {
129         return menuBackgroundColor_;
130     }
131 
GetHandleColor()132     const Color& GetHandleColor() const
133     {
134         return handleColor_;
135     }
136 
GetHandleColorInner()137     const Color& GetHandleColorInner() const
138     {
139         return handleColorInner_;
140     }
141 
GetButtonClickedColor()142     const Color& GetButtonClickedColor() const
143     {
144         return buttonClickedColor_;
145     }
146 
GetButtonHoverColor()147     const Color& GetButtonHoverColor() const
148     {
149         return buttonHoverColor_;
150     }
151 
GetIconColor()152     const Color& GetIconColor() const
153     {
154         return iconColor_;
155     }
156 
GetMenuIconColor()157     const Color& GetMenuIconColor() const
158     {
159         return menuIconColor_;
160     }
161 
GetMoreOrBackIconColor()162     const Color& GetMoreOrBackIconColor() const
163     {
164         return moreOrBackIconColor_;
165     }
166 
GetMenuPadding()167     const Edge& GetMenuPadding() const
168     {
169         return menuPadding_;
170     }
171 
GetMenuButtonPadding()172     const Edge& GetMenuButtonPadding() const
173     {
174         return menuButtonPadding_;
175     }
176 
GetHandleDiameter()177     const Dimension& GetHandleDiameter() const
178     {
179         return handleDiameter_;
180     }
181 
GetHandleDiameterInner()182     const Dimension& GetHandleDiameterInner() const
183     {
184         return handleDiameterInner_;
185     }
186 
GetMenuSpacingWithText()187     const Dimension& GetMenuSpacingWithText() const
188     {
189         return menuSpacingWithText_;
190     }
191 
GetMenuButtonWidth()192     const Dimension& GetMenuButtonWidth() const
193     {
194         return menuButtonWidth_;
195     }
196 
GetMenuButtonHeight()197     const Dimension& GetMenuButtonHeight() const
198     {
199         return menuButtonHeight_;
200     }
201 
GetMoreButtonHeight()202     const Dimension& GetMoreButtonHeight() const
203     {
204         return moreButtonHeight_;
205     }
206 
GetSelectOverlayMaxWidth()207     const Dimension& GetSelectOverlayMaxWidth() const
208     {
209         return selectOverlayMaxWidth_;
210     }
211 
GetMenuButtonTextStyle()212     const TextStyle& GetMenuButtonTextStyle() const
213     {
214         return menuButtonTextStyle_;
215     }
216 
GetMenuToolbarHeight()217     Dimension GetMenuToolbarHeight() const
218     {
219         return 40.0_vp;
220     }
221 
GetDefaultMenuPositionX()222     float GetDefaultMenuPositionX()
223     {
224         return 10.0f;
225     }
226 
GetHandleLineWidth()227     Dimension GetHandleLineWidth() const
228     {
229         return 1.5_vp;
230     }
231 
GetHandleHotZoneRadius()232     Dimension GetHandleHotZoneRadius() const
233     {
234         return handleDiameter_;
235     }
236 
GetBackResourceId()237     InternalResource::ResourceId GetBackResourceId() const
238     {
239         return backResourceId_;
240     }
241 
GetMoreResourceId()242     InternalResource::ResourceId GetMoreResourceId() const
243     {
244         return moreResourceId_;
245     }
246 
GetAlphaDisabled()247     double GetAlphaDisabled() const
248     {
249         return alphaDisabled_;
250     }
251 
252 protected:
253     TextOverlayTheme() = default;
254 
255 private:
256     Border menuBorder_;
257     Color iconColor_;
258     Color menuIconColor_;
259     Color menuBackgroundColor_;
260     Color handleColor_;
261     Color handleColorInner_;
262     Color buttonClickedColor_;
263     Color buttonHoverColor_;
264     Color moreOrBackIconColor_;
265     Edge menuPadding_;
266     Edge menuButtonPadding_;
267     Dimension handleDiameter_;
268     Dimension handleDiameterInner_;
269     Dimension menuSpacingWithText_;
270     Dimension menuButtonWidth_;
271     Dimension menuButtonHeight_;
272     Dimension moreButtonHeight_;
273     Dimension selectOverlayMaxWidth_;
274     TextStyle menuButtonTextStyle_;
275     double alphaDisabled_ = 0.0;
276 
277     InternalResource::ResourceId backResourceId_ = InternalResource::ResourceId::NO_ID;
278     InternalResource::ResourceId moreResourceId_ = InternalResource::ResourceId::NO_ID;
279 };
280 
281 } // namespace OHOS::Ace
282 
283 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_OVERLAY_TEXT_OVERLAY_THEME_H
284