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_LIST_LIST_ITEM_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_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 23 namespace OHOS::Ace { 24 25 /** 26 * ListItemTheme defines styles of list or grid item. ListItemTheme should be built 27 * using ListItemTheme::Builder. 28 */ 29 class ListItemTheme : public virtual Theme { 30 DECLARE_ACE_TYPE(ListItemTheme, Theme); 31 32 public: 33 class Builder { 34 public: 35 Builder() = default; 36 ~Builder() = default; 37 Build(const RefPtr<ThemeConstants> & themeConstants)38 RefPtr<ListItemTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 39 { 40 RefPtr<ListItemTheme> theme = AceType::Claim(new ListItemTheme()); 41 if (!themeConstants) { 42 return theme; 43 } 44 theme->clickColor_ = themeConstants->GetColor(THEME_ITEM_CLICK_COLOR); 45 theme->clickAlphaBegin_ = themeConstants->GetDouble(THEME_ITEM_CLICK_ALPHA_BEGIN); 46 theme->clickAlphaEnd_ = themeConstants->GetDouble(THEME_ITEM_CLICK_ALPHA_END); 47 theme->clickScale_ = themeConstants->GetDouble(THEME_ITEM_CLICK_SCALE); 48 theme->focusScale_ = themeConstants->GetDouble(THEME_ITEM_FOCUS_SCALE); 49 theme->focusScaleLarge_ = themeConstants->GetDouble(THEME_ITEM_FOCUS_SCALE_LARGE); 50 theme->focusScaleMiddle_ = themeConstants->GetDouble(THEME_ITEM_FOCUS_SCALE_MIDDLE); 51 theme->focusScaleLittle_ = themeConstants->GetDouble(THEME_ITEM_FOCUS_SCALE_LITTLE); 52 theme->focusOpacityLarge_ = themeConstants->GetDouble(THEME_ITEM_FOCUS_OPACITY_LARGE); 53 theme->focusOpacityMiddle_ = themeConstants->GetDouble(THEME_ITEM_FOCUS_OPACITY_MIDDLE); 54 theme->focusOpacityLittle_ = themeConstants->GetDouble(THEME_ITEM_FOCUS_OPACITY_LITTLE); 55 theme->focusAnimationDuration_ = themeConstants->GetDouble(THEME_ITEM_FOCUS_ANIMATION_DURATION); 56 theme->clickAnimationDuration_ = themeConstants->GetDouble(THEME_ITEM_CLICK_ANIMATION_DURATION); 57 theme->itemSize_ = themeConstants->GetDimension(THEME_ITEM_SIZE); 58 theme->paddingInPercent_ = themeConstants->GetDouble(THEME_ITEM_PADDING_IN_PERCENT); 59 theme->groupImageSize_ = themeConstants->GetDimension(THEME_ITEM_GROUP_IMAGE_SIZE); 60 return theme; 61 } 62 }; 63 64 ~ListItemTheme() override = default; 65 GetClickColor()66 const Color& GetClickColor() const 67 { 68 return clickColor_; 69 } GetClickAlphaBegin()70 double GetClickAlphaBegin() const 71 { 72 return clickAlphaBegin_; 73 } GetClickAlphaEnd()74 double GetClickAlphaEnd() const 75 { 76 return clickAlphaEnd_; 77 } GetClickScale()78 double GetClickScale() const 79 { 80 return clickScale_; 81 } GetFocusScale()82 double GetFocusScale() const 83 { 84 return focusScale_; 85 } GetFocusScaleLarge()86 double GetFocusScaleLarge() const 87 { 88 return focusScaleLarge_; 89 } GetFocusScaleMiddle()90 double GetFocusScaleMiddle() const 91 { 92 return focusScaleMiddle_; 93 } GetFocusScaleLittle()94 double GetFocusScaleLittle() const 95 { 96 return focusScaleLittle_; 97 } GetFocusOpacityLarge()98 double GetFocusOpacityLarge() const 99 { 100 return focusOpacityLarge_; 101 } GetFocusOpacityMiddle()102 double GetFocusOpacityMiddle() const 103 { 104 return focusOpacityMiddle_; 105 } GetFocusOpacityLittle()106 double GetFocusOpacityLittle() const 107 { 108 return focusOpacityLittle_; 109 } GetFocusAnimationDuration()110 double GetFocusAnimationDuration() const 111 { 112 return focusAnimationDuration_; 113 } GetClickAnimationDuration()114 double GetClickAnimationDuration() const 115 { 116 return clickAnimationDuration_; 117 } GetItemSize()118 Dimension GetItemSize() const 119 { 120 return itemSize_; 121 } GetItemPaddingInPercent()122 double GetItemPaddingInPercent() const 123 { 124 return paddingInPercent_; 125 } GetGroupImageSize()126 Dimension GetGroupImageSize() const 127 { 128 return groupImageSize_; 129 } GetItemSwipeThreshold()130 double GetItemSwipeThreshold() const 131 { 132 return swipeThreshold_; 133 } GetItemSwipeSpeedThreshold()134 double GetItemSwipeSpeedThreshold() const 135 { 136 return swipeSpeedThreshold_; 137 } GetItemSwipeRatio()138 double GetItemSwipeRatio() const 139 { 140 return swipeRatio_; 141 } GetItemSwipeSpringMass()142 double GetItemSwipeSpringMass() const 143 { 144 return swipeSpringMass_; 145 } GetItemSwipeSpringStiffness()146 double GetItemSwipeSpringStiffness() const 147 { 148 return swipeSpringStiffness_; 149 } GetItemSwipeSpringDamping()150 double GetItemSwipeSpringDamping() const 151 { 152 return swipeSpringDamping_; 153 } 154 155 protected: 156 ListItemTheme() = default; 157 158 private: 159 Color clickColor_; 160 double clickAlphaBegin_ = 1.0; 161 double clickAlphaEnd_ = 1.0; 162 double clickScale_ = 1.0; 163 double focusScale_ = 1.0; 164 double focusScaleLarge_ = 1.0; 165 double focusScaleMiddle_ = 1.0; 166 double focusScaleLittle_ = 1.0; 167 double focusOpacityLarge_ = 1.0; 168 double focusOpacityMiddle_ = 1.0; 169 double focusOpacityLittle_ = 1.0; 170 double focusAnimationDuration_ = 100.0; 171 double clickAnimationDuration_ = 200.0; 172 double paddingInPercent_ = 0.0; 173 double swipeThreshold_ = 0.25; 174 double swipeSpeedThreshold_ = 1200; 175 double swipeRatio_ = 0.6; 176 double swipeSpringMass_ = 1; 177 double swipeSpringStiffness_ = 228; 178 double swipeSpringDamping_ = 30; 179 Dimension itemSize_; 180 Dimension groupImageSize_; 181 }; 182 183 } // namespace OHOS::Ace 184 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_ITEM_THEME_H 185