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