1 /*
2  * Copyright (c) 2022 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_GRID_ADAPTIVE_GRID_ADAPTIVE_LAYOUT_ALGORITHM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_GRID_ADAPTIVE_GRID_ADAPTIVE_LAYOUT_ALGORITHM_H
18 
19 #include "core/components_ng/layout/layout_algorithm.h"
20 #include "core/components_ng/layout/layout_wrapper.h"
21 #include "core/components_ng/pattern/grid/grid_layout_base_algorithm.h"
22 #include "core/components_ng/pattern/grid/grid_layout_info.h"
23 #include "core/components_ng/pattern/grid/grid_layout_property.h"
24 
25 namespace OHOS::Ace::NG {
26 
27 // Effect when rowsTemplate and columnsTemplate are not setted, this algorithm effect these attribute:
28 // columnsGap | rowsGap | layoutDirection | maxCount | minCount | cellLength.
29 class ACE_EXPORT GridAdaptiveLayoutAlgorithm : public GridLayoutBaseAlgorithm {
30     DECLARE_ACE_TYPE(GridAdaptiveLayoutAlgorithm, GridLayoutBaseAlgorithm);
31 
32 public:
GridAdaptiveLayoutAlgorithm(GridLayoutInfo gridLayoutInfo)33     explicit GridAdaptiveLayoutAlgorithm(GridLayoutInfo gridLayoutInfo)
34         : GridLayoutBaseAlgorithm(std::move(gridLayoutInfo)) {};
35     ~GridAdaptiveLayoutAlgorithm() override = default;
36 
37     void Measure(LayoutWrapper* layoutWrapper) override;
38     void Layout(LayoutWrapper* layoutWrapper) override;
39 
40 private:
41     OffsetF CalculateChildOffset(int32_t index, LayoutWrapper* layoutWrapper);
42 
43     // cell size of grid.
44     SizeF gridCellSize_;
45     // grid cell count in main axis.
46     int32_t mainCount_ = 0;
47     // grid cell count in cross axis.
48     int32_t crossCount_ = 0;
49     // total count has shown.
50     int32_t displayCount_ = 0;
51 
52     int32_t rowCount_ = 0;
53     int32_t columnCount_ = 0;
54 
55     ACE_DISALLOW_COPY_AND_MOVE(GridAdaptiveLayoutAlgorithm);
56 };
57 
58 } // namespace OHOS::Ace::NG
59 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_GRID_ADAPTIVE_GRID_ADAPTIVE_LAYOUT_ALGORITHM_H
60