1/*
2 * Copyright (c) 2020-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 "components/ui_label_button.h"
17#include "common/typed_text.h"
18#include "draw/draw_label.h"
19#include "font/ui_font.h"
20
21namespace OHOS {
22UILabelButton::UILabelButton() : labelButtonText_(nullptr), offset_({ 0, 0 })
23{
24    labelStyle_ = StyleDefault::GetDefaultStyle();
25}
26
27void UILabelButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
28{
29    UIButton::OnDraw(gfxDstBuffer, invalidatedArea);
30
31    Rect textRect = GetContentRect();
32    textRect.SetLeft(textRect.GetLeft() + offset_.x);
33    textRect.SetTop(textRect.GetTop() + offset_.y);
34    InitLabelButtonText();
35    labelButtonText_->ReMeasureTextSize(textRect, labelStyle_);
36    OpacityType opa = GetMixOpaScale();
37    uint16_t ellipsisIndex = labelButtonText_->GetEllipsisIndex(textRect, labelStyle_);
38    labelButtonText_->OnDraw(gfxDstBuffer, invalidatedArea, GetOrigRect(), textRect, 0,
39                             labelStyle_, ellipsisIndex, opa);
40}
41
42UILabelButton::~UILabelButton()
43{
44    if (labelButtonText_ != nullptr) {
45        delete labelButtonText_;
46        labelButtonText_ = nullptr;
47    }
48}
49}  // namespace OHOS
50