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 #ifndef CHARGER_UI_TEXT_LABLE_H 17 #define CHARGER_UI_TEXT_LABLE_H 18 19 #include <iostream> 20 #include <string> 21 #include <functional> 22 #include "frame.h" 23 24 namespace OHOS { 25 namespace HDI { 26 namespace Battery { 27 namespace V1_1 { 28 class TextLabel : public View { 29 using ClickCallback = std::function<void(int32_t id)>; 30 enum class FontType { 31 DEFAULT_FONT, 32 }; 33 34 enum class AlignmentMethod { 35 ALIGN_CENTER, 36 ALIGN_TO_LEFT, 37 ALIGN_TO_TOP, 38 }; 39 public: 40 TextLabel(int32_t mStartX, int32_t mStartY, int32_t w, int32_t h, Frame* mparent); 41 ~TextLabel() override = default;; 42 void SetText(const char* str); 43 void SetTextColor(BRGA888Pixel color); 44 void SetFont(FontType fType); 45 void SetOutLineBold(bool topBold, bool bottomBold); 46 void SetTextAlignmentMethod(AlignmentMethod methodH, AlignmentMethod methodV); 47 void OnDraw() override; 48 private: 49 void InitFont(); 50 FILE* InitFontType(); 51 void DrawText(); 52 void DrawTextLoop(unsigned char ch, char* tmpBuf, int32_t textSx, int32_t textSy); 53 void DrawOutline(); 54 void DrawFocus(); 55 56 ClickCallback callBack_; 57 char textBuf_[512 + 1] {}; 58 Frame* parent_ {}; 59 60 AlignmentMethod fontAligMethodLevel_ = AlignmentMethod::ALIGN_TO_LEFT; 61 AlignmentMethod fontAligMethodUpright_ = AlignmentMethod::ALIGN_CENTER; 62 63 BRGA888Pixel outlineColor_ {}; 64 BRGA888Pixel actionBgColor_ {}; 65 BRGA888Pixel normalBgColor_ {}; 66 BRGA888Pixel textColor_ {}; 67 68 bool boldTopLine_ = false; 69 bool boldBottomLine_ = false; 70 71 FontType fontType_ { FontType::DEFAULT_FONT }; 72 char fontBuf_[4096 * 4096] {}; 73 uint32_t fontWidth_ = 0; 74 uint32_t fontHeight_ = 0; 75 }; 76 } // namespace V1_1 77 } // namespace Battery 78 } // namespace HDI 79 } // namespace OHOS 80 #endif // CHARGER_UI_TEXT_LABLE_H 81