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_TEXTTIMER_RENDER_TEXTTIMER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXTTIMER_RENDER_TEXTTIMER_H
18 
19 #include <functional>
20 
21 #include "base/utils/system_properties.h"
22 #include "core/components/text/render_text.h"
23 #include "core/pipeline/base/render_node.h"
24 
25 namespace OHOS::Ace {
26 class RenderTextTimer : public RenderNode {
27     DECLARE_ACE_TYPE(RenderTextTimer, RenderNode)
28 
29 public:
30     RenderTextTimer();
31     ~RenderTextTimer() override;
32 
33     static RefPtr<RenderNode> Create();
34     void Update(const RefPtr<Component>& component) override;
35     void PerformLayout() override;
36     void Tick(uint64_t duration);
37     void UpdateValue(uint32_t elapsedTime);
GetIsCountDown()38     bool GetIsCountDown() const
39     {
40         return isCountDown_;
41     }
GetCount()42     double GetCount() const
43     {
44         return inputCount_;
45     }
GetFormat()46     std::string GetFormat() const
47     {
48         return format_;
49     }
GetTextStyle()50     TextStyle GetTextStyle() const
51     {
52         if (textComponent_) {
53             return textComponent_->GetTextStyle();
54         }
55         return TextStyle();
56     }
57 
58 protected:
59     uint64_t elapsedTime_ = 0; // millisecond.
60     double inputCount_ = 0.0;
61     bool isCountDown_ = false;
62     std::string format_;
63     std::function<void(int64_t, int64_t)> onTimer_;
64 
65 private:
66     void HandleStart();
67     void HandlePause();
68     void HandleReset();
69 
70     Size realSize_;
71     RefPtr<TextComponent> textComponent_;
72     RefPtr<RenderText> renderText_;
73     RefPtr<Scheduler> scheduler_;
74 };
75 } // namespace OHOS::Ace
76 
77 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_OVERLAY_RENDER_TEXT_OVERLAY_H
78