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_LIST_LIST_ITEM_GROUP_LAYOUT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_ITEM_GROUP_LAYOUT_PROPERTY_H 18 19 #include "base/geometry/axis.h" 20 #include "base/utils/macros.h" 21 #include "core/components/common/layout/constants.h" 22 #include "core/components_ng/base/inspector_filter.h" 23 #include "core/components_ng/layout/layout_property.h" 24 #include "core/components_ng/property/property.h" 25 #include "core/components_v2/list/list_properties.h" 26 27 namespace OHOS::Ace::NG { 28 class ACE_EXPORT ListItemGroupLayoutProperty : public LayoutProperty { 29 DECLARE_ACE_TYPE(ListItemGroupLayoutProperty, LayoutProperty); 30 31 public: 32 ListItemGroupLayoutProperty() = default; 33 34 ~ListItemGroupLayoutProperty() override = default; 35 Clone()36 RefPtr<LayoutProperty> Clone() const override 37 { 38 auto value = MakeRefPtr<ListItemGroupLayoutProperty>(); 39 value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this)); 40 value->propSpace_ = CloneSpace(); 41 value->propDivider_ = CloneDivider(); 42 return value; 43 } 44 Reset()45 void Reset() override 46 { 47 LayoutProperty::Reset(); 48 ResetSpace(); 49 ResetDivider(); 50 } 51 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)52 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 53 { 54 LayoutProperty::ToJsonValue(json, filter); 55 /* no fixed attr below, just return */ 56 if (filter.IsFastFilter()) { 57 return; 58 } 59 json->PutExtAttr("space", propSpace_.value_or(Dimension(0, DimensionUnit::VP)).ToString().c_str(), filter); 60 if (propDivider_.has_value()) { 61 auto divider = JsonUtil::Create(true); 62 divider->Put("strokeWidth", propDivider_.value().strokeWidth.ToString().c_str()); 63 divider->Put("startMargin", propDivider_.value().startMargin.ToString().c_str()); 64 divider->Put("endMargin", propDivider_.value().endMargin.ToString().c_str()); 65 divider->Put("color", propDivider_.value().color.ColorToString().c_str()); 66 json->PutExtAttr("divider", divider, filter); 67 } else { 68 auto divider = JsonUtil::Create(true); 69 json->PutExtAttr("divider", divider, filter); 70 } 71 } 72 UpdateListLanes(std::optional<int32_t> lanes,std::optional<Dimension> minLength,std::optional<Dimension> maxLength)73 void UpdateListLanes(std::optional<int32_t> lanes, 74 std::optional<Dimension> minLength, std::optional<Dimension> maxLength) 75 { 76 listLanes_ = lanes; 77 listLaneMinLength_ = minLength; 78 listLaneMaxLength_ = maxLength; 79 } 80 IsListLanesEqual(std::optional<int32_t> lanes,std::optional<Dimension> minLength,std::optional<Dimension> maxLength)81 bool IsListLanesEqual(std::optional<int32_t> lanes, 82 std::optional<Dimension> minLength, std::optional<Dimension> maxLength) const 83 { 84 return (listLanes_ == lanes) && (listLaneMinLength_ == minLength) && (listLaneMaxLength_ == maxLength); 85 } 86 87 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Space, Dimension, PROPERTY_UPDATE_MEASURE); 88 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Divider, V2::ItemDivider, PROPERTY_UPDATE_MEASURE); 89 90 private: 91 std::optional<int32_t> listLanes_; 92 std::optional<Dimension> listLaneMinLength_; 93 std::optional<Dimension> listLaneMaxLength_; 94 }; 95 } // namespace OHOS::Ace::NG 96 97 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LAYOUT_PROPERTY_H 98