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_STACK_STACK_LAYOUT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_STACK_STACK_LAYOUT_PROPERTY_H 18 19 #include "core/components_ng/layout/layout_property.h" 20 21 namespace OHOS::Ace::NG { 22 class ACE_EXPORT StackLayoutProperty : public LayoutProperty { 23 DECLARE_ACE_TYPE(StackLayoutProperty, LayoutProperty); 24 25 public: 26 StackLayoutProperty() = default; 27 28 ~StackLayoutProperty() override = default; 29 Clone()30 RefPtr<LayoutProperty> Clone() const override 31 { 32 auto layoutProperty = MakeRefPtr<StackLayoutProperty>(); 33 layoutProperty->UpdateLayoutProperty(this); 34 return layoutProperty; 35 } 36 Reset()37 void Reset() override 38 { 39 LayoutProperty::Reset(); 40 } 41 ToJsonValue(std::unique_ptr<JsonValue> & json)42 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override 43 { 44 LayoutProperty::ToJsonValue(json); 45 auto align = Alignment::CENTER; 46 if (GetPositionProperty()) { 47 align = GetPositionProperty()->GetAlignment().value_or(Alignment::CENTER); 48 } 49 json->Put("alignContent", align.GetAlignmentStr(TextDirection::LTR).c_str()); 50 } 51 FromJson(const std::unique_ptr<JsonValue> & json)52 void FromJson(const std::unique_ptr<JsonValue>& json) override 53 { 54 UpdateAlignment(Alignment::GetAlignment(TextDirection::LTR, json->GetString("alignContent"))); 55 LayoutProperty::FromJson(json); 56 } 57 58 private: 59 ACE_DISALLOW_COPY_AND_MOVE(StackLayoutProperty); 60 }; 61 } // namespace OHOS::Ace::NG 62 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_STACK_STACK_LAYOUT_PROPERTY_H 63