• 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/divider_model_impl.h"
17 
18 #include "bridge/declarative_frontend/jsview/js_view_abstract.h"
19 #include "core/components/box/box_component.h"
20 #include "core/components/divider/divider_component.h"
21 #include "core/components/divider/divider_theme.h"
22 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
23 
24 namespace OHOS::Ace::Framework {
25 
Create()26 void DividerModelImpl::Create()
27 {
28     RefPtr<Component> dividerComponent = AceType::MakeRefPtr<OHOS::Ace::DividerComponent>();
29     auto theme = JSViewAbstract::GetTheme<DividerTheme>();
30     if (theme) {
31         auto component = AceType::DynamicCast<OHOS::Ace::DividerComponent>(dividerComponent);
32         component->SetDividerColor(theme->GetColor());
33     }
34     ViewStackProcessor::GetInstance()->ClaimElementId(dividerComponent);
35     ViewStackProcessor::GetInstance()->Push(dividerComponent);
36 }
Vertical(bool value)37 void DividerModelImpl::Vertical(bool value)
38 {
39     auto* stack = ViewStackProcessor::GetInstance();
40     auto component = AceType::DynamicCast<OHOS::Ace::DividerComponent>(stack->GetMainComponent());
41     if (component) {
42         component->SetVertical(value);
43     }
44 
45     auto box = stack->GetBoxComponent();
46     if (value) {
47         box->SetFlex(BoxFlex::FLEX_Y);
48     } else {
49         box->SetFlex(BoxFlex::FLEX_X);
50     }
51 }
DividerColor(const Color & value)52 void DividerModelImpl::DividerColor(const Color& value)
53 {
54     auto* stack = ViewStackProcessor::GetInstance();
55     auto component = AceType::DynamicCast<OHOS::Ace::DividerComponent>(stack->GetMainComponent());
56     if (component) {
57         component->SetDividerColor(value);
58     }
59 }
StrokeWidth(const Dimension & value)60 void DividerModelImpl::StrokeWidth(const Dimension& value)
61 {
62     auto* stack = ViewStackProcessor::GetInstance();
63     auto component = AceType::DynamicCast<OHOS::Ace::DividerComponent>(stack->GetMainComponent());
64     if (component) {
65         component->SetStrokeWidth(value);
66     }
67 }
LineCap(const enum LineCap & value)68 void DividerModelImpl::LineCap(const enum LineCap& value)
69 {
70     auto* stack = ViewStackProcessor::GetInstance();
71     auto component = AceType::DynamicCast<OHOS::Ace::DividerComponent>(stack->GetMainComponent());
72     if (component) {
73         component->SetLineCap(value);
74     }
75 }
76 
77 } // namespace OHOS::Ace::Framework