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_TEXT_CLOCK_TEXT_CLOCK_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_CLOCK_TEXT_CLOCK_COMPONENT_H 18 19 #include <float.h> 20 #include "base/resource/internal_resource.h" 21 #include "base/utils/utils.h" 22 #include "core/components_v2/common/common_def.h" 23 #include "core/components/text/text_component_v2.h" 24 #include "core/components/text_clock/text_clock_controller.h" 25 #include "core/pipeline/base/constants.h" 26 #include "core/pipeline/base/element.h" 27 28 namespace OHOS::Ace { 29 30 const std::string DEFAULT_FORMAT = "hms"; 31 class ACE_EXPORT TextClockComponent : public TextComponentV2 { 32 DECLARE_ACE_TYPE(TextClockComponent, TextComponentV2); 33 34 public: TextClockComponent(const std::string & data)35 explicit TextClockComponent(const std::string& data) : TextComponentV2(data) {} 36 ~TextClockComponent() override = default; 37 38 RefPtr<RenderNode> CreateRenderNode() override; 39 RefPtr<Element> CreateElement() override; 40 41 void SetHoursWest(int32_t hoursWest); 42 int32_t GetHoursWest() const; 43 44 void SetFormat(const std::string& format); 45 std::string GetFormat() const; 46 47 void SetTextClockController(RefPtr<TextClockController> textClockController); 48 49 RefPtr<TextClockController> GetTextClockController() const; 50 ACE_DEFINE_COMPONENT_EVENT(OnDateChange, void(const std::string)); 51 52 private: 53 std::string format_ = DEFAULT_FORMAT; 54 int32_t hoursWest_ = INT_MAX; 55 RefPtr<TextClockController> textClockController_; 56 }; 57 } // namespace OHOS::Ace 58 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_CLOCK_TEXT_CLOCK_COMPONENT_H 59