/* * Copyright (c) 2023 Fancy Code. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, softwareZhoufuwuqimima123 * * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "GuiLvgl.h" #include "ILog.h" #include "LvglWidget.h" GuiLvgl::GuiLvgl() { } /** * @brief Get screen width * * @return Screen width value */ const int16_t GuiLvgl::GetScreenWidth(void) { return lv_obj_get_width(std::dynamic_pointer_cast(_ParWidget)->mWidget); } /** * @brief Get screen height * * @return Screen height */ const int16_t GuiLvgl::GetScreenHeight(void) { return lv_obj_get_height(std::dynamic_pointer_cast(_ParWidget)->mWidget); } void FrameParObjectCb(i_lv_event_code_t e, void *userData) { if(VGuiEngine::GetInstance()->GetNowNode() != nullptr) { VGuiEngine::GetInstance()->GetNowNode()->EventSend(e, userData); } else { } } StatusCode GuiLvgl::CreateFrameParObject(int16_t widht, int16_t height, int16_t posX, int16_t posY) { std::shared_ptr widget = std::make_shared(); widget->mWidget = lv_obj_create(lv_scr_act()); widget->SetOpa(0); widget->SetSize(widht, height); widget->SetEventCb(FrameParObjectCb); widget->SetPos(0, 0); lv_refr_now(NULL); _ParWidget = widget; return CreateStatusCode(STATUS_CODE_OK); } std::shared_ptr GuiLvgl::GetFrameParObject(void) { return std::static_pointer_cast(_ParWidget); } StatusCode GuiLvgl::SetNowNode(std::shared_ptr widget) { _NowNode = widget; return CreateStatusCode(STATUS_CODE_OK); } std::shared_ptr GuiLvgl::GetNowNode(void) { return _NowNode; } std::shared_ptr GuiLvgl::NewWidget(void) { std::shared_ptr widget = std::make_shared(); widget->mWidget = lv_obj_create(JudgeParent()); return widget; } std::shared_ptr GuiLvgl::NewPage(void) { return nullptr; } std::shared_ptr GuiLvgl::NewImage(void) { std::shared_ptr widget = std::make_shared(); widget->mWidget = lv_img_create(JudgeParent()); return widget; } std::shared_ptr GuiLvgl::NewButton(void) { std::shared_ptr widget = std::make_shared(); widget->mWidget = lv_btn_create(JudgeParent()); lv_obj_set_pos(widget->mWidget, 0, 0); /*Set its position*/ lv_obj_set_size(widget->mWidget, 10, 10); /*Set its size*/ lv_obj_add_event_cb(widget->mWidget, nullptr, LV_EVENT_ALL, nullptr); /*Assign a callback to the button*/ return widget; } lv_obj_t* GuiLvgl::JudgeParent(void) { if (_NowNode != nullptr) { return (std::dynamic_pointer_cast(_NowNode)->mWidget); } else if (_ParWidget != nullptr) { // If no parent object is specified at the application layer, the parent window object of the application layer is used return (std::dynamic_pointer_cast(_ParWidget)->mWidget); } else { //If the application layer does not specify a parent object, and the application layer's parent window object does not exist, LVGL's frame window object is used return (lv_scr_act()); } }