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_STEPPER_STEPPER_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_STEPPER_STEPPER_LAYOUT_PROPERTY_H
18 
19 #include <string>
20 #include "core/components_ng/base/inspector_filter.h"
21 #include "core/components_ng/layout/layout_property.h"
22 
23 namespace OHOS::Ace::NG {
24 
25 class ACE_EXPORT StepperLayoutProperty : public LayoutProperty {
26     DECLARE_ACE_TYPE(StepperLayoutProperty, LayoutProperty);
27 
28 public:
29     StepperLayoutProperty() = default;
30     ~StepperLayoutProperty() override = default;
31 
Clone()32     RefPtr<LayoutProperty> Clone() const override
33     {
34         auto value = MakeRefPtr<StepperLayoutProperty>();
35         value->LayoutProperty::UpdateLayoutProperty(AceType::DynamicCast<LayoutProperty>(this));
36         value->propIndex_ = CloneIndex();
37         return value;
38     }
39 
Reset()40     void Reset() override
41     {
42         LayoutProperty::Reset();
43         ResetIndex();
44     }
45 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)46     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
47     {
48         LayoutProperty::ToJsonValue(json, filter);
49         /* no fixed attr below, just return */
50         if (filter.IsFastFilter()) {
51             return;
52         }
53         json->PutExtAttr("index", std::to_string(GetIndex().value_or(0)).c_str(), filter);
54     }
55 
UpdateIndexWithoutMeasure(int32_t index)56     void UpdateIndexWithoutMeasure(int32_t index)
57     {
58         if (propIndex_ != index) {
59             propIndex_ = index;
60         }
61     }
62 
63     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Index, uint32_t, PROPERTY_UPDATE_LAYOUT);
64 private:
65     ACE_DISALLOW_COPY_AND_MOVE(StepperLayoutProperty);
66 };
67 
68 } // namespace OHOS::Ace::NG
69 
70 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_STEPPER_STEPPER_LAYOUT_PROPERTY_H
71