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 "grid_container_layout_property.h"
17
18 namespace OHOS::Ace::NG {
19
RegistGridChild(const RefPtr<FrameNode> & child)20 void GridContainerLayoutProperty::RegistGridChild(const RefPtr<FrameNode>& child)
21 {
22 childrenFramenode_.emplace_back(child);
23 }
24
OnContainerInfoUpdate(const GridContainerInfo &)25 void GridContainerLayoutProperty::OnContainerInfoUpdate(const GridContainerInfo& /* info */)
26 {
27 auto p = childrenFramenode_.begin();
28 while (p != childrenFramenode_.end()) {
29 RefPtr<FrameNode> child = p->Upgrade();
30 if (child) {
31 child->MarkDirtyNode(PROPERTY_UPDATE_MEASURE | PROPERTY_UPDATE_LAYOUT);
32 }
33 p = childrenFramenode_.erase(p);
34 }
35 }
36
BuildWidth(float width)37 void GridContainerLayoutProperty::BuildWidth(float width)
38 {
39 if (GreaterOrEqualToInfinity(width)) {
40 propContainerInfo_->BuildColumnWidth();
41 } else {
42 propContainerInfo_->BuildColumnWidth(width);
43 }
44 }
45
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter) const46 void GridContainerLayoutProperty::ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const
47 {
48 LinearLayoutProperty::ToJsonValue(json, filter);
49 if (!HasContainerInfo()) {
50 return;
51 }
52 /* no fixed attr below, just return */
53 if (filter.IsFastFilter()) {
54 return;
55 }
56 auto info = GetContainerInfoValue();
57 const std::string sizeTypeStrs[] { "SizeType.Auto", "SizeType.XS", "SizeType.SM", "SizeType.MD", "SizeType.LG",
58 "SizeType.XL" };
59 auto constructor = JsonUtil::Create(true);
60 constructor->Put("columns", std::to_string(info.GetColumns()).c_str());
61 constructor->Put("sizeType", sizeTypeStrs[static_cast<int32_t>(info.GetSizeType())].c_str());
62 constructor->Put("gutter", info.GetGutterWidth().ToString().c_str());
63 constructor->Put("margin", info.GetMarginLeft().ToString().c_str());
64
65 json->PutExtAttr("constructor", constructor, filter);
66 }
67
68 } // namespace OHOS::Ace::NG
69