Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
HEYAHONG committed Dec 19, 2024
1 parent f399579 commit 19f097e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 18 deletions.
71 changes: 61 additions & 10 deletions hbox/gui/hgui_gui_scene1/hgui_scene1_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
{
Expand Down Expand Up @@ -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;
Expand All @@ -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
};


Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion hbox/gui/hgui_gui_scene1/hgui_scene1_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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* 用户自定义参数
Expand Down
12 changes: 5 additions & 7 deletions test/monochromescreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 19f097e

Please sign in to comment.