• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_LAYOUT_PROPERTY_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "core/components_ng/layout/layout_property.h"
21 
22 namespace OHOS::Ace::NG {
23 class InspectorFilter;
24 
25 class ACE_EXPORT WaterFlowLayoutProperty : public LayoutProperty {
26     DECLARE_ACE_TYPE(WaterFlowLayoutProperty, LayoutProperty);
27 
28 public:
29     WaterFlowLayoutProperty() = default;
30     ~WaterFlowLayoutProperty() override = default;
31 
32     RefPtr<LayoutProperty> Clone() const override;
33 
Reset()34     void Reset() override
35     {
36         LayoutProperty::Reset();
37         ResetColumnsTemplate();
38         ResetRowsTemplate();
39         ResetColumnsGap();
40         ResetRowsGap();
41         ResetWaterflowDirection();
42         ResetScrollEnabled();
43         itemLayoutConstraint_.reset();
44     }
45 
46     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
47 
GetAxis()48     Axis GetAxis() const
49     {
50         auto axis = propWaterflowDirection_.value_or(FlexDirection::COLUMN);
51         return (axis == FlexDirection::COLUMN || axis == FlexDirection::COLUMN_REVERSE) ? Axis::VERTICAL
52                                                                                         : Axis::HORIZONTAL;
53     }
54 
IsReverse()55     bool IsReverse() const
56     {
57         auto axis = propWaterflowDirection_.value_or(FlexDirection::COLUMN);
58         auto isRtl = GetNonAutoLayoutDirection() == TextDirection::RTL;
59         return (!isRtl && (axis == FlexDirection::COLUMN_REVERSE || axis == FlexDirection::ROW_REVERSE)) ||
60                 (isRtl && (axis == FlexDirection::COLUMN_REVERSE || axis == FlexDirection::ROW));
61     }
62 
63     ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(ColumnsTemplate, std::string);
OnColumnsTemplateUpdate(const std::string &)64     void OnColumnsTemplateUpdate(const std::string& /* columnsTemplate */) const
65     {
66         ResetWaterflowLayoutInfoAndMeasure();
67     }
68 
69     ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(RowsTemplate, std::string);
OnRowsTemplateUpdate(const std::string &)70     void OnRowsTemplateUpdate(const std::string& /* rowsTemplate */) const
71     {
72         ResetWaterflowLayoutInfoAndMeasure();
73     }
74 
75     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP_AND_USING_CALLBACK(ColumnsGap, Dimension, PROPERTY_UPDATE_MEASURE);
76     void OnColumnsGapUpdate(Dimension /* columnsGap */) const;
77 
78     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP_AND_USING_CALLBACK(RowsGap, Dimension, PROPERTY_UPDATE_MEASURE);
79     void OnRowsGapUpdate(Dimension /* rowsGap */) const;
80 
81     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CachedCount, int32_t, PROPERTY_UPDATE_MEASURE_SELF);
82 
83     ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(WaterflowDirection, FlexDirection);
OnWaterflowDirectionUpdate(FlexDirection)84     void OnWaterflowDirectionUpdate(FlexDirection /* WaterflowDirection */) const
85     {
86         ResetWaterflowLayoutInfoAndMeasure();
87     }
88 
UpdateItemMinSize(const CalcSize & value)89     void UpdateItemMinSize(const CalcSize& value)
90     {
91         if (!itemLayoutConstraint_) {
92             itemLayoutConstraint_ = std::make_unique<MeasureProperty>();
93         }
94         if (itemLayoutConstraint_->UpdateMinSizeWithCheck(value)) {
95             propertyChangeFlag_ = propertyChangeFlag_ | PROPERTY_UPDATE_MEASURE;
96         }
97     }
98 
UpdateItemMaxSize(const CalcSize & value)99     void UpdateItemMaxSize(const CalcSize& value)
100     {
101         if (!itemLayoutConstraint_) {
102             itemLayoutConstraint_ = std::make_unique<MeasureProperty>();
103         }
104         if (itemLayoutConstraint_->UpdateMaxSizeWithCheck(value)) {
105             propertyChangeFlag_ = propertyChangeFlag_ | PROPERTY_UPDATE_MEASURE;
106         }
107     }
108 
GetItemMinSize()109     std::optional<CalcSize> GetItemMinSize() const
110     {
111         if (itemLayoutConstraint_) {
112             return itemLayoutConstraint_->minSize;
113         }
114         return std::optional<CalcSize>();
115     }
116 
GetItemMaxSize()117     std::optional<CalcSize> GetItemMaxSize() const
118     {
119         if (itemLayoutConstraint_) {
120             return itemLayoutConstraint_->maxSize;
121         }
122         return std::optional<CalcSize>();
123     }
124 
HasItemLayoutConstraint()125     bool HasItemLayoutConstraint() const
126     {
127         return itemLayoutConstraint_ != nullptr;
128     }
129 
130     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ScrollEnabled, bool, PROPERTY_UPDATE_MEASURE);
131 
132 private:
133     ACE_DISALLOW_COPY_AND_MOVE(WaterFlowLayoutProperty);
134 
135     void ResetWaterflowLayoutInfoAndMeasure() const;
136     std::string GetWaterflowDirectionStr() const;
137     std::unique_ptr<MeasureProperty> itemLayoutConstraint_;
138 };
139 } // namespace OHOS::Ace::NG
140 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_LAYOUT_PROPERTY_H
141