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