• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/marquee_model_impl.h"
17 
18 #include "base/utils/utils.h"
19 #include "bridge/declarative_frontend/view_stack_processor.h"
20 
21 namespace OHOS::Ace::Framework {
Create()22 void MarqueeModelImpl::Create()
23 {
24     auto marqueeComponent = AceType::MakeRefPtr<MarqueeComponent>();
25     CHECK_NULL_VOID(marqueeComponent);
26     ViewStackProcessor::GetInstance()->ClaimElementId(marqueeComponent);
27     ViewStackProcessor::GetInstance()->Push(marqueeComponent);
28 }
29 
SetValue(const std::string & value)30 void MarqueeModelImpl::SetValue(const std::string& value)
31 {
32     auto component = GetComponent();
33     CHECK_NULL_VOID(component);
34     component->SetValue(value);
35 }
36 
SetPlayerStatus(bool playerStatus)37 void MarqueeModelImpl::SetPlayerStatus(bool playerStatus)
38 {
39     auto component = GetComponent();
40     CHECK_NULL_VOID(component);
41     component->SetPlayerStatus(playerStatus);
42 }
43 
SetScrollAmount(double scrollAmount)44 void MarqueeModelImpl::SetScrollAmount(double scrollAmount)
45 {
46     auto component = GetComponent();
47     CHECK_NULL_VOID(component);
48     component->SetScrollAmount(scrollAmount);
49 }
50 
SetLoop(int32_t loop)51 void MarqueeModelImpl::SetLoop(int32_t loop)
52 {
53     auto component = GetComponent();
54     CHECK_NULL_VOID(component);
55     component->SetLoop(loop);
56 }
57 
SetDirection(MarqueeDirection direction)58 void MarqueeModelImpl::SetDirection(MarqueeDirection direction)
59 {
60     auto component = GetComponent();
61     CHECK_NULL_VOID(component);
62     component->SetDirection(direction);
63 }
64 
SetTextColor(const Color & textColor)65 void MarqueeModelImpl::SetTextColor(const Color& textColor)
66 {
67     auto component = GetComponent();
68     CHECK_NULL_VOID(component);
69     auto textStyle = component->GetTextStyle();
70     textStyle.SetTextColor(textColor);
71     component->SetTextStyle(textStyle);
72 }
73 
SetFontSize(const Dimension & fontSize)74 void MarqueeModelImpl::SetFontSize(const Dimension& fontSize)
75 {
76     auto component = GetComponent();
77     CHECK_NULL_VOID(component);
78     auto textStyle = component->GetTextStyle();
79     textStyle.SetFontSize(fontSize);
80     component->SetTextStyle(textStyle);
81 }
82 
SetFontWeight(const FontWeight & fontWeight)83 void MarqueeModelImpl::SetFontWeight(const FontWeight& fontWeight)
84 {
85     auto component = GetComponent();
86     CHECK_NULL_VOID(component);
87     auto textStyle = component->GetTextStyle();
88     textStyle.SetFontWeight(fontWeight);
89     component->SetTextStyle(textStyle);
90 }
91 
SetFontFamily(const std::vector<std::string> & fontFamilies)92 void MarqueeModelImpl::SetFontFamily(const std::vector<std::string>& fontFamilies)
93 {
94     auto component = GetComponent();
95     CHECK_NULL_VOID(component);
96     auto textStyle = component->GetTextStyle();
97     textStyle.SetFontFamilies(fontFamilies);
98     component->SetTextStyle(textStyle);
99 }
100 
SetAllowScale(bool allowScale)101 void MarqueeModelImpl::SetAllowScale(bool allowScale)
102 {
103     auto component = GetComponent();
104     CHECK_NULL_VOID(component);
105     auto textStyle = component->GetTextStyle();
106     textStyle.SetAllowScale(allowScale);
107     component->SetTextStyle(textStyle);
108 }
109 
SetOnStart(std::function<void ()> && onChange)110 void MarqueeModelImpl::SetOnStart(std::function<void()>&& onChange)
111 {
112     auto component = GetComponent();
113     CHECK_NULL_VOID(component);
114     component->SetOnStart(move(onChange));
115 }
116 
SetOnBounce(std::function<void ()> && onChange)117 void MarqueeModelImpl::SetOnBounce(std::function<void()>&& onChange)
118 {
119     auto component = GetComponent();
120     CHECK_NULL_VOID(component);
121     component->SetOnBounce(move(onChange));
122 }
123 
SetOnFinish(std::function<void ()> && onChange)124 void MarqueeModelImpl::SetOnFinish(std::function<void()>&& onChange)
125 {
126     auto component = GetComponent();
127     CHECK_NULL_VOID(component);
128     component->SetOnFinish(move(onChange));
129 }
130 
GetComponent()131 RefPtr<MarqueeComponent> MarqueeModelImpl::GetComponent()
132 {
133     auto* stack = ViewStackProcessor::GetInstance();
134     if (!stack) {
135         return nullptr;
136     }
137     auto component = AceType::DynamicCast<MarqueeComponent>(stack->GetMainComponent());
138     return component;
139 }
140 } // namespace OHOS::Ace::Framework
141