138 lines
4.9 KiB
C++
Executable File
138 lines
4.9 KiB
C++
Executable File
/*
|
|
* 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 <memory>
|
|
|
|
|
|
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<VWidget> 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<VGuiEngine> &log = VGuiEngine::GetInstance();
|
|
* or std::shared_ptr<VGuiEngine> log = VGuiEngine::GetInstance();
|
|
* @param impl
|
|
* @return std::shared_ptr<VGuiEngine>&
|
|
*/
|
|
static std::shared_ptr<VGuiEngine> &GetInstance(std::shared_ptr<VGuiEngine> *impl = nullptr)
|
|
{
|
|
static auto instance = std::make_shared<VGuiEngine>();
|
|
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<VWidget> GetFrameParObject(void) { return std::make_shared<VWidget>(); }
|
|
virtual StatusCode SetNowNode(std::shared_ptr<VWidget>) { return CreateStatusCode(STATUS_CODE_OK); } // 这个函数不应该放出来, 在切换界面的时候使用
|
|
virtual std::shared_ptr<VWidget> GetNowNode(void) { return nullptr; }
|
|
virtual std::shared_ptr<VWidget> NewWidget(void) { return std::make_shared<VWidget>(); }
|
|
virtual std::shared_ptr<VWidget> NewPage(void) { return std::make_shared<VWidget>(); }
|
|
virtual std::shared_ptr<VWidget> NewImage(void) { return std::make_shared<VWidget>(); }
|
|
virtual std::shared_ptr<VWidget> NewButton(void) { return std::make_shared<VWidget>(); }
|
|
|
|
};
|
|
|
|
|
|
bool CreateGuiEngineImpl();
|
|
|
|
#endif
|