1 /* 2 * Copyright (c) 2021 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_BASE_PROPERTIES_PROGRESS_DATA_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_PROGRESS_DATA_H 18 19 #include "base/memory/ace_type.h" 20 21 namespace OHOS::Ace { 22 23 class ProgressData : public AceType { 24 DECLARE_ACE_TYPE(ProgressData, AceType); 25 26 public: 27 ProgressData() = default; 28 ~ProgressData() override = default; 29 SetMinValue(double minValue)30 void SetMinValue(double minValue) 31 { 32 minValue_ = minValue; 33 } 34 SetMaxValue(double maxValue)35 void SetMaxValue(double maxValue) 36 { 37 maxValue_ = maxValue; 38 } 39 SetValue(double value)40 void SetValue(double value) 41 { 42 value_ = value; 43 } 44 SetStepValue(double stepValue)45 void SetStepValue(double stepValue) 46 { 47 stepValue_ = stepValue; 48 } 49 SetCachedValue(double cachedValue)50 void SetCachedValue(double cachedValue) 51 { 52 cachedValue_ = cachedValue; 53 } 54 55 // Change the value by the number of step. Positive number will move forwards and negative number will move 56 // backwards. MoveSteps(int32_t num)57 double MoveSteps(int32_t num) 58 { 59 double temp = value_ + (stepValue_ * num); 60 if (temp < minValue_) { 61 value_ = minValue_; 62 } else if (temp > maxValue_) { 63 value_ = maxValue_; 64 } else { 65 value_ = temp; 66 } 67 return value_; 68 } 69 GetMinValue()70 double GetMinValue() const 71 { 72 return minValue_; 73 } 74 GetMaxValue()75 double GetMaxValue() const 76 { 77 return maxValue_; 78 } 79 GetValue()80 double GetValue() const 81 { 82 return value_; 83 } 84 GetStepValue()85 double GetStepValue() const 86 { 87 return stepValue_; 88 } 89 GetCachedValue()90 double GetCachedValue() const 91 { 92 return cachedValue_; 93 } 94 95 private: 96 double minValue_ { 0.0 }; 97 double maxValue_ { 1.0 }; 98 double value_ { 0.0 }; 99 double stepValue_ { 0.01 }; 100 double cachedValue_ { 0.0 }; 101 }; 102 103 } // namespace OHOS::Ace 104 105 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_PROGRESS_DATA_H 106