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_CLOSE_ICON_CLOSE_ICON_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CLOSE_ICON_CLOSE_ICON_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 24 namespace OHOS::Ace { 25 namespace { 26 constexpr Dimension PANEL_CLOSE_ICON_WIDTH = 24.0_vp; 27 constexpr Dimension PANEL_CLOSE_ICON_Height = 24.0_vp; 28 constexpr Dimension PANEL_CLOSE_ICON_MARGIN_TOP = 20.0_vp; 29 constexpr Dimension PANEL_CLOSE_ICON_MARGIN_RIGHT = 24.0_vp; 30 constexpr Dimension PANEL_CLOSE_ICON_RADIUS = 12.0_vp; 31 } // namespace 32 class CloseIconTheme : public virtual Theme { 33 DECLARE_ACE_TYPE(CloseIconTheme, Theme); 34 35 public: 36 class Builder { 37 public: 38 Builder() = default; 39 ~Builder() = default; 40 Build(const RefPtr<ThemeConstants> & themeConstants)41 RefPtr<CloseIconTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 42 { 43 RefPtr<CloseIconTheme> theme = AceType::Claim(new CloseIconTheme()); 44 if (!themeConstants) { 45 return theme; 46 } 47 auto themeStyle = themeConstants->GetThemeStyle(); 48 if (!themeStyle) { 49 return theme; 50 } 51 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_CLOSE_ICON, nullptr); 52 if (pattern) { 53 theme->closeIconWidth_ = pattern->GetAttr<Dimension>(CLOSE_ICON_WIDTH, PANEL_CLOSE_ICON_WIDTH); 54 theme->closeIconHeight_ = pattern->GetAttr<Dimension>(CLOSE_ICON_Height, PANEL_CLOSE_ICON_Height); 55 theme->closeIconMarginTop_ = 56 pattern->GetAttr<Dimension>(CLOSE_ICON_MARGIN_TOP, PANEL_CLOSE_ICON_MARGIN_TOP); 57 theme->closeIconMarginRight_ = 58 pattern->GetAttr<Dimension>(CLOSE_ICON_MARGIN_RIGHT, PANEL_CLOSE_ICON_MARGIN_RIGHT); 59 theme->closeIconRadius_ = pattern->GetAttr<Dimension>(CLOSE_ICON_RADIUS, PANEL_CLOSE_ICON_RADIUS); 60 } else { 61 LOGW("find pattern of closeIcon fail"); 62 } 63 return theme; 64 } 65 }; 66 ~CloseIconTheme() override = default; 67 GetCloseIconWidth()68 const Dimension& GetCloseIconWidth() const 69 { 70 return closeIconWidth_; 71 } 72 GetCloseIconHeight()73 const Dimension& GetCloseIconHeight() const 74 { 75 return closeIconHeight_; 76 } 77 GetCloseIconMarginRight()78 const Dimension& GetCloseIconMarginRight() const 79 { 80 return closeIconMarginRight_; 81 } 82 GetCloseIconMarginTop()83 const Dimension& GetCloseIconMarginTop() const 84 { 85 return closeIconMarginTop_; 86 } 87 GetCloseIconRadius()88 const Dimension& GetCloseIconRadius() const 89 { 90 return closeIconRadius_; 91 } 92 93 protected: 94 CloseIconTheme() = default; 95 96 private: 97 Dimension closeIconMarginRight_; 98 Dimension closeIconMarginTop_; 99 Dimension closeIconWidth_; 100 Dimension closeIconHeight_; 101 Dimension closeIconRadius_; 102 }; 103 } // namespace OHOS::Ace 104 105 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CLOSE_ICON_CLOSE_ICON_THEME_H 106