• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/components_ng/pattern/grid/grid_layout_property.h"
17 
18 #include "base/geometry/dimension.h"
19 #include "base/utils/utils.h"
20 #include "core/components/scroll/scroll_bar_theme.h"
21 #include "core/components_ng/base/frame_node.h"
22 #include "core/components_ng/pattern/grid/grid_pattern.h"
23 #include "core/pipeline_ng/pipeline_context.h"
24 
25 namespace OHOS::Ace::NG {
26 
ResetGridLayoutInfoAndMeasure() const27 void GridLayoutProperty::ResetGridLayoutInfoAndMeasure() const
28 {
29     auto host = GetHost();
30     CHECK_NULL_VOID(host);
31     auto pattern = host->GetPattern<GridPattern>();
32     CHECK_NULL_VOID(pattern);
33     pattern->ResetGridLayoutInfo();
34     if (host->GetParent()) {
35         host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
36     }
37 }
38 
ToJsonValue(std::unique_ptr<JsonValue> & json) const39 void GridLayoutProperty::ToJsonValue(std::unique_ptr<JsonValue>& json) const
40 {
41     LayoutProperty::ToJsonValue(json);
42     json->Put("columnsTemplate", propColumnsTemplate_.value_or("").c_str());
43     json->Put("rowsTemplate", propRowsTemplate_.value_or("").c_str());
44     json->Put("columnsGap", propColumnsGap_.value_or(0.0_vp).ToString().c_str());
45     json->Put("rowsGap", propRowsGap_.value_or(0.0_vp).ToString().c_str());
46     json->Put("cachedCount", propCachedCount_.value_or(1));
47     json->Put("editMode", propEditable_.value_or(false) ? "true" : "false");
48     json->Put("layoutDirection", GetGridDirectionStr().c_str());
49     json->Put("maxCount", propMaxCount_.value_or(Infinity<int32_t>()));
50     json->Put("minCount", propMinCount_.value_or(1));
51     json->Put("cellLength", propCellLength_.value_or(0));
52     auto edgeEffect = propEdgeEffect_.value_or(EdgeEffect::NONE);
53     if (edgeEffect == EdgeEffect::SPRING) {
54         json->Put("edgeEffect", "EdgeEffect.Spring");
55     } else if (edgeEffect == EdgeEffect::FADE) {
56         json->Put("edgeEffect", "EdgeEffect.Fade");
57     } else {
58         json->Put("edgeEffect", "EdgeEffect.None");
59     }
60     json->Put("enableScrollInteraction", propScrollEnabled_.value_or(true));
61 }
62 
GetGridDirectionStr() const63 std::string GridLayoutProperty::GetGridDirectionStr() const
64 {
65     auto gridDirection = propGridDirection_.value_or(FlexDirection::ROW);
66     switch (gridDirection) {
67         case FlexDirection::ROW:
68             return "GridDirection.Row";
69         case FlexDirection::ROW_REVERSE:
70             return "GridDirection.RowReverse";
71         case FlexDirection::COLUMN:
72             return "GridDirection.Column";
73         case FlexDirection::COLUMN_REVERSE:
74             return "GridDirection.ColumnReverse";
75         default:
76             LOGE("grid direction %{public}d is not valid", gridDirection);
77             break;
78     }
79     return "GridDirection.Row";
80 }
81 
82 } // namespace OHOS::Ace::NG
83