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/counter_model_impl.h"
17 
18 #include "core/components/counter/counter_component.h"
19 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
20 
21 namespace OHOS::Ace::Framework {
22 
23 namespace {
24 
25 constexpr Dimension COUNTER_DEFAULT_HEIGHT = 32.0_vp;
26 constexpr Dimension COUNTER_DEFAULT_WIDTH = 100.0_vp;
27 constexpr Dimension COUNTER_DEFAULT_CONTROL_WIDTH = 32.0_vp;
28 constexpr Dimension COUNTER_DEFAULT_RADIUS = 4.0_vp;
29 
30 } // namespace
31 
Create()32 void CounterModelImpl::Create()
33 {
34     std::list<RefPtr<Component>> children;
35     RefPtr<OHOS::Ace::CounterComponent> component = AceType::MakeRefPtr<CounterComponent>(children);
36     ViewStackProcessor::GetInstance()->ClaimElementId(component);
37     ViewStackProcessor::GetInstance()->Push(component);
38 
39     component->SetHeight(COUNTER_DEFAULT_HEIGHT);
40     component->SetWidth(COUNTER_DEFAULT_WIDTH);
41     component->SetControlWidth(COUNTER_DEFAULT_CONTROL_WIDTH);
42     component->SetControlRadius(COUNTER_DEFAULT_RADIUS);
43 }
SetOnInc(CounterEventFunc && onInc)44 void CounterModelImpl::SetOnInc(CounterEventFunc&& onInc)
45 {
46     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
47     auto counterComponent = AceType::DynamicCast<CounterComponent>(component);
48     counterComponent->SetOnInc(std::move(onInc));
49 }
SetOnDec(CounterEventFunc && onDec)50 void CounterModelImpl::SetOnDec(CounterEventFunc&& onDec)
51 {
52     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
53     auto counterComponent = AceType::DynamicCast<CounterComponent>(component);
54     counterComponent->SetOnDec(std::move(onDec));
55 }
SetHeight(const Dimension & value)56 void CounterModelImpl::SetHeight(const Dimension& value)
57 {
58     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
59     auto counterComponent = AceType::DynamicCast<CounterComponent>(component);
60     counterComponent->SetHeight(value);
61 }
SetWidth(const Dimension & value)62 void CounterModelImpl::SetWidth(const Dimension& value)
63 {
64     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
65     auto counterComponent = AceType::DynamicCast<CounterComponent>(component);
66     counterComponent->SetWidth(value);
67 }
SetControlWidth(const Dimension & value)68 void CounterModelImpl::SetControlWidth(const Dimension& value)
69 {
70     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
71     auto counterComponent = AceType::DynamicCast<CounterComponent>(component);
72     counterComponent->SetControlWidth(value);
73 }
SetStateChange(bool value)74 void CounterModelImpl::SetStateChange(bool value)
75 {
76     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
77     auto counterComponent = AceType::DynamicCast<CounterComponent>(component);
78     counterComponent->SetState(value);
79 }
SetBackgroundColor(const Color & value)80 void CounterModelImpl::SetBackgroundColor(const Color& value)
81 {
82     auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
83     auto counterComponent = AceType::DynamicCast<CounterComponent>(component);
84     counterComponent->SetBackgroundColor(value);
85 }
SetEnableDec(bool enableDec)86 void CounterModelImpl::SetEnableDec(bool enableDec) {};
SetEnableInc(bool enableInc)87 void CounterModelImpl::SetEnableInc(bool enableInc) {};
88 } // namespace OHOS::Ace::Framework
89