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_THEME_CARD_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_THEME_CARD_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 #include "core/components/theme/theme_constants_defines.h" 23 #include "core/components/theme/theme_manager.h" 24 25 namespace OHOS::Ace { 26 27 class CardTheme : public virtual Theme { 28 DECLARE_ACE_TYPE(CardTheme, Theme); 29 30 public: 31 class Builder { 32 public: 33 Builder() = default; 34 ~Builder() = default; 35 Build(const RefPtr<ThemeConstants> & themeConstants)36 RefPtr<CardTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 37 { 38 RefPtr<CardTheme> theme = AceType::Claim(new CardTheme()); 39 if (!themeConstants) { 40 return theme; 41 } 42 theme = AceType::Claim(new CardTheme()); 43 ParsePattern(themeConstants, theme); 44 return theme; 45 } 46 ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<CardTheme> & theme)47 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<CardTheme>& theme) const 48 { 49 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_CARD); 50 if (!pattern) { 51 LOGW("find pattern of card fail"); 52 return; 53 } 54 theme->borderRadius_ = pattern->GetAttr<Dimension>("card_border_radius", 16.0_vp); 55 theme->backgroundColor_ = pattern->GetAttr<Color>("card_bg_color", Color(0xff202224)); 56 theme->blurRadius_ = pattern->GetAttr<Dimension>("card_blur_radius", 10.0_px); 57 } 58 }; 59 60 ~CardTheme() override = default; 61 GetBackgroundColor()62 const Color& GetBackgroundColor() const 63 { 64 return backgroundColor_; 65 } 66 GetBorderRadius()67 const Dimension& GetBorderRadius() const 68 { 69 return borderRadius_; 70 } 71 GetBlurRadius()72 const Dimension& GetBlurRadius() const 73 { 74 return blurRadius_; 75 } 76 77 protected: 78 CardTheme() = default; 79 80 private: 81 Dimension borderRadius_; 82 Color backgroundColor_; 83 Dimension blurRadius_; 84 }; 85 86 } // namespace OHOS::Ace 87 88 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_THEME_CARD_THEME_H 89