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_TOOL_BAR_TOOL_BAR_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TOOL_BAR_TOOL_BAR_THEME_H 18 19 #include <vector> 20 21 #include "core/components/common/properties/edge.h" 22 #include "core/components/common/properties/text_style.h" 23 #include "core/components/theme/theme.h" 24 #include "core/components/theme/theme_constants.h" 25 #include "core/components/theme/theme_constants_defines.h" 26 #include "core/components/theme/theme_manager.h" 27 #include "frameworks/bridge/common/utils/utils.h" 28 29 namespace OHOS::Ace { 30 31 /** 32 * ToolBarTheme defines color and styles of ToolBar. ToolBarTheme should be built 33 * using ToolBarTheme::Builder. 34 */ 35 class ToolBarTheme : public virtual Theme { 36 DECLARE_ACE_TYPE(ToolBarTheme, Theme); 37 38 public: 39 class Builder { 40 public: 41 Builder() = default; 42 ~Builder() = default; 43 Build(const RefPtr<ThemeConstants> & themeConstants)44 RefPtr<ToolBarTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 45 { 46 RefPtr<ToolBarTheme> theme = AceType::Claim(new ToolBarTheme()); 47 if (!themeConstants) { 48 return theme; 49 } 50 ParsePattern(themeConstants, theme); 51 return theme; 52 } 53 54 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<ToolBarTheme> & theme)55 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<ToolBarTheme>& theme) const 56 { 57 RefPtr<ThemeStyle> toolbarPattern = themeConstants->GetPatternByName(THEME_PATTERN_TOOLBAR); 58 if (!toolbarPattern) { 59 LOGI("ToolbarPattern is null"); 60 return; 61 } 62 theme->iconMoreColor_ = toolbarPattern->GetAttr<Color>("more_icon_color", Color()); 63 theme->textStyle_.SetTextColor(toolbarPattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color::BLACK)); 64 theme->iconColor_ = toolbarPattern->GetAttr<Color>("icon_color", Color()); 65 theme->toolBarBgColor_ = toolbarPattern->GetAttr<Color>(PATTERN_BG_COLOR, Color()); 66 theme->toolBarItemBgColor_ = toolbarPattern->GetAttr<Color>("item_bg_color", Color()); 67 theme->textStyle_.SetFontSize(toolbarPattern->GetAttr<Dimension>("text_fontsize", 10.0_fp)); 68 theme->textStyle_.SetFontFamilies({ toolbarPattern->GetAttr<std::string>("text_font_family_medium", 69 "HwChinese-medium") }); 70 theme->textStyle_.SetAdaptTextSize(toolbarPattern->GetAttr<Dimension>("text_fontsize", 10.0_fp), 71 toolbarPattern->GetAttr<Dimension>("text_min_fontsize", 9.0_vp)); 72 theme->iconSize_ = Size(toolbarPattern->GetAttr<Dimension>("item_icon_width", 24.0_vp).Value(), 73 toolbarPattern->GetAttr<Dimension>("item_icon_height", 24.0_vp).Value()); 74 theme->imageEdge_ = Edge(toolbarPattern->GetAttr<Dimension>("item_padding_icon_left", 1.0_vp), 75 toolbarPattern->GetAttr<Dimension>("item_padding_icon_top", 8.0_vp), 76 toolbarPattern->GetAttr<Dimension>("item_padding_icon_right", 1.0_vp), 77 toolbarPattern->GetAttr<Dimension>("item_padding_icon_bottom", 1.0_vp)); 78 theme->textEdge_ = Edge(toolbarPattern->GetAttr<Dimension>("item_padding_text_left", 1.0_vp), 79 toolbarPattern->GetAttr<Dimension>("item_padding_text_top", 1.0_vp), 80 toolbarPattern->GetAttr<Dimension>("item_padding_text_right", 1.0_vp), 81 toolbarPattern->GetAttr<Dimension>("item_padding_text_bottom", 8.0_vp)); 82 theme->focusColor_ = toolbarPattern->GetAttr<Color>("item_focus_color", Color(0xe6254ff7)); 83 theme->hoverColor_ = toolbarPattern->GetAttr<Color>("item_hover_color", Color(0x0c000000)); 84 theme->pressColor_ = toolbarPattern->GetAttr<Color>("control_normal", Color(0x19000000)); 85 theme->radius_ = toolbarPattern->GetAttr<Dimension>("item_radius", 8.0_vp); 86 } 87 }; 88 89 ~ToolBarTheme() override = default; 90 GetToolBarTextStyle()91 const TextStyle& GetToolBarTextStyle() const 92 { 93 return textStyle_; 94 } 95 GetIconSize()96 const Size& GetIconSize() const 97 { 98 return iconSize_; 99 } 100 GetIconEdge()101 const Edge& GetIconEdge() const 102 { 103 return imageEdge_; 104 } 105 GetTextEdge()106 const Edge& GetTextEdge() const 107 { 108 return textEdge_; 109 } 110 GetToolBarBgColor()111 const Color& GetToolBarBgColor() const 112 { 113 return toolBarBgColor_; 114 } 115 GetItemBackgroundColor()116 const Color& GetItemBackgroundColor() const 117 { 118 return toolBarItemBgColor_; 119 } 120 GetIconColor()121 const Color& GetIconColor() const 122 { 123 return iconColor_; 124 } 125 GetFocusColor()126 const Color& GetFocusColor() const 127 { 128 return focusColor_; 129 } 130 GetHoverColor()131 const Color& GetHoverColor() const 132 { 133 return hoverColor_; 134 } 135 GetPressColor()136 const Color& GetPressColor() const 137 { 138 return pressColor_; 139 } 140 GetRadius()141 const Dimension& GetRadius() const 142 { 143 return radius_; 144 } 145 GetIconMoreColor()146 const Color& GetIconMoreColor() const 147 { 148 return iconMoreColor_; 149 } 150 151 protected: 152 ToolBarTheme() = default; 153 154 private: 155 Edge imageEdge_; 156 Edge textEdge_; 157 TextStyle textStyle_; 158 Size iconSize_; 159 Color toolBarBgColor_; 160 Color iconColor_; 161 Color focusColor_; 162 Color hoverColor_; 163 Color toolBarItemBgColor_; 164 Color pressColor_; 165 Dimension radius_; 166 Color iconMoreColor_; 167 }; 168 169 } // namespace OHOS::Ace 170 171 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TOOL_BAR_TOOL_BAR_THEME_H 172