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_NG_PATTERN_SIDE_BAR_SIDE_BAR_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SIDE_BAR_SIDE_BAR_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 /** 25 * SideBarTheme defines color and styles of SideBarPattern. SideBarTheme should be built 26 * using SideBarTheme::Builder. 27 */ 28 class SideBarTheme : public virtual Theme { 29 DECLARE_ACE_TYPE(SideBarTheme, Theme); 30 31 public: 32 class Builder { 33 public: 34 Builder() = default; 35 ~Builder() = default; 36 Build(const RefPtr<ThemeConstants> & themeConstants)37 RefPtr<SideBarTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 38 { 39 RefPtr<SideBarTheme> theme = AceType::MakeRefPtr<SideBarTheme>(); 40 InitTheme(theme, themeConstants); 41 return theme; 42 } 43 44 protected: InitTheme(const RefPtr<SideBarTheme> & theme,const RefPtr<ThemeConstants> & themeConstants)45 void InitTheme(const RefPtr<SideBarTheme>& theme, const RefPtr<ThemeConstants>& themeConstants) const 46 { 47 CHECK_NULL_VOID(theme); 48 CHECK_NULL_VOID(themeConstants); 49 ParsePattern(themeConstants, theme); 50 } 51 52 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SideBarTheme> & theme)53 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SideBarTheme>& theme) const 54 { 55 RefPtr<ThemeStyle> sideBarPattern = themeConstants->GetPatternByName(THEME_PATTERN_SIDE_BAR); 56 if (!sideBarPattern) { 57 return; 58 } 59 60 theme->controlImageColor_ = sideBarPattern->GetAttr<Color>("control_image_color", Color::BLACK); 61 theme->sideBarBackgroundColor_ = sideBarPattern->GetAttr<Color>("side_bar_background_color", Color::WHITE); 62 theme->controlButtonRadius_ = sideBarPattern->GetAttr<Dimension>("control_button_radius", 0.0_vp); 63 auto dividerShadowEnable = sideBarPattern->GetAttr<std::string>("divider_shadow_enable", "0"); 64 theme->dividerShadowEnable_ = StringUtils::StringToInt(dividerShadowEnable); 65 66 auto sideBarUnfocusEffectEnable 67 = sideBarPattern->GetAttr<std::string>("section_unfocus_effect_enable", "0"); 68 theme->sideBarUnfocusEffectEnable_ = StringUtils::StringToInt(sideBarUnfocusEffectEnable); 69 theme->sideBarUnfocusColor_ = sideBarPattern->GetAttr<Color>("color_panel_bg", Color::TRANSPARENT); 70 71 theme->controlButtonIconColor_ = sideBarPattern->GetAttr<Color>("dialog_icon_primary", Color::TRANSPARENT); 72 theme->controlButtonBackboardColor_ = 73 sideBarPattern->GetAttr<Color>("control_button_back_board_color", Color::TRANSPARENT); 74 theme->controlButtonBackboardColorHover_ = 75 sideBarPattern->GetAttr<Color>("control_button_back_board_color_hover", Color::TRANSPARENT); 76 theme->controlButtonBackboardColorPress_ = 77 sideBarPattern->GetAttr<Color>("control_button_back_board_color_press", Color::TRANSPARENT); 78 theme->controlButtonBackboardStrokeColor_ = 79 sideBarPattern->GetAttr<Color>("control_button_back_board_stroke_color", Color::TRANSPARENT); 80 theme->controlButtonBackboardRadius_ = 81 sideBarPattern->GetAttr<Dimension>("dialog_radius_level10", 20.0_vp); 82 theme->controlButtonMarginLeftSmall_ = 83 sideBarPattern->GetAttr<Dimension>("control_button_margin_left_small", 0.0_vp); 84 theme->controlButtonMarginLeftMiddle_ = 85 sideBarPattern->GetAttr<Dimension>("control_button_margin_left_middle", 0.0_vp); 86 theme->controlButtonMarginLeftLarge_ = 87 sideBarPattern->GetAttr<Dimension>("control_button_margin_left_large", 0.0_vp); 88 theme->breakPointHorizontalSmall_ = 89 sideBarPattern->GetAttr<Dimension>("break_point_horizontal_small", 0.0_vp); 90 theme->breakPointHorizontalMiddle_ = 91 sideBarPattern->GetAttr<Dimension>("break_point_horizontal_middle", 0.0_vp); 92 theme->controlButtonMarginTopSmall_ = 93 sideBarPattern->GetAttr<Dimension>("control_button_margin_top_small", 0.0_vp); 94 theme->controlButtonWidthSmall_ = 95 sideBarPattern->GetAttr<Dimension>("control_button_width_small", 0.0_vp); 96 theme->controlButtonHeightSmall_ = 97 sideBarPattern->GetAttr<Dimension>("control_button_height_small", 0.0_vp); 98 theme->sideBarWidth_ = sideBarPattern->GetAttr<Dimension>("side_bar_width", -1.0_vp); 99 } 100 }; 101 102 ~SideBarTheme() override = default; 103 GetControlImageColor()104 const Color& GetControlImageColor() const 105 { 106 return controlImageColor_; 107 } 108 SetControlImageColor(const Color & color)109 void SetControlImageColor(const Color& color) 110 { 111 controlImageColor_ = color; 112 } 113 GetSideBarBackgroundColor()114 const Color& GetSideBarBackgroundColor() const 115 { 116 return sideBarBackgroundColor_; 117 } 118 GetControlButtonRadius()119 const Dimension& GetControlButtonRadius() const 120 { 121 return controlButtonRadius_; 122 } 123 GetDividerShadowEnable()124 int32_t GetDividerShadowEnable() const 125 { 126 return dividerShadowEnable_; 127 } 128 GetSideBarUnfocusEffectEnable()129 const int32_t& GetSideBarUnfocusEffectEnable() const 130 { 131 return sideBarUnfocusEffectEnable_; 132 } 133 GetSideBarUnfocusColor()134 const Color& GetSideBarUnfocusColor() const 135 { 136 return sideBarUnfocusColor_; 137 } 138 GetControlButtonIconColor()139 const Color& GetControlButtonIconColor() const 140 { 141 return controlButtonIconColor_; 142 } 143 GetControlButtonBackboardColor()144 const Color& GetControlButtonBackboardColor() const 145 { 146 return controlButtonBackboardColor_; 147 } 148 GetControlButtonBackboardColorHover()149 const Color& GetControlButtonBackboardColorHover() const 150 { 151 return controlButtonBackboardColorHover_; 152 } 153 GetControlButtonBackboardColorPress()154 const Color& GetControlButtonBackboardColorPress() const 155 { 156 return controlButtonBackboardColorPress_; 157 } 158 GetControlButtonBackboardStrokeColor()159 const Color& GetControlButtonBackboardStrokeColor() const 160 { 161 return controlButtonBackboardStrokeColor_; 162 } 163 GetControlButtonBackboardRadius()164 const Dimension& GetControlButtonBackboardRadius() const 165 { 166 return controlButtonBackboardRadius_; 167 } 168 GetControlButtonMarginLeftSmall()169 const Dimension& GetControlButtonMarginLeftSmall() const 170 { 171 return controlButtonMarginLeftSmall_; 172 } 173 GetControlButtonMarginLeftMiddle()174 const Dimension& GetControlButtonMarginLeftMiddle() const 175 { 176 return controlButtonMarginLeftMiddle_; 177 } 178 GetControlButtonMarginLeftLarge()179 const Dimension& GetControlButtonMarginLeftLarge() const 180 { 181 return controlButtonMarginLeftLarge_; 182 } 183 GetBreakPointHorizontalSmall()184 const Dimension& GetBreakPointHorizontalSmall() const 185 { 186 return breakPointHorizontalSmall_; 187 } 188 GetBreakPointHorizontalMiddle()189 const Dimension& GetBreakPointHorizontalMiddle() const 190 { 191 return breakPointHorizontalMiddle_; 192 } 193 GetControlButtonMarginTopSmall()194 const Dimension& GetControlButtonMarginTopSmall() const 195 { 196 return controlButtonMarginTopSmall_; 197 } 198 GetControlButtonWidthSmall()199 const Dimension& GetControlButtonWidthSmall() const 200 { 201 return controlButtonWidthSmall_; 202 } 203 GetControlButtonHeightSmall()204 const Dimension& GetControlButtonHeightSmall() const 205 { 206 return controlButtonHeightSmall_; 207 } 208 GetSideBarWidth()209 const Dimension& GetSideBarWidth() const 210 { 211 return sideBarWidth_; 212 } 213 214 protected: 215 SideBarTheme() = default; 216 217 private: 218 Color controlImageColor_ = Color::BLACK; 219 Color sideBarBackgroundColor_ = Color::WHITE; 220 Dimension controlButtonRadius_; 221 int32_t dividerShadowEnable_ = 0; 222 int32_t sideBarUnfocusEffectEnable_ = 0; 223 Color sideBarUnfocusColor_ = Color::TRANSPARENT; 224 // version 13 225 Color controlButtonIconColor_ = Color::BLACK; 226 Color controlButtonBackboardColor_ = Color::TRANSPARENT; 227 Color controlButtonBackboardColorHover_ = Color::TRANSPARENT; 228 Color controlButtonBackboardColorPress_ = Color::TRANSPARENT; 229 Color controlButtonBackboardStrokeColor_ = Color::TRANSPARENT; 230 Dimension controlButtonBackboardRadius_ = 0.0_vp; 231 Dimension controlButtonMarginLeftSmall_ = 0.0_vp; 232 Dimension controlButtonMarginLeftMiddle_ = 0.0_vp; 233 Dimension controlButtonMarginLeftLarge_ = 0.0_vp; 234 Dimension breakPointHorizontalSmall_ = 0.0_vp; 235 Dimension breakPointHorizontalMiddle_ = 0.0_vp; 236 Dimension controlButtonMarginTopSmall_ = 0.0_vp; 237 Dimension controlButtonWidthSmall_ = 0.0_vp; 238 Dimension controlButtonHeightSmall_ = 0.0_vp; 239 Dimension sideBarWidth_ = -1.0_vp; 240 }; 241 } // namespace OHOS::Ace::NG 242 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SIDE_BAR_SIDE_BAR_THEME_H 243