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::Claim(new SideBarTheme()); 40 if (!themeConstants) { 41 return theme; 42 } 43 44 ParsePattern(themeConstants, theme); 45 return theme; 46 } 47 48 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SideBarTheme> & theme)49 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SideBarTheme>& theme) const 50 { 51 RefPtr<ThemeStyle> sideBarPattern = themeConstants->GetPatternByName(THEME_PATTERN_SIDE_BAR); 52 if (!sideBarPattern) { 53 return; 54 } 55 56 theme->controlImageColor_ = sideBarPattern->GetAttr<Color>("control_image_color", Color::BLACK); 57 theme->sideBarBackgroundColor_ = sideBarPattern->GetAttr<Color>("side_bar_background_color", Color::WHITE); 58 theme->controlButtonRadius_ = sideBarPattern->GetAttr<Dimension>("control_button_radius", 0.0_vp); 59 auto dividerShadowEnable = sideBarPattern->GetAttr<std::string>("divider_shadow_enable", "0"); 60 theme->dividerShadowEnable_ = StringUtils::StringToInt(dividerShadowEnable); 61 62 auto sideBarUnfocusEffectEnable 63 = sideBarPattern->GetAttr<std::string>("section_unfocus_effect_enable", "0"); 64 theme->sideBarUnfocusEffectEnable_ = StringUtils::StringToInt(sideBarUnfocusEffectEnable); 65 theme->sideBarUnfocusColor_ = sideBarPattern->GetAttr<Color>("color_panel_bg", Color::TRANSPARENT); 66 } 67 }; 68 69 ~SideBarTheme() override = default; 70 GetControlImageColor()71 const Color& GetControlImageColor() const 72 { 73 return controlImageColor_; 74 } 75 GetSideBarBackgroundColor()76 const Color& GetSideBarBackgroundColor() const 77 { 78 return sideBarBackgroundColor_; 79 } 80 GetControlButtonRadius()81 const Dimension& GetControlButtonRadius() const 82 { 83 return controlButtonRadius_; 84 } 85 GetDividerShadowEnable()86 int32_t GetDividerShadowEnable() const 87 { 88 return dividerShadowEnable_; 89 } 90 GetSideBarUnfocusEffectEnable()91 const int32_t& GetSideBarUnfocusEffectEnable() const 92 { 93 return sideBarUnfocusEffectEnable_; 94 } 95 GetSideBarUnfocusColor()96 const Color& GetSideBarUnfocusColor() const 97 { 98 return sideBarUnfocusColor_; 99 } 100 101 protected: 102 SideBarTheme() = default; 103 104 private: 105 Color controlImageColor_ = Color::BLACK; 106 Color sideBarBackgroundColor_ = Color::WHITE; 107 Dimension controlButtonRadius_; 108 int32_t dividerShadowEnable_ = 0; 109 int32_t sideBarUnfocusEffectEnable_ = 0; 110 Color sideBarUnfocusColor_ = Color::TRANSPARENT; 111 }; 112 } // namespace OHOS::Ace::NG 113 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SIDE_BAR_SIDE_BAR_THEME_H 114