/* * 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. */ #ifndef GUI_ENGINE_H #define GUI_ENGINE_H #include "StatusCode.h" #include enum class i_lv_event_code_t{ I_LV_EVENT_ALL = 0, I_LV_EVENT_CLICKED, /**< Called on release if not scrolled (regardless to long press)*/ }; enum class i_lv_align_t{ I_LV_ALIGN_DEFAULT = 0, I_LV_ALIGN_TOP_LEFT, I_LV_ALIGN_TOP_MID, I_LV_ALIGN_TOP_RIGHT, I_LV_ALIGN_BOTTOM_LEFT, I_LV_ALIGN_BOTTOM_MID, I_LV_ALIGN_BOTTOM_RIGHT, I_LV_ALIGN_LEFT_MID, I_LV_ALIGN_RIGHT_MID, I_LV_ALIGN_CENTER, I_LV_ALIGN_OUT_TOP_LEFT, I_LV_ALIGN_OUT_TOP_MID, I_LV_ALIGN_OUT_TOP_RIGHT, I_LV_ALIGN_OUT_BOTTOM_LEFT, I_LV_ALIGN_OUT_BOTTOM_MID, I_LV_ALIGN_OUT_BOTTOM_RIGHT, I_LV_ALIGN_OUT_LEFT_TOP, I_LV_ALIGN_OUT_LEFT_MID, I_LV_ALIGN_OUT_LEFT_BOTTOM, I_LV_ALIGN_OUT_RIGHT_TOP, I_LV_ALIGN_OUT_RIGHT_MID, I_LV_ALIGN_OUT_RIGHT_BOTTOM, }; typedef void (*i_lv_event_cb_t)(i_lv_event_code_t e, void * userData); class VWidget { public: VWidget() = default; virtual ~VWidget() {} virtual void ImageSetSrc(const void *src) {} virtual void SetSize(const int16_t width, const int16_t height) {} virtual void SetColor(uint32_t color) {} virtual void Load(void) {} virtual void SetText(const char *text) {} virtual void AlignTo(std::shared_ptr base, i_lv_align_t align, int16_t posX, int16_t posY) {} virtual void SetPos(int16_t posX, int16_t posY) {} virtual void Center(void) {} virtual void SetEventCb(i_lv_event_cb_t eventCb) {} virtual void EventSend(i_lv_event_code_t e, void * userData) {} // lv_res_t lv_event_send(lv_obj_t * obj, lv_event_code_t event_code, void * param) virtual void Delete(void) {} /** * @brief Set transparency * @param opaValue 0~255 * 0: transparency * 255:opacification * 10%= 25; 20%= 51; 30%= 76; 40%= 102; 50%= 127; 60%= 153; 70%= 178; 80%= 204; 90%= 229; 100%= 255; */ virtual void SetOpa(const uint8_t opaValue = 0) {} }; class VGuiEngine { public: VGuiEngine() = default; virtual ~VGuiEngine() = default; /** * @brief Get the Instance object * Return reference for runing faster. Usage : VGuiEngine::GetInstance()->Init(); * Don't use VGuiEngine like this: * std::shared_ptr &log = VGuiEngine::GetInstance(); * or std::shared_ptr log = VGuiEngine::GetInstance(); * @param impl * @return std::shared_ptr& */ static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr) { static auto instance = std::make_shared(); if (impl) { /** * @brief * The non-thread-safe changing is only for gtest. */ instance = *impl; } return instance; } /** * @brief * * @param width width of screen * @param height height of screen * @param appInit for app to init the first window */ virtual bool Init(const unsigned int width, const unsigned int height, void (*appInit)()) { return false; } virtual void UnInit() {} virtual const int16_t GetScreenWidth(void) { return 1;} virtual const int16_t GetScreenHeight(void) { return 1;} virtual StatusCode CreateFrameParObject(int16_t widht = 100, int16_t height = 100, int16_t posX = 0, int16_t posY = 0) { return CreateStatusCode(STATUS_CODE_OK); } // 这个界面不应该放出来, 在应用层初始化的时候使用 virtual std::shared_ptr GetFrameParObject(void) { return std::make_shared(); } virtual StatusCode SetNowNode(std::shared_ptr) { return CreateStatusCode(STATUS_CODE_OK); } // 这个函数不应该放出来, 在切换界面的时候使用 virtual std::shared_ptr GetNowNode(void) { return nullptr; } virtual std::shared_ptr NewWidget(void) { return std::make_shared(); } virtual std::shared_ptr NewPage(void) { return std::make_shared(); } virtual std::shared_ptr NewImage(void) { return std::make_shared(); } virtual std::shared_ptr NewButton(void) { return std::make_shared(); } }; bool CreateGuiEngineImpl(); #endif