• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     }
130 
131 protected:
132     ListItemTheme() = default;
133 
134 private:
135     Color clickColor_;
136     double clickAlphaBegin_ = 1.0;
137     double clickAlphaEnd_ = 1.0;
138     double clickScale_ = 1.0;
139     double focusScale_ = 1.0;
140     double focusScaleLarge_ = 1.0;
141     double focusScaleMiddle_ = 1.0;
142     double focusScaleLittle_ = 1.0;
143     double focusOpacityLarge_ = 1.0;
144     double focusOpacityMiddle_ = 1.0;
145     double focusOpacityLittle_ = 1.0;
146     double focusAnimationDuration_ = 100.0;
147     double clickAnimationDuration_ = 200.0;
148     double paddingInPercent_ = 0.0;
149     Dimension itemSize_;
150     Dimension groupImageSize_;
151 };
152 
153 } // namespace OHOS::Ace
154 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_ITEM_THEME_H
155