• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef ACE_STATIC
26 class ACE_FORCE_EXPORT MeasureLayoutChild {
27 #else
28 class MeasureLayoutChild {
29 #endif
30 public:
Init(MeasureLayoutParam * parent,int32_t index)31     inline void Init(MeasureLayoutParam* parent, int32_t index)
32     {
33         parent_ = parent;
34         index_ = index;
35     }
36     RefPtr<LayoutWrapper> GetChild() const;
37     RefPtr<LayoutWrapper> GetOrCreateChild() const;
38     LayoutConstraintF CreateChildConstraint() const;
39     void UpdateSize(const SizeF& size);
40 private:
41     MeasureLayoutParam* parent_;
42     int32_t index_ = 0;
43 };
44 
45 #ifdef ACE_STATIC
46 class ACE_FORCE_EXPORT MeasureLayoutParam : public AceType {
47 #else
48 class MeasureLayoutParam : public AceType {
49 #endif
50     DECLARE_ACE_TYPE(MeasureLayoutParam, AceType);
51 public:
52     MeasureLayoutParam(LayoutWrapper* layoutWrapper);
53     ~MeasureLayoutParam();
54 
55     RefPtr<LayoutWrapper> GetChildByIndex(int32_t index);
56     RefPtr<LayoutWrapper> GetOrCreateChildByIndex(int32_t index);
57     LayoutConstraintF CreateChildConstraint() const;
GetTotalChildCount()58     int32_t GetTotalChildCount() const
59     {
60         return count_;
61     }
Get(int32_t index)62     MeasureLayoutChild& Get(int32_t index)
63     {
64         return children_[index];
65     }
66 
ChildIndexInRange(int32_t index)67     bool ChildIndexInRange(int32_t index)
68     {
69         return index >= 0 && index < static_cast<int32_t>(children_.size());
70     }
71 
GetLayoutWrapper()72     LayoutWrapper* GetLayoutWrapper()
73     {
74         return layoutWrapper_;
75     }
Init()76     virtual void Init() {}
UpdateSize(int32_t index,const SizeF & size)77     virtual void UpdateSize(int32_t index, const SizeF& size) {}
78     virtual void Update(LayoutWrapper* layoutWrapper);
79 private:
80     LayoutWrapper* layoutWrapper_;
81     std::vector<MeasureLayoutChild> children_;
82     int32_t count_ = 0;
83 };
84 } // namespace OHOS::Ace::NG
85 #endif
86