From 19f097e117f1b2caab04a626806d4bdb013bb849 Mon Sep 17 00:00:00 2001 From: HEYAHONG <2229388563@qq.com> Date: Thu, 19 Dec 2024 15:32:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hbox/gui/hgui_gui_scene1/hgui_scene1_app.c | 71 +++++++++++++++++++--- hbox/gui/hgui_gui_scene1/hgui_scene1_app.h | 10 ++- test/monochromescreen/main.cpp | 12 ++-- 3 files changed, 75 insertions(+), 18 deletions(-) diff --git a/hbox/gui/hgui_gui_scene1/hgui_scene1_app.c b/hbox/gui/hgui_gui_scene1/hgui_scene1_app.c index bdd9bdd..f824733 100644 --- a/hbox/gui/hgui_gui_scene1/hgui_scene1_app.c +++ b/hbox/gui/hgui_gui_scene1/hgui_scene1_app.c @@ -26,6 +26,25 @@ extern "C" #define HGUI_SCENE1_APP_HEIGHT 64 #endif // HGUI_SCENE1_APP_HEIGHT + +typedef struct +{ + struct + { + uint32_t be_init:1; + }; +} hgui_scene1_app_status_t;//APP状态,包含所有APP可修改的属性 + +struct hgui_scene1_app +{ + hgui_driver_t * driver; + size_t w; + size_t h; + bool (*init)(const hgui_scene1_app_t *app,void *usr); + bool (*update)(const hgui_scene1_app_t *app,void *usr); + hgui_scene1_app_status_t *status; +}; + #ifndef HGUI_SCENE1_APP_ON_INIT_SUCCESS #define HGUI_SCENE1_APP_ON_INIT_SUCCESS {} #endif // HGUI_SCENE1_APP_ON_INIT_SUCCESS @@ -36,11 +55,26 @@ extern "C" static bool hgui_scene1_app_init_callback(const hgui_scene1_app_t *app,void *usr) { + if(hgui_scene1_app_was_init(app)) + { + return true; + } if(hgui_driver_reset(hgui_scene1_app_driver_get(app))) { { HGUI_SCENE1_APP_ON_INIT_SUCCESS; } + if(app!=NULL) + { + if(app->status!=NULL) + { + app->status->be_init=1; + } + } + else + { + g_hgui_scene1_app.status->be_init=1; + } return true; } { @@ -68,6 +102,17 @@ static bool hgui_scene1_app_init_callback(const hgui_scene1_app_t *app,void *us static bool hgui_scene1_app_update_callback(const hgui_scene1_app_t *app,void *usr) { + if(app!=NULL) + { + if(!hgui_scene1_app_was_init(app)) + { + hgui_scene1_app_init(app,usr); + } + if(!hgui_scene1_app_was_init(app)) + { + return false; + } + } bool ret=false; { HGUI_SCENE1_APP_ON_UPDATE_BEGIN; @@ -91,22 +136,15 @@ static bool hgui_scene1_app_update_callback(const hgui_scene1_app_t *app,void * return ret; } -struct hgui_scene1_app -{ - hgui_driver_t * driver; - size_t w; - size_t h; - bool (*init)(const hgui_scene1_app_t *app,void *usr); - bool (*update)(const hgui_scene1_app_t *app,void *usr); -}; - +static hgui_scene1_app_status_t m_hgui_scene1_app_status= {0}; const hgui_scene1_app_t g_hgui_scene1_app= { (HGUI_SCENE1_APP_DRIVER), (HGUI_SCENE1_APP_WIDTH), (HGUI_SCENE1_APP_HEIGHT), hgui_scene1_app_init_callback, - hgui_scene1_app_update_callback + hgui_scene1_app_update_callback, + &m_hgui_scene1_app_status }; @@ -152,6 +190,19 @@ bool hgui_scene1_app_init(const hgui_scene1_app_t *app,void *usr) return g_hgui_scene1_app.init(app,usr); } +bool hgui_scene1_app_was_init(const hgui_scene1_app_t *app) +{ + if(app!=NULL) + { + if(g_hgui_scene1_app.status!=NULL) + { + return app->status->be_init==1; + } + return false; + } + return g_hgui_scene1_app.status->be_init==1; +} + bool hgui_scene1_app_update(const hgui_scene1_app_t *app,void *usr) { if(app!=NULL) diff --git a/hbox/gui/hgui_gui_scene1/hgui_scene1_app.h b/hbox/gui/hgui_gui_scene1/hgui_scene1_app.h index ecfc517..0a3cfa4 100644 --- a/hbox/gui/hgui_gui_scene1/hgui_scene1_app.h +++ b/hbox/gui/hgui_gui_scene1/hgui_scene1_app.h @@ -65,7 +65,15 @@ size_t hgui_scene1_app_height_get(const hgui_scene1_app_t *app); */ bool hgui_scene1_app_init(const hgui_scene1_app_t *app,void *usr); -/** \brief App更新,注意:此函数只能在成功初始化后使用,在某些场景下不进行更新将导致异常。 +/** \brief App是否初始化 + * + * \param app const hgui_scene1_app_t* App指针 + * \return bool 是否成功初始化 + * + */ +bool hgui_scene1_app_was_init(const hgui_scene1_app_t *app); + +/** \brief App更新,注意:在某些场景下不进行更新将导致异常。 * * \param app const hgui_scene1_app_t* App指针 * \param usr void* 用户自定义参数 diff --git a/test/monochromescreen/main.cpp b/test/monochromescreen/main.cpp index acaf09e..db3c35c 100644 --- a/test/monochromescreen/main.cpp +++ b/test/monochromescreen/main.cpp @@ -133,14 +133,12 @@ static void monochromscreen_init() int main() { - if(hgui_scene1_app_init(&g_hgui_scene1_app,NULL)) + + size_t i=0; + while(hgui_scene1_app_update(&g_hgui_scene1_app,NULL)) { - size_t i=0; - while(hgui_scene1_app_update(&g_hgui_scene1_app,NULL)) - { - i++; - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - } + i++; + std::this_thread::sleep_for(std::chrono::milliseconds(50)); } return 0; }