1 /*
2  * Copyright (c) 2021-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 "core/components/coverage/coverage_component.h"
17 
18 #include "core/components/coverage/render_coverage.h"
19 
20 namespace OHOS::Ace {
21 namespace {
22 
23 constexpr Dimension DEFAULT_FONT_SIZE = Dimension(40);
24 
25 } // namespace
26 
CoverageComponent(const std::list<RefPtr<Component>> & children)27 CoverageComponent::CoverageComponent(const std::list<RefPtr<Component>>& children) : ComponentGroup(children)
28 {
29     std::list<RefPtr<Component>> childrenAlign;
30     alignComponent_ = AceType::MakeRefPtr<AlignComponent>(childrenAlign, Alignment::CENTER);
31     textBoxComponent_ = AceType::MakeRefPtr<OHOS::Ace::BoxComponent>();
32     textComponent_ = AceType::MakeRefPtr<OHOS::Ace::TextComponentV2>("");
33 }
34 
CreateRenderNode()35 RefPtr<RenderNode> CoverageComponent::CreateRenderNode()
36 {
37     return RenderCoverage::Create();
38 }
39 
Initialization()40 void CoverageComponent::Initialization()
41 {
42     auto textStyle = textComponent_->GetTextStyle();
43     textStyle.SetFontSize(DEFAULT_FONT_SIZE);
44     textComponent_->SetTextStyle(textStyle);
45     textBoxComponent_->SetChild(textComponent_);
46     alignComponent_->AppendChild(textBoxComponent_);
47     InsertChild(1, alignComponent_);
48     Component::MergeRSNode(alignComponent_, textComponent_);
49 }
50 
51 } // namespace OHOS::Ace
52