• 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_GRID_LAYOUT_GRID_LAYOUT_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_GRID_LAYOUT_GRID_LAYOUT_COMPONENT_H
18 
19 #include "base/utils/macros.h"
20 #include "core/components/common/layout/constants.h"
21 #include "core/components/common/properties/scroll_bar.h"
22 #include "core/components/scroll_bar/scroll_bar_proxy.h"
23 #include "core/components_v2/foreach/lazy_foreach_component.h"
24 #include "core/components_v2/grid/grid_position_controller.h"
25 #include "core/pipeline/base/component_group.h"
26 
27 namespace OHOS::Ace {
28 
29 using OnGridDragEnterFunc = std::function<void(const ItemDragInfo&)>;
30 using OnGridDragMoveFunc = std::function<void(const ItemDragInfo&, int32_t, int32_t)>;
31 using OnGridDragLeaveFunc = std::function<void(const ItemDragInfo&, int32_t)>;
32 using OnGridDragStartFunc = std::function<RefPtr<Component>(const ItemDragInfo&, int32_t)>;
33 using OnGridDropFunc = std::function<void(const ItemDragInfo&, int32_t, int32_t, bool)>;
34 
35 class ACE_EXPORT GridLayoutComponent : public ComponentGroup {
36     DECLARE_ACE_TYPE(GridLayoutComponent, ComponentGroup);
37 
38 public:
GridLayoutComponent(const std::list<RefPtr<Component>> & children)39     explicit GridLayoutComponent(const std::list<RefPtr<Component>>& children) : ComponentGroup(children) {}
40 
41     ~GridLayoutComponent() override = default;
42 
43     RefPtr<Element> CreateElement() override;
44 
45     RefPtr<RenderNode> CreateRenderNode() override;
46 
47     void SetDirection(FlexDirection direction);
48     void SetFlexAlign(FlexAlign flexAlign);
49     void SetColumnCount(int32_t count);
50     void SetRowCount(int32_t count);
51     void SetWidth(double width);
52     void SetHeight(double height);
53     void SetColumnsArgs(const std::string& columnsArgs);
54     void SetRowsArgs(const std::string& rowsArgs);
55     void SetColumnGap(const Dimension& columnGap);
56     void SetRowGap(const Dimension& rowGap);
57     void SetRightToLeft(bool rightToLeft);
58 
59     // set scroll bar color
60     void SetScrollBarColor(const std::string& color);
61 
62     // set scroll bar width
63     void SetScrollBarWidth(const std::string& width);
64 
65     void SetScrollBar(DisplayMode displayMode);
66 
GetColumnsArgs()67     const std::string& GetColumnsArgs() const
68     {
69         return columnsArgs_;
70     }
71 
GetRowsArgs()72     const std::string& GetRowsArgs() const
73     {
74         return rowsArgs_;
75     }
76 
GetColumnGap()77     const Dimension& GetColumnGap() const
78     {
79         return columnGap_;
80     }
81 
GetRowGap()82     const Dimension& GetRowGap() const
83     {
84         return rowGap_;
85     }
86 
GetDirection()87     FlexDirection GetDirection() const
88     {
89         return direction_;
90     }
91 
GetFlexAlign()92     FlexAlign GetFlexAlign() const
93     {
94         return flexAlign_;
95     }
96 
GetColumnCount()97     int32_t GetColumnCount() const
98     {
99         return columnCount_;
100     }
101 
GetRowCount()102     int32_t GetRowCount() const
103     {
104         return rowCount_;
105     }
106 
GetWidth()107     double GetWidth() const
108     {
109         return width_;
110     }
111 
GetHeight()112     double GetHeight() const
113     {
114         return height_;
115     }
116 
GetRightToLeft()117     bool GetRightToLeft() const
118     {
119         return rightToLeft_;
120     }
121 
SetUseScroll(bool flag)122     void SetUseScroll(bool flag)
123     {
124         useScroll_ = flag;
125     }
126 
GetScrollBarColor()127     const std::string& GetScrollBarColor() const
128     {
129         return scrollBarColor_;
130     }
131 
GetScrollBarWidth()132     const std::string& GetScrollBarWidth() const
133     {
134         return scrollBarWidth_;
135     }
136 
GetScrollBar()137     DisplayMode GetScrollBar()
138     {
139         return displayMode_;
140     }
141 
SetDeclarative()142     void SetDeclarative()
143     {
144         isDeclarative_ = true;
145     }
146 
GetController()147     const RefPtr<V2::GridPositionController>& GetController() const
148     {
149         return controller_;
150     }
151 
SetController(const RefPtr<V2::GridPositionController> & controller)152     void SetController(const RefPtr<V2::GridPositionController>& controller)
153     {
154         controller_ = controller;
155     }
156 
SetScrolledEvent(const EventMarker & event)157     void SetScrolledEvent(const EventMarker& event)
158     {
159         scrolledEvent_ = event;
160     }
161 
GetScrolledEvent()162     const EventMarker& GetScrolledEvent() const
163     {
164         return scrolledEvent_;
165     }
166 
SetCachedCount(int32_t cacheCount)167     void SetCachedCount(int32_t cacheCount)
168     {
169         cacheCount_ = cacheCount;
170     }
171 
GetCacheCount()172     int32_t GetCacheCount() const
173     {
174         return cacheCount_;
175     }
176 
SetScrollBarProxy(const RefPtr<ScrollBarProxy> & scrollBarProxy)177     void SetScrollBarProxy(const RefPtr<ScrollBarProxy>& scrollBarProxy)
178     {
179         scrollBarProxy_ = scrollBarProxy;
180     }
181 
GetScrollBarProxy()182     const RefPtr<ScrollBarProxy>& GetScrollBarProxy() const
183     {
184         return scrollBarProxy_;
185     }
186 
SetEditMode(bool editMode)187     void SetEditMode(bool editMode)
188     {
189         editMode_ = editMode;
190     }
191 
GetEditMode()192     bool GetEditMode() const
193     {
194         return editMode_;
195     }
196 
SetMaxCount(int32_t maxCount)197     void SetMaxCount(int32_t maxCount)
198     {
199         maxCount_ = maxCount;
200     }
201 
GetMaxCount(void)202     int32_t GetMaxCount(void) const
203     {
204         return maxCount_;
205     }
206 
SetMinCount(int32_t minCount)207     void SetMinCount(int32_t minCount)
208     {
209         minCount_ = minCount;
210     }
211 
GetMinCount(void)212     int32_t GetMinCount(void) const
213     {
214         return minCount_;
215     }
216 
SetCellLength(int32_t cellLength)217     void SetCellLength(int32_t cellLength)
218     {
219         cellLength_ = cellLength;
220     }
221 
GetCellLength(void)222     int32_t GetCellLength(void) const
223     {
224         return cellLength_;
225     }
226 
SetSupportAnimation(bool supportAnimation)227     void SetSupportAnimation(bool supportAnimation)
228     {
229         supportAnimation_ = supportAnimation;
230     }
231 
GetSupportAnimation()232     bool GetSupportAnimation()
233     {
234         return supportAnimation_;
235     }
236 
237     void SetOnGridDragEnterId(const OnGridDragEnterFunc& onGridDragEnterId);
238     void SetOnGridDragMoveId(const OnGridDragMoveFunc& onGridDragMoveId);
239     void SetOnGridDragLeaveId(const OnGridDragLeaveFunc& onGridDragLeaveId);
240     void SetOnGridDragStartId(const OnGridDragStartFunc& onGridDragStartId);
241     void SetOnGridDropId(const OnGridDropFunc& onGridDropId);
242     const OnGridDragEnterFunc& GetOnGridDragEnterId() const;
243     const OnGridDragMoveFunc& GetOnGridDragMoveId() const;
244     const OnGridDragLeaveFunc& GetOnGridDragLeaveId() const;
245     const OnGridDragStartFunc& GetOnGridDragStartId() const;
246     const OnGridDropFunc& GetOnGridDropId() const;
247 
SetMultiSelectable(bool multiSelectable)248     void SetMultiSelectable(bool multiSelectable)
249     {
250         multiSelectable_ = multiSelectable;
251     }
252 
GetMultiSelectable()253     bool GetMultiSelectable() const
254     {
255         return multiSelectable_;
256     }
257 
258 private:
259     FlexDirection direction_ = FlexDirection::COLUMN;
260     FlexAlign flexAlign_ = FlexAlign::CENTER;
261     double width_ = -1.0;
262     double height_ = -1.0;
263     int32_t columnCount_ = 1;
264     int32_t rowCount_ = 1;
265     bool isDeclarative_ = false;
266     int32_t cacheCount_ = 1;
267     bool supportAnimation_ = false;
268 
269     std::string columnsArgs_;
270     std::string rowsArgs_;
271     Dimension columnGap_ = 0.0_px;
272     Dimension rowGap_ = 0.0_px;
273     bool rightToLeft_ = false;
274     bool useScroll_ = true;
275 
276     // scroll bar attribute
277     std::string scrollBarColor_;
278     std::string scrollBarWidth_;
279     DisplayMode displayMode_ = DisplayMode::OFF;
280     RefPtr<V2::GridPositionController> controller_;
281     EventMarker scrolledEvent_;
282     RefPtr<ScrollBarProxy> scrollBarProxy_;
283 
284     // drag in grid attribute
285     bool editMode_ = false;
286     bool multiSelectable_ = false;
287     int32_t maxCount_ = 1;
288     int32_t minCount_ = 1;
289     int32_t cellLength_ = 0;
290     OnGridDragEnterFunc onGridDragEnterId_;
291     OnGridDragMoveFunc onGridDragMoveId_;
292     OnGridDragLeaveFunc onGridDragLeaveId_;
293     OnGridDragStartFunc onGridDragStartId_;
294     OnGridDropFunc onGridDropId_;
295 };
296 
297 } // namespace OHOS::Ace
298 
299 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_GRID_LAYOUT_GRID_LAYOUT_COMPONENT_H
300