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_PATTERNS_STEPPER_STEPPER_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_STEPPER_STEPPER_NODE_H 18 19 #include "core/components_ng/base/group_node.h" 20 #include "core/components_ng/pattern/stepper/stepper_pattern.h" 21 22 namespace OHOS::Ace::NG { 23 24 class ACE_EXPORT StepperNode : public GroupNode { 25 DECLARE_ACE_TYPE(StepperNode, GroupNode); 26 27 public: 28 StepperNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern, bool isRoot = false) 29 : GroupNode(tag, nodeId, pattern, isRoot) 30 {} 31 ~StepperNode() override = default; 32 33 static RefPtr<StepperNode> GetOrCreateStepperNode( 34 const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator); 35 36 void AddChildToGroup(const RefPtr<UINode>& child, int32_t slot = DEFAULT_NODE_SLOT) override; 37 void DeleteChildFromGroup(int32_t slot = DEFAULT_NODE_SLOT) override; 38 HasSwiperNode()39 bool HasSwiperNode() const 40 { 41 return swiperId_.has_value(); 42 } 43 HasLeftButtonNode()44 bool HasLeftButtonNode() const 45 { 46 return leftButtonId_.has_value(); 47 } 48 HasRightButtonNode()49 bool HasRightButtonNode() const 50 { 51 return rightButtonId_.has_value(); 52 } 53 GetSwiperId()54 int32_t GetSwiperId() 55 { 56 if (!swiperId_.has_value()) { 57 swiperId_ = ElementRegister::GetInstance()->MakeUniqueId(); 58 } 59 return swiperId_.value(); 60 } 61 GetLeftButtonId()62 int32_t GetLeftButtonId() 63 { 64 if (!leftButtonId_.has_value()) { 65 leftButtonId_ = ElementRegister::GetInstance()->MakeUniqueId(); 66 } 67 return leftButtonId_.value(); 68 } 69 GetRightButtonId()70 int32_t GetRightButtonId() 71 { 72 if (!rightButtonId_.has_value()) { 73 rightButtonId_ = ElementRegister::GetInstance()->MakeUniqueId(); 74 } 75 return rightButtonId_.value(); 76 } 77 RemoveLeftButtonNode()78 void RemoveLeftButtonNode() 79 { 80 CHECK_NULL_VOID(HasLeftButtonNode()); 81 RemoveChildAtIndex(GetChildIndexById(GetLeftButtonId())); 82 leftButtonId_ = std::nullopt; 83 } 84 RemoveRightButtonNode()85 void RemoveRightButtonNode() 86 { 87 CHECK_NULL_VOID(HasRightButtonNode()); 88 RemoveChildAtIndex(GetChildIndexById(GetRightButtonId())); 89 rightButtonId_ = std::nullopt; 90 } 91 92 private: 93 std::optional<int32_t> swiperId_; 94 std::optional<int32_t> leftButtonId_; 95 std::optional<int32_t> rightButtonId_; 96 ACE_DISALLOW_COPY_AND_MOVE(StepperNode); 97 }; 98 99 } // namespace OHOS::Ace::NG 100 101 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_STEPPER_STEPPER_NODE_H 102