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_ANIMATION_SELECT_MOTION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SELECT_MOTION_H 18 #include "core/animation/motion.h" 19 20 namespace OHOS::Ace { 21 using CompleteCallbck = std::function<bool()>; 22 // scroll by offset on each frame before complete 23 class ACE_EXPORT SelectMotion : public Motion { 24 DECLARE_ACE_TYPE(SelectMotion, Motion); 25 26 public: SelectMotion(float offset,CompleteCallbck && complete)27 SelectMotion(float offset, CompleteCallbck&& complete) : offset_(offset), complete_(complete) {}; GetCurrentPosition()28 double GetCurrentPosition() override 29 { 30 return offset_; 31 }; GetCurrentVelocity()32 double GetCurrentVelocity() override 33 { 34 return 0.0f; 35 }; IsCompleted()36 bool IsCompleted() override 37 { 38 if (complete_) { 39 return complete_(); 40 } 41 return true; 42 }; 43 GetMotionType()44 std::string GetMotionType() const override 45 { 46 return "select"; 47 } 48 49 // Each subclass should override this method to perform motion in each timestamp. Move(float offsetTime)50 void Move(float offsetTime) override {}; 51 Reset(float offset)52 void Reset(float offset) 53 { 54 offset_ = offset; 55 } 56 57 private: 58 float offset_ = 0.0f; 59 CompleteCallbck complete_; 60 }; 61 } // namespace OHOS::Ace 62 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_SELECT_MOTION_H