• 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LINEAR_LAYOUT_LINEAR_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LINEAR_LAYOUT_LINEAR_LAYOUT_PROPERTY_H
18 
19 #include "base/geometry/dimension.h"
20 #include "core/components/common/layout/constants.h"
21 #include "core/components_ng/layout/layout_property.h"
22 #include "core/components_ng/pattern/flex/flex_layout_property.h"
23 #include "core/components_ng/property/flex_property.h"
24 #include "core/components_ng/property/property.h"
25 #include "core/components_v2/inspector/utils.h"
26 
27 namespace OHOS::Ace::NG {
28 class ACE_EXPORT LinearLayoutProperty : public FlexLayoutProperty {
29     DECLARE_ACE_TYPE(LinearLayoutProperty, FlexLayoutProperty);
30 
31 public:
LinearLayoutProperty(bool isVertical)32     explicit LinearLayoutProperty(bool isVertical) : isVertical_(isVertical)
33     {
34         UpdateFlexDirection(isVertical_ ? FlexDirection::COLUMN : FlexDirection::ROW);
35     }
36 
37     ~LinearLayoutProperty() override = default;
38 
Clone()39     RefPtr<LayoutProperty> Clone() const override
40     {
41         auto value = MakeRefPtr<LinearLayoutProperty>(isVertical_);
42         Clone(value);
43         return value;
44     }
45 
Reset()46     void Reset() override
47     {
48         FlexLayoutProperty::Reset();
49         isVertical_ = false;
50     }
51 
IsVertical()52     bool IsVertical() const
53     {
54         return isVertical_;
55     }
56 
ToJsonValue(std::unique_ptr<JsonValue> & json)57     void ToJsonValue(std::unique_ptr<JsonValue>& json) const override
58     {
59         LayoutProperty::ToJsonValue(json);
60         std::string alignItems;
61         auto flexAlignItems = GetCrossAxisAlign().value_or(FlexAlign::CENTER);
62         if (isVertical_) {
63             alignItems = "HorizontalAlign::Center";
64             if (flexAlignItems == FlexAlign::FLEX_START) {
65                 alignItems = "HorizontalAlign.Start";
66             } else if (flexAlignItems == FlexAlign::CENTER) {
67                 alignItems = "HorizontalAlign.Center";
68             } else if (flexAlignItems == FlexAlign::FLEX_END) {
69                 alignItems = "HorizontalAlign.End";
70             }
71         } else {
72             alignItems = "VerticalAlign.Center";
73             if (flexAlignItems == FlexAlign::FLEX_START) {
74                 alignItems = "VerticalAlign.Top";
75             } else if (flexAlignItems == FlexAlign::CENTER) {
76                 alignItems = "VerticalAlign.Center";
77             } else if (flexAlignItems == FlexAlign::FLEX_END) {
78                 alignItems = "VerticalAlign.Bottom";
79             }
80         }
81         json->Put("alignItems", alignItems.c_str());
82         auto justifyContent = V2::ConvertFlexAlignToStirng(GetMainAxisAlign().value_or(FlexAlign::FLEX_START));
83         json->Put("justifyContent", justifyContent.c_str());
84     }
85 
86 protected:
Clone(RefPtr<LayoutProperty> property)87     void Clone(RefPtr<LayoutProperty> property) const override
88     {
89         auto value = DynamicCast<LinearLayoutProperty>(property);
90         FlexLayoutProperty::Clone(value);
91         value->isVertical_ = isVertical_;
92     }
93 
94 private:
95     // This will call after ModifyLayoutConstraint.
96     bool isVertical_ = false;
97 
98     ACE_DISALLOW_COPY_AND_MOVE(LinearLayoutProperty);
99 };
100 } // namespace OHOS::Ace::NG
101 
102 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_LAYOUTS_LAYOUT_PROPERTY_H
103