1 /* 2 * Copyright (c) 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_DECLARATION_TEXTTIMER_TEXTTIMER_DECLARATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_TEXTTIMER_TEXTTIMER_DECLARATION_H 18 19 #include "core/components/common/properties/text_style.h" 20 #include "core/components/declaration/common/declaration.h" 21 #include "core/components/text/text_component.h" 22 #include "core/components/texttimer/texttimer_controller.h" 23 24 namespace OHOS::Ace { 25 26 inline constexpr double TIME_DEFAULT_COUNT = 60000.0; 27 inline const char DEFAULT_FORMAT[] = "HH:mm:ss.S"; 28 29 struct TextTimerAttribute : Attribute { 30 double inputCount = TIME_DEFAULT_COUNT; 31 bool isCountDown_ = false; 32 std::string format_ = DEFAULT_FORMAT; 33 }; 34 35 struct TextTimerStyle : Style { 36 TextStyle textStyle; 37 }; 38 39 struct TextTimerEvent : Event {}; 40 41 struct TextTimerMethod : Method {}; 42 43 class TextTimerDeclaration : public Declaration { 44 DECLARE_ACE_TYPE(TextTimerDeclaration, Declaration); 45 46 public: 47 TextTimerDeclaration(); 48 ~TextTimerDeclaration() override = default; 49 GetTextTimerController()50 const RefPtr<TextTimerController>& GetTextTimerController() const 51 { 52 return textTimerController_; 53 } 54 GetInputCount()55 double GetInputCount() const 56 { 57 auto& attribute = static_cast<TextTimerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 58 return attribute.inputCount; 59 } 60 SetInputCount(double value)61 void SetInputCount(double value) 62 { 63 auto& attribute = MaybeResetAttribute<TextTimerAttribute>(AttributeTag::SPECIALIZED_ATTR); 64 attribute.inputCount = value; 65 } 66 GetIsCountDown()67 bool GetIsCountDown() const 68 { 69 auto& attribute = static_cast<TextTimerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 70 return attribute.isCountDown_; 71 } 72 SetIsCountDown(bool value)73 void SetIsCountDown(bool value) 74 { 75 auto& attribute = MaybeResetAttribute<TextTimerAttribute>(AttributeTag::SPECIALIZED_ATTR); 76 attribute.isCountDown_ = value; 77 } 78 GetFormat()79 const std::string& GetFormat() const 80 { 81 auto& attribute = static_cast<TextTimerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR)); 82 return attribute.format_; 83 } 84 SetFormat(const std::string & value)85 void SetFormat(const std::string& value) 86 { 87 auto& attribute = MaybeResetAttribute<TextTimerAttribute>(AttributeTag::SPECIALIZED_ATTR); 88 attribute.format_ = value; 89 } 90 SetTextStyle(const TextStyle & textstyle)91 void SetTextStyle(const TextStyle& textstyle) 92 { 93 auto& style = MaybeResetStyle<TextTimerStyle>(StyleTag::SPECIALIZED_STYLE); 94 style.textStyle = textstyle; 95 } 96 GetTextStyle()97 const TextStyle& GetTextStyle() const 98 { 99 auto& style = static_cast<TextTimerStyle&>(GetStyle(StyleTag::SPECIALIZED_STYLE)); 100 return style.textStyle; 101 } 102 103 protected: 104 void InitSpecialized() override; 105 106 private: 107 RefPtr<TextTimerController> textTimerController_; 108 }; 109 } // namespace OHOS::Ace 110 111 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_TEXTTIMER_TEXTTIMER_DECLARATION_H 112