1 /*
2  * Copyright (c) 2021 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/slider/render_block.h"
17 
18 namespace OHOS::Ace {
19 
Update(const RefPtr<Component> & component)20 void RenderBlock::Update(const RefPtr<Component>& component)
21 {
22     const RefPtr<BlockComponent> block = AceType::DynamicCast<BlockComponent>(component);
23     if (block == nullptr) {
24         LOGE("Slider::RenderBlock update with nullptr");
25         return;
26     }
27     blockColor_ = block->GetBlockColor();
28     blockSize_ = block->GetBlockSize();
29     hotRegionWidth_ = block->GetHotRegionWidth();
30     hotRegionHeight_ = block->GetHotRegionHeight();
31     MarkNeedRender();
32 }
33 
PerformLayout()34 void RenderBlock::PerformLayout()
35 {
36     SetLayoutSize(Measure());
37 }
38 
Measure()39 Size RenderBlock::Measure()
40 {
41     double rawWidth = NormalizeToPx(hotRegionWidth_);
42     double rawHeight = NormalizeToPx(hotRegionHeight_);
43     return Size(rawWidth, rawHeight);
44 }
45 
46 } // namespace OHOS::Ace