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_ITEM_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_GRID_ITEM_LAYOUT_PROPERTY_H
18 
19 #include "core/components_ng/layout/layout_property.h"
20 
21 namespace OHOS::Ace::NG {
22 class InspectorFilter;
23 
24 class ACE_EXPORT GridItemLayoutProperty : public LayoutProperty {
25     DECLARE_ACE_TYPE(GridItemLayoutProperty, LayoutProperty);
26 
27 public:
28     GridItemLayoutProperty() = default;
29     ~GridItemLayoutProperty() override = default;
30 
Clone()31     RefPtr<LayoutProperty> Clone() const override
32     {
33         auto value = MakeRefPtr<GridItemLayoutProperty>();
34         value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this));
35         value->propRowStart_ = CloneRowStart();
36         value->propRowEnd_ = CloneRowEnd();
37         value->propColumnStart_ = CloneColumnStart();
38         value->propColumnEnd_ = CloneColumnEnd();
39         return value;
40     }
41 
Reset()42     void Reset() override
43     {
44         LayoutProperty::Reset();
45         ResetRowStart();
46         ResetRowEnd();
47         ResetColumnStart();
48         ResetColumnEnd();
49     }
50 
51     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
52 
53     ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(RowStart, int32_t);
OnRowStartUpdate(int32_t)54     void OnRowStartUpdate(int32_t /*rowStart*/) const
55     {
56         ResetGridLayoutInfoAndMeasure();
57     }
58 
59     ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(RowEnd, int32_t);
OnRowEndUpdate(int32_t)60     void OnRowEndUpdate(int32_t /*rowEnd*/) const
61     {
62         ResetGridLayoutInfoAndMeasure();
63     }
64 
65     ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(ColumnStart, int32_t);
OnColumnStartUpdate(int32_t)66     void OnColumnStartUpdate(int32_t /*columnStart*/) const
67     {
68         ResetGridLayoutInfoAndMeasure();
69     }
70 
71     ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(ColumnEnd, int32_t);
OnColumnEndUpdate(int32_t)72     void OnColumnEndUpdate(int32_t /*columnEnd*/) const
73     {
74         ResetGridLayoutInfoAndMeasure();
75     }
76 
77     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(MainIndex, int32_t, PROPERTY_UPDATE_LAYOUT);
78     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CrossIndex, int32_t, PROPERTY_UPDATE_LAYOUT);
79 
80     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RealColumnSpan, int32_t, PROPERTY_UPDATE_LAYOUT);
81     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RealRowSpan, int32_t, PROPERTY_UPDATE_LAYOUT);
82 
83     int32_t GetCustomCrossIndex(Axis axis) const;
84     int32_t GetMainSpan(Axis axis) const;
85     int32_t GetCrossSpan(Axis axis) const;
86     int32_t GetMainStart(Axis axis) const;
87     int32_t GetCrossStart(Axis axis) const;
88     int32_t GetMainEnd(Axis axis) const;
89     int32_t GetCrossEnd(Axis axis) const;
90     bool CheckWhetherCurrentItemAtExpectedPosition(Axis axis) const;
91     int32_t GetRealMainSpan(Axis axis) const;
92     int32_t GetRealCrossSpan(Axis axis) const;
SetNeedStretch(bool needStretch)93     void SetNeedStretch(bool needStretch)
94     {
95         needStretch_ = needStretch;
96     }
97 
GetStretchChild()98     bool GetStretchChild() const
99     {
100         return stretchChild_;
101     }
102 
SetStretchChild(bool stretchChild)103     void SetStretchChild(bool stretchChild)
104     {
105         stretchChild_ = stretchChild;
106     }
107 
GetNeedStretch()108     bool GetNeedStretch() const
109     {
110         return needStretch_;
111     }
112 
SetAxis(Axis axis)113     void SetAxis(Axis axis)
114     {
115         axis_ = axis;
116     }
117 
GetAxis()118     Axis GetAxis() const
119     {
120         return axis_;
121     }
122 
123 private:
124     ACE_DISALLOW_COPY_AND_MOVE(GridItemLayoutProperty);
125 
126     void ResetGridLayoutInfoAndMeasure() const;
127 
128     bool needStretch_ = false;
129     bool stretchChild_ = false;
130     Axis axis_ = Axis::NONE;
131 };
132 
133 } // namespace OHOS::Ace::NG
134 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_GRID_ITEM_LAYOUT_PROPERTY_H
135