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_CUSTOM_CUSTOM_MEASURE_LAYOUT_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CUSTOM_CUSTOM_MEASURE_LAYOUT_NODE_H
18 
19 #include "core/components_ng/layout/layout_wrapper.h"
20 #include "core/components_ng/property/layout_constraint.h"
21 
22 namespace OHOS::Ace::NG {
23 class MeasureLayoutParam;
24 
25 class MeasureLayoutChild {
26 public:
Init(MeasureLayoutParam * parent,int32_t index)27     inline void Init(MeasureLayoutParam* parent, int32_t index)
28     {
29         parent_ = parent;
30         index_ = index;
31     }
32     RefPtr<LayoutWrapper> GetChild() const;
33     RefPtr<LayoutWrapper> GetOrCreateChild() const;
34     LayoutConstraintF CreateChildConstraint() const;
35     void UpdateSize(const SizeF& size);
36 private:
37     MeasureLayoutParam* parent_;
38     int32_t index_ = 0;
39 };
40 
41 class MeasureLayoutParam : public AceType {
42     DECLARE_ACE_TYPE(MeasureLayoutParam, AceType)
43 public:
44     MeasureLayoutParam(LayoutWrapper* layoutWrapper);
45     ~MeasureLayoutParam();
46 
47     RefPtr<LayoutWrapper> GetChildByIndex(int32_t index);
48     RefPtr<LayoutWrapper> GetOrCreateChildByIndex(int32_t index);
49     LayoutConstraintF CreateChildConstraint() const;
GetTotalChildCount()50     int32_t GetTotalChildCount() const
51     {
52         return count_;
53     }
Get(int32_t index)54     MeasureLayoutChild& Get(int32_t index)
55     {
56         return children_[index];
57     }
58 
ChildIndexInRange(int32_t index)59     bool ChildIndexInRange(int32_t index)
60     {
61         return index >= 0 && index < static_cast<int32_t>(children_.size());
62     }
63 
GetLayoutWrapper()64     LayoutWrapper* GetLayoutWrapper()
65     {
66         return layoutWrapper_;
67     }
Init()68     virtual void Init() {}
UpdateSize(int32_t index,const SizeF & size)69     virtual void UpdateSize(int32_t index, const SizeF& size) {}
70     virtual void Update(LayoutWrapper* layoutWrapper);
71 private:
72     LayoutWrapper* layoutWrapper_;
73     std::vector<MeasureLayoutChild> children_;
74     int32_t count_ = 0;
75 };
76 } // namespace OHOS::Ace::NG
77 #endif
78