1 /*
2  * Copyright (c) 2024 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_LAYOUT_UTILS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_LAYOUT_UTILS_H
18 
19 #include "core/components_ng/layout/layout_wrapper.h"
20 #include "core/components_ng/pattern/grid/grid_layout_info.h"
21 #include "core/components_ng/pattern/grid/grid_layout_options.h"
22 
23 namespace OHOS::Ace::NG {
24 class GridPattern;
25 
26 class GridLayoutUtils {
27 public:
28     /**
29      * @brief Gets the size of an item at the specified index.
30      *
31      * @param info The GridLayoutInfo object.
32      * @param wrapper The LayoutWrapper of Grid.
33      * @param idx The index of the item.
34      * @return The size of the item.
35      * IMPORTANT: Output assumes [row] represents mainSize and [column] represents crossSize.
36      */
37     static GridItemSize GetItemSize(const GridLayoutInfo* info, const LayoutWrapper* wrapper, int32_t idx);
38 
39     /**
40      * @brief Add a task to preload GridItems when Pipeline is idle.
41      *
42      * @param pattern of this Grid component.
43      * @param items list of GridItems to preload.
44      * @param buildCb callback to build a GridItem.
45      */
46     static void PreloadGridItems(
47         const RefPtr<GridPattern>& pattern, std::list<GridPreloadItem>&& items, const BuildGridItemCallback& buildCb);
48 
49 private:
50     // helper to add the GridItem build task to Pipeline
51     static void PreloadGridItemsHelper(const RefPtr<GridPattern>& pattern, const BuildGridItemCallback& buildCb);
52 };
53 } // namespace OHOS::Ace::NG
54 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_LAYOUT_UTILS_H
55