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 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_CLOSE_ICON); 48 if (pattern) { 49 theme->closeIconWidth_ = pattern->GetAttr<Dimension>(CLOSE_ICON_WIDTH, PANEL_CLOSE_ICON_WIDTH); 50 theme->closeIconHeight_ = pattern->GetAttr<Dimension>(CLOSE_ICON_Height, PANEL_CLOSE_ICON_Height); 51 theme->closeIconMarginTop_ = 52 pattern->GetAttr<Dimension>(CLOSE_ICON_MARGIN_TOP, PANEL_CLOSE_ICON_MARGIN_TOP); 53 theme->closeIconMarginRight_ = 54 pattern->GetAttr<Dimension>(CLOSE_ICON_MARGIN_RIGHT, PANEL_CLOSE_ICON_MARGIN_RIGHT); 55 theme->closeIconRadius_ = pattern->GetAttr<Dimension>(CLOSE_ICON_RADIUS, PANEL_CLOSE_ICON_RADIUS); 56 } else { 57 LOGW("find pattern of closeIcon fail"); 58 } 59 return theme; 60 } 61 }; 62 ~CloseIconTheme() override = default; 63 GetCloseIconWidth()64 const Dimension& GetCloseIconWidth() const 65 { 66 return closeIconWidth_; 67 } 68 GetCloseIconHeight()69 const Dimension& GetCloseIconHeight() const 70 { 71 return closeIconHeight_; 72 } 73 GetCloseIconMarginRight()74 const Dimension& GetCloseIconMarginRight() const 75 { 76 return closeIconMarginRight_; 77 } 78 GetCloseIconMarginTop()79 const Dimension& GetCloseIconMarginTop() const 80 { 81 return closeIconMarginTop_; 82 } 83 GetCloseIconRadius()84 const Dimension& GetCloseIconRadius() const 85 { 86 return closeIconRadius_; 87 } 88 89 protected: 90 CloseIconTheme() = default; 91 92 private: 93 Dimension closeIconMarginRight_; 94 Dimension closeIconMarginTop_; 95 Dimension closeIconWidth_; 96 Dimension closeIconHeight_; 97 Dimension closeIconRadius_; 98 }; 99 } // namespace OHOS::Ace 100 101 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CLOSE_ICON_CLOSE_ICON_THEME_H 102