1 /*
2  * Copyright (c) 2021-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_PROGRESS_RENDER_PROGRESS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_RENDER_PROGRESS_H
18 
19 #include "core/components/progress/progress_component.h"
20 #include "core/pipeline/base/component.h"
21 #include "core/pipeline/base/render_node.h"
22 
23 namespace OHOS::Ace {
24 
25 constexpr double PROGRESS_DEFAULT_VALUE = 0.0;
26 constexpr double PROGRESS_DEFAULT_MAX = 1.0;
27 constexpr double PROGRESS_DEFAULT_MIN = 0.0;
28 constexpr double PROGRESS_DEFAULT_CACHED_VALUE = 0.0;
29 
30 class RenderProgress : public RenderNode {
31     DECLARE_ACE_TYPE(RenderProgress, RenderNode);
32 
33 public:
34     static RefPtr<RenderNode> Create();
35     void Update(const RefPtr<Component>& component) override;
36     void PerformLayout() override;
37     void OnPaintFinish() override;
38 
GetErrorBit()39     bool GetErrorBit() const
40     {
41         return isError_;
42     }
GetMaxValue()43     double GetMaxValue() const
44     {
45         return max_;
46     }
GetMinValue()47     double GetMinValue() const
48     {
49         return min_;
50     }
GetValue()51     double GetValue() const
52     {
53         return value_;
54     }
GetProgressType()55     ProgressType GetProgressType() const
56     {
57         return type_;
58     }
GetProgressComponent()59     RefPtr<ProgressComponent> GetProgressComponent() const
60     {
61         return component_;
62     }
63 
64 protected:
65     Size Measure();
66     // TRACK length
67     double totalRatio_ = 0.0;
68     double cachedRatio_ = 0.0;
69     double trackThickness_ = 0.0;
70 
71     // vp to logical pixel
72     double scale_ = 0.0;
73     ProgressType type_ = ProgressType::LINEAR;
74 
75 private:
76     void UpdateAccessibilityAttr();
77 
78     RefPtr<ProgressComponent> component_;
79     double value_ = PROGRESS_DEFAULT_VALUE;
80     double max_ = PROGRESS_DEFAULT_MAX;
81     double min_ = PROGRESS_DEFAULT_MIN;
82     double cachedValue_ = PROGRESS_DEFAULT_CACHED_VALUE;
83 
84     bool isError_ = false;
85 };
86 
87 } // namespace OHOS::Ace
88 
89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_RENDER_PROGRESS_H
90