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_BRIDGE_COMMON_DOM_DOM_PROGRESS_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_PROGRESS_H 18 19 #include <vector> 20 21 #include "core/components/progress/bubble_progress_component.h" 22 #include "core/components/progress/loading_progress_component.h" 23 #include "core/components/progress/progress_component.h" 24 #include "frameworks/bridge/common/dom/dom_node.h" 25 26 namespace OHOS::Ace::Framework { 27 28 class DOMProgress final : public DOMNode { 29 DECLARE_ACE_TYPE(DOMProgress, DOMNode); 30 31 public: 32 DOMProgress(NodeId nodeId, const std::string& nodeName); 33 ~DOMProgress() override = default; 34 35 static RefPtr<ProgressComponent> CreateProgressComponent( 36 double min, double percent, double cachedValue, double max, ProgressType type); 37 38 RefPtr<Component> GetSpecializedComponent() override; 39 40 protected: 41 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 42 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 43 void OnSetStyleFinished() override; 44 void PrepareSpecializedComponent() override; 45 46 private: 47 void InitProgressIfNeed(); 48 49 double cachedValue_ = 0.0; 50 double min_ = 0.0; 51 double max_ = 100.0; 52 double percent_ = 0.0; 53 54 bool clockwiseDirection_ = true; 55 bool showAnimationEffect_ = true; 56 57 // All the magic numbers below are followed UX requirement. 58 std::pair<Color, bool> color_ { Color(), false }; 59 60 Gradient gradient_; 61 std::pair<Color, bool> cachedColor_ { Color(), false }; 62 std::pair<Color, bool> backgroundColor_ { Color(), false }; 63 std::pair<Dimension, bool> strokeWidth_ = { 32.0_px, false }; 64 std::pair<Dimension, bool> scaleWidth_ = { 2.0_vp, false }; 65 std::pair<int32_t, bool> scaleNumber_ = { 120, false }; 66 67 std::pair<double, bool> radius_ = { -1.0, false }; 68 std::pair<double, bool> centerX_ = { -1.0, false }; 69 std::pair<double, bool> centerY_ = { -1.0, false }; 70 71 double startDegree_ = -120.0; 72 double sweepDegree_ = 240.0; 73 bool isStartToEnd_ = true; 74 75 Dimension diameter_; 76 Dimension bubbleRadius_; 77 78 std::vector<Color> colors_; 79 std::vector<double> weights_; 80 81 ProgressType type_ = ProgressType::LINEAR; 82 83 RefPtr<ProgressComponent> progressChild_; 84 RefPtr<BubbleProgressComponent> bubbleProgressChild_; 85 RefPtr<LoadingProgressComponent> loadingProgressChild_; 86 }; 87 88 } // namespace OHOS::Ace::Framework 89 90 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_PROGRESS_H 91