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/column_model_impl.h"
17
18 #include "base/memory/referenced.h"
19 #include "core/components/flex/flex_component.h"
20 #include "core/components/wrap/wrap_component.h"
21 #include "core/components_ng/pattern/flex/flex_model.h"
22 #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h"
23 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
24
25 namespace OHOS::Ace::Framework {
26
Create(const std::optional<Dimension> & space,AlignDeclaration * declaration,const std::string & tag)27 void ColumnModelImpl::Create(
28 const std::optional<Dimension>& space, AlignDeclaration* declaration, const std::string& tag)
29 {
30 std::list<RefPtr<Component>> children;
31 RefPtr<ColumnComponent> columnComponent =
32 AceType::MakeRefPtr<OHOS::Ace::ColumnComponent>(FlexAlign::FLEX_START, FlexAlign::CENTER, children);
33 ViewStackProcessor::GetInstance()->ClaimElementId(columnComponent);
34 columnComponent->SetMainAxisSize(MainAxisSize::MIN);
35 columnComponent->SetCrossAxisSize(CrossAxisSize::MIN);
36 if (space.has_value()) {
37 columnComponent->SetSpace(space.value());
38 }
39 if (declaration != nullptr) {
40 columnComponent->SetAlignDeclarationPtr(declaration);
41 }
42
43 columnComponent->SetInspectorTag(tag);
44 ViewStackProcessor::GetInstance()->Push(columnComponent, false);
45 JSInteractableView::SetFocusNode(true);
46 }
47
SetAlignItems(FlexAlign flexAlign)48 void ColumnModelImpl::SetAlignItems(FlexAlign flexAlign)
49 {
50 FlexModel::GetInstance()->SetAlignItems(static_cast<int32_t>(flexAlign));
51 }
52
SetJustifyContent(FlexAlign flexAlign)53 void ColumnModelImpl::SetJustifyContent(FlexAlign flexAlign)
54 {
55 FlexModel::GetInstance()->SetJustifyContent(static_cast<int32_t>(flexAlign));
56 }
57
CreateWithWrap()58 void ColumnModelImpl::CreateWithWrap()
59 {
60 std::list<RefPtr<Component>> children;
61 RefPtr<WrapComponent> component = AceType::MakeRefPtr<WrapComponent>(0.0, 0.0, children);
62 ViewStackProcessor::GetInstance()->ClaimElementId(component);
63
64 component->SetDirection(WrapDirection::VERTICAL);
65 component->SetMainAlignment(WrapAlignment::START);
66 component->SetCrossAlignment(WrapAlignment::START);
67 component->SetAlignment(WrapAlignment::START);
68 component->SetDialogStretch(false);
69
70 ViewStackProcessor::GetInstance()->Push(component);
71 }
72
73 } // namespace OHOS::Ace::Framework
74