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 #include "bridge/declarative_frontend/jsview/models/text_timer_model_impl.h" 17 18 #include <cstddef> 19 20 #include "base/utils/utils.h" 21 #include "bridge/declarative_frontend/view_stack_processor.h" 22 23 namespace OHOS::Ace::Framework { Create()24RefPtr<TextTimerController> TextTimerModelImpl::Create() 25 { 26 auto timerComponent = AceType::MakeRefPtr<TextTimerComponent>(); 27 CHECK_NULL_RETURN(timerComponent, nullptr); 28 ViewStackProcessor::GetInstance()->Push(timerComponent); 29 return timerComponent->GetTextTimerController(); 30 } 31 SetIsCountDown(bool isCountDown)32void TextTimerModelImpl::SetIsCountDown(bool isCountDown) 33 { 34 auto component = GetComponent(); 35 CHECK_NULL_VOID(component); 36 component->SetIsCountDown(isCountDown); 37 } 38 SetInputCount(double count)39void TextTimerModelImpl::SetInputCount(double count) 40 { 41 auto component = GetComponent(); 42 CHECK_NULL_VOID(component); 43 component->SetInputCount(count); 44 } 45 SetFormat(const std::string & format)46void TextTimerModelImpl::SetFormat(const std::string& format) 47 { 48 auto component = GetComponent(); 49 CHECK_NULL_VOID(component); 50 component->SetFormat(format); 51 } 52 SetOnTimer(std::function<void (int64_t,int64_t)> && onChange)53void TextTimerModelImpl::SetOnTimer(std::function<void(int64_t, int64_t)> && onChange) 54 { 55 auto component = GetComponent(); 56 CHECK_NULL_VOID(component); 57 component->SetOnTimer(std::move(onChange)); 58 } 59 SetFontSize(const Dimension & value)60void TextTimerModelImpl::SetFontSize(const Dimension& value) 61 { 62 auto component = GetComponent(); 63 CHECK_NULL_VOID(component); 64 65 auto textStyle = component->GetTextStyle(); 66 textStyle.SetFontSize(value); 67 component->SetTextStyle(textStyle); 68 } 69 SetTextColor(const Color & value)70void TextTimerModelImpl::SetTextColor(const Color& value) 71 { 72 auto component = GetComponent(); 73 CHECK_NULL_VOID(component); 74 75 auto textStyle = component->GetTextStyle(); 76 textStyle.SetTextColor(value); 77 component->SetTextStyle(textStyle); 78 } 79 SetItalicFontStyle(Ace::FontStyle value)80void TextTimerModelImpl::SetItalicFontStyle(Ace::FontStyle value) 81 { 82 auto component = GetComponent(); 83 CHECK_NULL_VOID(component); 84 85 auto textStyle = component->GetTextStyle(); 86 textStyle.SetFontStyle(value); 87 component->SetTextStyle(textStyle); 88 } 89 SetFontWeight(FontWeight value)90void TextTimerModelImpl::SetFontWeight(FontWeight value) 91 { 92 auto component = GetComponent(); 93 CHECK_NULL_VOID(component); 94 95 auto textStyle = component->GetTextStyle(); 96 textStyle.SetFontWeight(value); 97 component->SetTextStyle(textStyle); 98 } 99 SetFontFamily(const std::vector<std::string> & value)100void TextTimerModelImpl::SetFontFamily(const std::vector<std::string>& value) 101 { 102 auto component = GetComponent(); 103 CHECK_NULL_VOID(component); 104 105 auto textStyle = component->GetTextStyle(); 106 textStyle.SetFontFamilies(value); 107 component->SetTextStyle(textStyle); 108 } 109 GetComponent()110RefPtr<TextTimerComponent> TextTimerModelImpl::GetComponent() 111 { 112 auto* stack = ViewStackProcessor::GetInstance(); 113 if (!stack) { 114 return nullptr; 115 } 116 auto component = AceType::DynamicCast<TextTimerComponent>(stack->GetMainComponent()); 117 return component; 118 } 119 } // namespace OHOS::Ace::Framework