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 "core/components/common/properties/border.h" 20 #include "core/components/common/properties/border_edge.h" 21 #include "core/components/common/properties/color.h" 22 #include "core/components/common/properties/edge.h" 23 #include "core/components/common/properties/radius.h" 24 #include "core/components/common/properties/text_style.h" 25 #include "core/components/theme/theme.h" 26 #include "core/components/theme/theme_constants.h" 27 #include "core/components/theme/theme_constants_defines.h" 28 29 namespace OHOS::Ace { 30 31 /** 32 * DialogTheme defines color and styles of PopupComponent. PopupTheme should be built 33 * using DialogTheme::Builder. 34 */ 35 class TextOverlayTheme : public virtual Theme { 36 DECLARE_ACE_TYPE(TextOverlayTheme, Theme); 37 38 public: 39 class Builder { 40 public: 41 Builder() = default; 42 ~Builder() = default; 43 Build(const RefPtr<ThemeConstants> & themeConstants)44 RefPtr<TextOverlayTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 45 { 46 RefPtr<TextOverlayTheme> theme = AceType::Claim(new TextOverlayTheme()); 47 if (!themeConstants) { 48 return theme; 49 } 50 // init theme from global data 51 theme->menuBorder_ = Border(BorderEdge(themeConstants->GetColor(THEME_TEXT_OVERLAY_MENU_BORDER_COLOR), 52 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BORDER_WIDTH), 53 BorderStyle(themeConstants->GetInt(THEME_TEXT_OVERLAY_MENU_BORDER_STYLE)))); 54 theme->menuBackgroundColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_MENU_BACKGROUND_COLOR); 55 theme->handleColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_HANDLE_COLOR); 56 theme->handleColorInner_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_HANDLE_COLOR_INNER); 57 theme->buttonClickedColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_BUTTON_CLICKED_COLOR); 58 theme->buttonHoverColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_BUTTON_HOVER_COLOR); 59 theme->iconColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_MENU_ICON_COLOR); 60 theme->menuIconColor_ = themeConstants->GetColor(THEME_TEXT_OVERLAY_MENU_ICON_COLOR); 61 theme->menuPadding_ = Edge(themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_LEFT), 62 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_TOP), 63 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_RIGHT), 64 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_BOTTOM)); 65 theme->handleDiameter_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_HANDLE_DIAMETER); 66 theme->handleDiameterInner_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_HANDLE_DIAMETER_INNER); 67 theme->menuSpacingWithText_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_SPACING_WITH_TEXT); 68 theme->menuButtonWidth_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_WIDTH); 69 theme->menuButtonHeight_ = themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_HEIGHT); 70 theme->menuButtonTextStyle_.SetFontSize( 71 themeConstants->GetDimension(THEME_TEXT_OVERLAY_BUTTON_TEXT_FONTSIZE)); 72 theme->menuButtonTextStyle_.SetFontWeight( 73 FontWeight(themeConstants->GetInt(THEME_TEXT_OVERLAY_BUTTON_TEXT_FONTWEIGHT))); 74 theme->menuButtonTextStyle_.SetTextColor(themeConstants->GetColor(THEME_TEXT_OVERLAY_BUTTON_TEXT_COLOR)); 75 theme->menuButtonPadding_ = 76 Edge(themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_PADDING_LEFT).Value(), 77 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_PADDING_TOP).Value(), 78 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_PADDING_RIGHT).Value(), 79 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_BUTTON_PADDING_BOTTOM).Value(), 80 themeConstants->GetDimension(THEME_TEXT_OVERLAY_MENU_PADDING_LEFT).Unit()); 81 ParsePattern(themeConstants->GetThemeStyle(), theme); 82 return theme; 83 } 84 85 private: ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<TextOverlayTheme> & theme)86 void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<TextOverlayTheme>& theme) const 87 { 88 if (!themeStyle || !theme) { 89 return; 90 } 91 theme->iconColor_ = themeStyle->GetAttr<Color>(TEXT_OVERLAY_TOOL_BAR_ICON_COLOR, Color()); 92 theme->menuIconColor_ = themeStyle->GetAttr<Color>(TEXT_OVERLAY_MENU_ICON_COLOR, Color()); 93 theme->handleColor_ = themeStyle->GetAttr<Color>(TEXT_OVERLAY_HANDLE_COLOR, Color()); 94 theme->handleColorInner_ = themeStyle->GetAttr<Color>(TEXT_OVERLAY_HANDLE_COLOR_INNER, Color()); 95 theme->menuBackgroundColor_ = themeStyle->GetAttr<Color>(TEXT_OVERLAY_TOOL_BAR_BACKGROUND_COLOR, Color()); 96 theme->buttonHoverColor_ = themeStyle->GetAttr<Color>(TEXT_OVERLAY_TOOL_BAR_BUTTON_HOVER_COLOR, Color()); 97 theme->buttonClickedColor_ = themeStyle->GetAttr<Color>(TEXT_OVERLAY_TOOL_BAR_BUTTON_PRESS_COLOR, Color()); 98 theme->menuButtonTextStyle_.SetTextColor( 99 themeStyle->GetAttr<Color>(TEXT_OVERLAY_TOOL_BAR_TEXT_COLOR, Color())); 100 theme->menuButtonTextStyle_.SetFontSize( 101 themeStyle->GetAttr<Dimension>(TEXT_OVERLAY_TOOL_BAR_FONT_SIZE, 0.0_fp)); 102 } 103 }; 104 105 ~TextOverlayTheme() override = default; 106 GetMenuBorder()107 const Border& GetMenuBorder() const 108 { 109 return menuBorder_; 110 } 111 GetMenuBackgroundColor()112 const Color& GetMenuBackgroundColor() const 113 { 114 return menuBackgroundColor_; 115 } 116 GetHandleColor()117 const Color& GetHandleColor() const 118 { 119 return handleColor_; 120 } 121 GetHandleColorInner()122 const Color& GetHandleColorInner() const 123 { 124 return handleColorInner_; 125 } 126 GetButtonClickedColor()127 const Color& GetButtonClickedColor() const 128 { 129 return buttonClickedColor_; 130 } 131 GetButtonHoverColor()132 const Color& GetButtonHoverColor() const 133 { 134 return buttonHoverColor_; 135 } 136 GetIconColor()137 const Color& GetIconColor() const 138 { 139 return iconColor_; 140 } 141 GetMenuIconColor()142 const Color& GetMenuIconColor() const 143 { 144 return menuIconColor_; 145 } 146 GetMenuPadding()147 const Edge& GetMenuPadding() const 148 { 149 return menuPadding_; 150 } 151 GetMenuButtonPadding()152 const Edge& GetMenuButtonPadding() const 153 { 154 return menuButtonPadding_; 155 } 156 GetHandleDiameter()157 const Dimension& GetHandleDiameter() const 158 { 159 return handleDiameter_; 160 } 161 GetHandleDiameterInner()162 const Dimension& GetHandleDiameterInner() const 163 { 164 return handleDiameterInner_; 165 } 166 GetMenuSpacingWithText()167 const Dimension& GetMenuSpacingWithText() const 168 { 169 return menuSpacingWithText_; 170 } 171 GetMenuButtonWidth()172 const Dimension& GetMenuButtonWidth() const 173 { 174 return menuButtonWidth_; 175 } 176 GetMenuButtonHeight()177 const Dimension& GetMenuButtonHeight() const 178 { 179 return menuButtonHeight_; 180 } 181 GetMenuButtonTextStyle()182 const TextStyle& GetMenuButtonTextStyle() const 183 { 184 return menuButtonTextStyle_; 185 } 186 187 protected: 188 TextOverlayTheme() = default; 189 190 private: 191 Border menuBorder_; 192 Color iconColor_; 193 Color menuIconColor_; 194 Color menuBackgroundColor_; 195 Color handleColor_; 196 Color handleColorInner_; 197 Color buttonClickedColor_; 198 Color buttonHoverColor_; 199 Edge menuPadding_; 200 Edge menuButtonPadding_; 201 Dimension handleDiameter_; 202 Dimension handleDiameterInner_; 203 Dimension menuSpacingWithText_; 204 Dimension menuButtonWidth_; 205 Dimension menuButtonHeight_; 206 TextStyle menuButtonTextStyle_; 207 }; 208 209 } // namespace OHOS::Ace 210 211 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_OVERLAY_TEXT_OVERLAY_THEME_H 212