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_PROGRESS_PROGRESS_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_PROGRESS_COMPONENT_H 18 19 #include "core/components/common/properties/progress_data.h" 20 #include "core/components/progress/progress_theme.h" 21 #include "core/components/track/track_component.h" 22 #include "core/pipeline/base/render_component.h" 23 24 namespace OHOS::Ace { 25 26 enum class ProgressType { 27 LINEAR = 1, 28 RING = 2, 29 SCALE = 3, 30 CIRCLE = 4, 31 GAUGE = 5, 32 ARC = 6, 33 MOON = 7, 34 BUBBLE = 8, 35 CAPSULE = 9, 36 }; 37 38 class ACE_EXPORT ProgressComponent : public RenderComponent { 39 DECLARE_ACE_TYPE(ProgressComponent, RenderComponent); 40 41 public: 42 ProgressComponent(double min, double value, double cachedValue, double max, ProgressType type); 43 ~ProgressComponent() override = default; 44 45 RefPtr<Element> CreateElement() override; 46 RefPtr<RenderNode> CreateRenderNode() override; 47 48 void InitStyle(const RefPtr<ProgressTheme>& theme); 49 GetTrack()50 RefPtr<TrackComponent> GetTrack() const 51 { 52 return track_; 53 } 54 SetTrack(const RefPtr<TrackComponent> & track)55 void SetTrack(const RefPtr<TrackComponent>& track) 56 { 57 track_ = track; 58 } 59 SetValue(double value)60 void SetValue(double value) 61 { 62 data_.SetValue(value); 63 } 64 GetValue()65 double GetValue() const 66 { 67 return data_.GetValue(); 68 } 69 SetCachedValue(double cachedValue)70 void SetCachedValue(double cachedValue) 71 { 72 data_.SetCachedValue(cachedValue); 73 } 74 GetCachedValue()75 double GetCachedValue() const 76 { 77 return data_.GetCachedValue(); 78 } 79 SetMaxValue(double max)80 void SetMaxValue(double max) 81 { 82 data_.SetMaxValue(max); 83 } 84 GetMaxValue()85 double GetMaxValue() const 86 { 87 return data_.GetMaxValue(); 88 } 89 SetMinValue(double min)90 void SetMinValue(double min) 91 { 92 data_.SetMinValue(min); 93 } 94 GetMinValue()95 double GetMinValue() const 96 { 97 return data_.GetMinValue(); 98 } 99 GetType()100 ProgressType GetType() const 101 { 102 return type_; 103 } 104 SetAnimationPlay(bool playAnimation)105 void SetAnimationPlay(bool playAnimation) 106 { 107 playAnimation_ = playAnimation; 108 } 109 GetAnimationPlay()110 bool GetAnimationPlay() const 111 { 112 return playAnimation_; 113 } 114 GetSelectColor()115 const Color& GetSelectColor() const 116 { 117 return track_->GetSelectColor(); 118 } 119 SetSelectColor(const Color & color)120 void SetSelectColor(const Color& color) 121 { 122 return track_->SetSelectColor(color); 123 } 124 GetTrackThickness()125 const Dimension& GetTrackThickness() const 126 { 127 return track_->GetTrackThickness(); 128 } 129 SetTrackThickness(const Dimension & thickness)130 void SetTrackThickness(const Dimension& thickness) 131 { 132 return track_->SetTrackThickness(thickness); 133 } 134 GetScaleNumber()135 int32_t GetScaleNumber() const 136 { 137 return track_->GetScaleNumber(); 138 } 139 SetScaleNumber(int32_t number)140 void SetScaleNumber(int32_t number) 141 { 142 return track_->SetScaleNumber(number); 143 } 144 GetScaleWidth()145 const Dimension& GetScaleWidth() const 146 { 147 return track_->GetScaleWidth(); 148 } 149 SetScaleWidth(const Dimension & width)150 void SetScaleWidth(const Dimension& width) 151 { 152 return track_->SetScaleWidth(width); 153 } 154 SetLabelMarkedText(const std::string markedValue)155 void SetLabelMarkedText(const std::string markedValue) 156 { 157 track_->SetLabelMarkedText(markedValue); 158 } 159 SetMarkedTextColor(const Color & color)160 void SetMarkedTextColor(const Color& color) 161 { 162 track_->SetLabelMarkedColor(color); 163 } 164 SetIndicatorFlag(bool flag)165 void SetIndicatorFlag(bool flag) 166 { 167 track_->SetIndicatorFlag(flag); 168 } 169 SetSectionsStyle(const std::vector<Color> & colors,const std::vector<double> & weights)170 void SetSectionsStyle(const std::vector<Color>& colors, const std::vector<double>& weights) 171 { 172 track_->SetSectionsStyle(colors, weights); 173 } 174 175 private: 176 ProgressData data_; 177 RefPtr<TrackComponent> track_; 178 ProgressType type_ = ProgressType::LINEAR; 179 bool playAnimation_ = false; 180 }; 181 182 } // namespace OHOS::Ace 183 184 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_PROGRESS_COMPONENT_H 185