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_GRID_GRID_ITEM_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_GRID_ITEM_THEME_H 18 19 #include "core/components/theme/theme.h" 20 #include "core/components/theme/theme_constants.h" 21 #include "core/components/theme/theme_constants_defines.h" 22 #include "core/components_ng/property/border_property.h" 23 24 namespace OHOS::Ace::NG { 25 enum class GridItemStyle { 26 NONE = 0, 27 PLAIN, 28 }; 29 30 /** 31 * GridItemTheme defines styles of grid item. GridItemTheme should be built using GridItemTheme::Builder. 32 */ 33 class GridItemTheme : public virtual Theme { 34 DECLARE_ACE_TYPE(GridItemTheme, Theme); 35 36 public: 37 class Builder { 38 public: 39 Builder() = default; 40 ~Builder() = default; 41 Build(const RefPtr<ThemeConstants> & themeConstants)42 RefPtr<GridItemTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 43 { 44 RefPtr<GridItemTheme> theme = AceType::Claim(new GridItemTheme()); 45 if (!themeConstants) { 46 return theme; 47 } 48 ParsePattern(themeConstants, theme); 49 return theme; 50 } 51 52 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<GridItemTheme> & theme)53 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<GridItemTheme>& theme) const 54 { 55 if (!theme) { 56 return; 57 } 58 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_GRID); 59 if (!pattern) { 60 return; 61 } 62 theme->pressColor_ = pattern->GetAttr<Color>("grid_item_press_color", Color::WHITE); 63 theme->hoverColor_ = pattern->GetAttr<Color>("grid_item_hover_color", Color::WHITE); 64 theme->focusRadius_ = pattern->GetAttr<Dimension>("grid_item_focus_border_radius", 0.0_vp); 65 theme->focusColor_ = pattern->GetAttr<Color>("grid_item_focus_color", Color::WHITE); 66 theme->borderRadius_.SetRadius(theme->focusRadius_); 67 } 68 }; 69 70 ~GridItemTheme() override = default; 71 GetGridItemPressColor()72 const Color& GetGridItemPressColor() const 73 { 74 return pressColor_; 75 } GetGridItemHoverColor()76 const Color& GetGridItemHoverColor() const 77 { 78 return hoverColor_; 79 } GetHoverAnimationDuration()80 int32_t GetHoverAnimationDuration() const 81 { 82 return hoverAnimationDuration_; 83 } GetHoverToPressAnimationDuration()84 int32_t GetHoverToPressAnimationDuration() const 85 { 86 return hoverToPressAnimationDuration_; 87 } GetGridItemDisabledAlpha()88 double GetGridItemDisabledAlpha() const 89 { 90 return disabledAlpha_; 91 } GetGridItemEnabledAlpha()92 double GetGridItemEnabledAlpha() const 93 { 94 return enabledAlpha_; 95 } GetGridItemFocusRadius()96 const Dimension& GetGridItemFocusRadius() const 97 { 98 return focusRadius_; 99 } GetFocusPaintPadding()100 const Dimension& GetFocusPaintPadding() const 101 { 102 return focusPaintPadding_; 103 } GetGridItemFocusColor()104 const Color& GetGridItemFocusColor() const 105 { 106 return focusColor_; 107 } GetGridItemBorderRadius()108 const NG::BorderRadiusProperty& GetGridItemBorderRadius() const 109 { 110 return borderRadius_; 111 } 112 113 protected: 114 GridItemTheme() = default; 115 116 private: 117 Color pressColor_; 118 Color hoverColor_; 119 int32_t hoverAnimationDuration_ = 250; 120 int32_t hoverToPressAnimationDuration_ = 100; 121 double disabledAlpha_ = 0.4; 122 double enabledAlpha_ = 1.0; 123 Dimension focusRadius_; 124 Dimension focusPaintPadding_ = 3.0_vp; 125 Color focusColor_; 126 Dimension borderRadiusValue_; 127 NG::BorderRadiusProperty borderRadius_; 128 }; 129 } // namespace OHOS::Ace::NG 130 131 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_GRID_ITEM_THEME_H 132