• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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_PATTERNS_GRID_GRID_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GRID_GRID_MODEL_NG_H
18 
19 #include <string>
20 
21 #include "base/geometry/dimension.h"
22 #include "base/utils/macros.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components/common/properties/scroll_bar.h"
25 #include "core/components_ng/pattern/grid/grid_event_hub.h"
26 #include "core/components_ng/pattern/grid/grid_model.h"
27 
28 namespace OHOS::Ace::NG {
29 
30 class ACE_EXPORT GridModelNG : public OHOS::Ace::GridModel {
31 public:
32     void Create(
33         const RefPtr<ScrollControllerBase>& positionController, const RefPtr<ScrollProxy>& scrollProxy) override;
34     void Pop() override;
35     void SetLayoutOptions(GridLayoutOptions options) override;
36     void SetColumnsTemplate(const std::string& value) override;
37     void SetRowsTemplate(const std::string& value) override;
38     void SetColumnsGap(const Dimension& value) override;
39     void SetRowsGap(const Dimension& value) override;
40     void SetGridHeight(const Dimension& value) override;
41     void SetScrollBarMode(DisplayMode value) override;
42     void SetScrollBarColor(const std::string& value) override;
43     void SetScrollBarWidth(const std::string& value) override;
44     void SetCachedCount(int32_t value, bool show = false) override;
45     void SetIsRTL(TextDirection direction) override;
46     void SetLayoutDirection(FlexDirection value) override;
47     void SetMaxCount(int32_t value) override;
48     void SetMinCount(int32_t value) override;
49     void SetCellLength(int32_t value) override;
50     void SetEditable(bool value) override;
51     void SetMultiSelectable(bool value) override;
52     void SetSupportAnimation(bool value) override;
53     void SetSupportDragAnimation(bool value) override;
54     void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled, EffectEdge edge = EffectEdge::ALL) override;
55     void SetNestedScroll(const NestedScrollOptions& nestedOpt) override;
56     void SetScrollEnabled(bool scrollEnabled) override;
57     void SetFriction(double friction) override;
58     void SetFocusWrapMode(const std::optional<FocusWrapMode>& focusWrapMode) override;
59     void SetAlignItems(GridItemAlignment itemAlign) override;
60     void SetOnScrollToIndex(ScrollToIndexFunc&& value) override;
61     void SetOnScrollBarUpdate(ScrollBarUpdateFunc&& value) override;
62     void SetOnItemDragStart(std::function<void(const ItemDragInfo&, int32_t)>&& value) override;
63     void SetOnItemDragEnter(ItemDragEnterFunc&& value) override;
64     void SetOnItemDragMove(ItemDragMoveFunc&& value) override;
65     void SetOnItemDragLeave(ItemDragLeaveFunc&& value) override;
66     void SetOnItemDrop(ItemDropFunc&& value) override;
67     void SetOnScroll(OnScrollEvent&& onScroll) override;
68     void SetOnScrollFrameBegin(OnScrollFrameBeginEvent&& onScrollFrameBegin) override;
69     void SetOnScrollStart(OnScrollStartEvent&& onScrollStart) override;
70     void SetOnScrollStop(OnScrollStopEvent&& onScrollStop) override;
71     void SetOnScrollIndex(ScrollIndexFunc&& onScrollIndex) override;
72     void SetOnReachStart(OnReachEvent&& onReachStart) override;
73     void SetOnReachEnd(OnReachEvent&& onReachEnd) override;
74     void SetSyncLoad(bool syncLoad) override;
75     RefPtr<ScrollControllerBase> CreatePositionController() override;
76     RefPtr<ScrollProxy> CreateScrollBarProxy() override;
77     void CreateWithResourceObjFriction(const RefPtr<ResourceObject>& resObj) override;
78     void CreateWithResourceObjScrollBarColor(const RefPtr<ResourceObject>& resObj) override;
79 
80     DisplayMode GetDisplayMode() const override;
81 
82     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId);
83     static RefPtr<ScrollControllerBase> GetOrCreateController(FrameNode* frameNode);
84     static RefPtr<ScrollProxy> GetOrCreateScrollBarProxy(FrameNode* frameNode);
85     static void SetOnScrollIndex(FrameNode* frameNode, ScrollIndexFunc&& onScrollIndex);
86     static void SetColumnsTemplate(FrameNode* frameNode, const std::string& columnsTemplate);
87     static void SetRowsTemplate(FrameNode* frameNode, const std::string& rowsTemplate);
88     static void SetColumnsGap(FrameNode* frameNode, const Dimension& columnsGap);
89     static void SetRowsGap(FrameNode* frameNode, const Dimension& rowsGap);
90     static void SetScrollBarMode(FrameNode* frameNode, const std::optional<DisplayMode>& scrollBarMode);
91     static void SetScrollBarWidth(FrameNode* frameNode, const std::optional<Dimension>& scrollBarWidth);
92     static void SetScrollBarColor(FrameNode* frameNode, const std::optional<Color>& scrollBarColor);
93     static void SetCachedCount(FrameNode* frameNode, int32_t cachedCount);
94     static void SetShowCached(FrameNode* frameNode, bool show);
95     static void SetLayoutDirection(FrameNode* frameNode, const std::optional<FlexDirection>& layoutDirection);
96     static void SetMaxCount(FrameNode* frameNode, int32_t maxCount);
97     static void SetMinCount(FrameNode* frameNode, int32_t minCount);
98     static void SetCellLength(FrameNode* frameNode, int32_t cellLength);
99     static void SetEditable(FrameNode* frameNode, bool editMode);
100     static void SetMultiSelectable(FrameNode* frameNode, bool multiSelectable);
101     static void SetSupportAnimation(FrameNode* frameNode, bool supportAnimation);
102     static EdgeEffect GetEdgeEffect(FrameNode* frameNode);
103     static bool GetAlwaysEnabled(FrameNode* frameNode);
104     static void SetEdgeEffect(
105         FrameNode* frameNode, const std::optional<EdgeEffect>& edgeEffect, const std::optional<bool>& alwaysEnabled,
106         EffectEdge edge = EffectEdge::ALL);
107     static void SetNestedScroll(FrameNode* frameNode, const NestedScrollOptions& nestedOpt);
108     static void SetScrollEnabled(FrameNode* frameNode, bool scrollEnabled);
109     static void SetFriction(FrameNode* frameNode, const std::optional<double>& value);
110     static void SetFocusWrapMode(FrameNode* frameNode, const std::optional<FocusWrapMode>& focusWrapMode);
111     static FocusWrapMode GetFocusWrapMode(FrameNode* frameNode);
112     static void SetAlignItems(FrameNode* frameNode, const std::optional<GridItemAlignment>& itemAlign);
113     static std::string GetColumnsTemplate(FrameNode* frameNode);
114     static std::string GetRowsTemplate(FrameNode* frameNode);
115     static float GetColumnsGap(FrameNode* frameNode);
116     static float GetRowsGap(FrameNode* frameNode);
117     static int32_t GetCachedCount(FrameNode* frameNode);
118     static bool GetShowCached(FrameNode* frameNode);
119     static void InitScroller(FrameNode* frameNode, const RefPtr<ScrollControllerBase>& positionController,
120         const RefPtr<ScrollProxy>& scrollProxy);
121     static void SetLayoutOptions(FrameNode* frameNode, GridLayoutOptions& options);
122     static void SetOnScrollBarUpdate(FrameNode* frameNode, ScrollBarUpdateFunc&& value);
123     static void SetOnItemDragStart(FrameNode* frameNode, std::function<void(const ItemDragInfo&, int32_t)>&& value);
124     static void SetOnItemDragEnter(FrameNode* frameNode, ItemDragEnterFunc&& value);
125     static void SetOnItemDragMove(FrameNode* frameNode, ItemDragMoveFunc&& value);
126     static void SetOnItemDragLeave(FrameNode* frameNode, ItemDragLeaveFunc&& value);
127     static void SetOnItemDrop(FrameNode* frameNode, ItemDropFunc&& value);
128 
129     static void SetGridItemTotalCount(FrameNode* frameNode, int totalCount);
130 
131     static void SetGridItemAdapterFunc(FrameNode* frameNode, std::function<void(int start, int end)>&& requestFunc);
132     static void SetGridItemAdapterCallFinish(FrameNode* frameNode, int start, int end);
133     static void SetGridItemGetFunc(FrameNode* frameNode, std::function<RefPtr<FrameNode>(int32_t index)>&& getFunc);
134     static RefPtr<FrameNode> CreateGrid(int32_t nodeId);
135 
136     static void SetOnScrollFrameBegin(FrameNode* frameNode, OnScrollFrameBeginEvent&& onScrollFrameBegin);
137     static void SetOnReachStart(FrameNode* frameNode, OnReachEvent&& onReachStart);
138     static void SetOnReachEnd(FrameNode* frameNode, OnReachEvent&& onReachEnd);
139     static void SetOnScrollStart(FrameNode* frameNode, OnScrollStartEvent&& onScrollStart);
140     static void SetOnScrollStop(FrameNode* frameNode, OnScrollStopEvent&& onScrollStop);
141     static void SetOnScroll(FrameNode* frameNode, OnScrollEvent&& onScroll);
142     static void CreateWithResourceObjFriction(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj);
143     static void CreateWithResourceObjScrollBarColor(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj);
144 
145     static void SetSyncLoad(FrameNode* frameNode, bool syncLoad);
146     static bool GetSyncLoad(FrameNode* frameNode);
147 private:
148     static void AddDragFrameNodeToManager(FrameNode* frameNode);
149 };
150 
151 } // namespace OHOS::Ace::NG
152 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GRID_GRID_MODEL_NG_H
153