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_WATERFLOW_WATER_FLOW_LAYOUT_UTILS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_LAYOUT_UTILS_H
18 #include <string>
19 
20 #include "core/components_ng/pattern/waterflow/layout/top_down/water_flow_layout_info.h"
21 #include "core/components_ng/pattern/waterflow/water_flow_layout_property.h"
22 #include "core/components_ng/property/layout_constraint.h"
23 namespace OHOS::Ace::NG {
24 class WaterFlowLayoutUtils {
25 public:
26     static std::string PreParseArgs(const std::string& args);
27     static FlowItemPosition GetItemPosition(const RefPtr<WaterFlowLayoutInfo>& info, int32_t index, float mainGap);
28 
29     struct ConstraintParams {
30         float crossSize = 0.0f;
31         float mainSize = 0.0f;
32         Axis axis = Axis::VERTICAL;
33         bool haveUserDefSize = false;
34     };
35     static LayoutConstraintF CreateChildConstraint(const ConstraintParams& params,
36         const RefPtr<WaterFlowLayoutProperty>& props, const RefPtr<LayoutWrapper>& child);
37 
38     /**
39      * @brief Measure self before measuring children.
40      *
41      * @return [idealSize given by parent, whether measure is successful (need to adapt to children size if not)].
42      */
43     static std::pair<SizeF, bool> PreMeasureSelf(LayoutWrapper* wrapper, Axis axis);
44 
45     /**
46      * @brief Helper to measure the footer node.
47      * REQUIRES: footer resides at index 0.
48      * @return main length of the footer node.
49      */
50     static float MeasureFooter(LayoutWrapper* layoutWrapper, Axis axis);
51 
52     /**
53      * @brief Get user defined height of an item from Sections.
54      *
55      * @param sections WaterFlowSections
56      * @param seg section index
57      * @param idx item index
58      * @return user defined item height, -1 if not defined.
59      */
60     static float GetUserDefHeight(const RefPtr<WaterFlowSections>& sections, int32_t seg, int32_t idx);
61     static void UpdateItemIdealSize(const RefPtr<LayoutWrapper>& item, Axis axis, float userHeight);
62 };
63 } // namespace OHOS::Ace::NG
64 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_LAYOUT_UTILS_H
65