refactor app code (#93)
This commit is contained in:
committed by
GitHub
parent
a312bd5527
commit
d7b151ab88
@@ -20,13 +20,12 @@ static int32_t gui_main(void*);
|
||||
|
||||
Gui* gui = nullptr;
|
||||
|
||||
typedef void (*PubSubCallback)(const void* message, void* context);
|
||||
void loader_callback(const void* message, TT_UNUSED void* context) {
|
||||
auto* event = static_cast<const loader::LoaderEvent*>(message);
|
||||
if (event->type == loader::LoaderEventTypeApplicationShowing) {
|
||||
app::App* app = event->app_showing.app;
|
||||
const app::Manifest& app_manifest = app::tt_app_get_manifest(app);
|
||||
show_app(app, app_manifest.on_show, app_manifest.on_hide);
|
||||
app::App& app = event->app_showing.app;
|
||||
const app::Manifest& app_manifest = app.getManifest();
|
||||
show_app(app, app_manifest.onShow, app_manifest.onHide);
|
||||
} else if (event->type == loader::LoaderEventTypeApplicationHiding) {
|
||||
hide_app();
|
||||
}
|
||||
@@ -83,7 +82,7 @@ void request_draw() {
|
||||
thread_flags_set(thread_id, GUI_THREAD_FLAG_DRAW);
|
||||
}
|
||||
|
||||
void show_app(app::App app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide) {
|
||||
void show_app(app::App& app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide) {
|
||||
lock();
|
||||
tt_check(gui->app_view_port == nullptr);
|
||||
gui->app_view_port = view_port_alloc(app, on_show, on_hide);
|
||||
|
||||
@@ -14,7 +14,7 @@ typedef struct Gui Gui;
|
||||
* @param on_show
|
||||
* @param on_hide
|
||||
*/
|
||||
void show_app(app::App app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide);
|
||||
void show_app(app::App& app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide);
|
||||
|
||||
/**
|
||||
* Hide the current app's viewport.
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace tt::service::gui {
|
||||
|
||||
#define TAG "gui"
|
||||
|
||||
static lv_obj_t* create_app_views(Gui* gui, lv_obj_t* parent, app::App app) {
|
||||
static lv_obj_t* create_app_views(Gui* gui, lv_obj_t* parent, app::App& app) {
|
||||
lvgl::obj_set_style_bg_blacken(parent);
|
||||
|
||||
lv_obj_t* vertical_container = lv_obj_create(parent);
|
||||
@@ -19,8 +19,8 @@ static lv_obj_t* create_app_views(Gui* gui, lv_obj_t* parent, app::App app) {
|
||||
lvgl::obj_set_style_bg_blacken(vertical_container);
|
||||
|
||||
// TODO: Move statusbar into separate ViewPort
|
||||
app::Flags flags = app::tt_app_get_flags(app);
|
||||
if (flags.show_statusbar) {
|
||||
app::Flags flags = app.getFlags();
|
||||
if (flags.showStatusbar) {
|
||||
lvgl::statusbar_create(vertical_container);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void redraw(Gui* gui) {
|
||||
|
||||
ViewPort* view_port = gui->app_view_port;
|
||||
if (view_port != nullptr) {
|
||||
app::App app = view_port->app;
|
||||
app::App& app = view_port->app;
|
||||
lv_obj_t* container = create_app_views(gui, gui->lvgl_parent, app);
|
||||
view_port_show(view_port, container);
|
||||
} else {
|
||||
|
||||
@@ -9,35 +9,35 @@ namespace tt::service::gui {
|
||||
#define TAG "viewport"
|
||||
|
||||
ViewPort* view_port_alloc(
|
||||
app::App app,
|
||||
app::App& app,
|
||||
ViewPortShowCallback on_show,
|
||||
ViewPortHideCallback on_hide
|
||||
) {
|
||||
auto* view_port = static_cast<ViewPort*>(malloc(sizeof(ViewPort)));
|
||||
view_port->app = app;
|
||||
view_port->on_show = on_show;
|
||||
view_port->on_hide = on_hide;
|
||||
return view_port;
|
||||
return new ViewPort(
|
||||
app,
|
||||
on_show,
|
||||
on_hide
|
||||
);
|
||||
}
|
||||
|
||||
void view_port_free(ViewPort* view_port) {
|
||||
tt_assert(view_port);
|
||||
free(view_port);
|
||||
delete view_port;
|
||||
}
|
||||
|
||||
void view_port_show(ViewPort* view_port, lv_obj_t* parent) {
|
||||
tt_assert(view_port);
|
||||
tt_assert(parent);
|
||||
if (view_port->on_show) {
|
||||
if (view_port->onShow) {
|
||||
lvgl::obj_set_style_no_padding(parent);
|
||||
view_port->on_show(view_port->app, parent);
|
||||
view_port->onShow(view_port->app, parent);
|
||||
}
|
||||
}
|
||||
|
||||
void view_port_hide(ViewPort* view_port) {
|
||||
tt_assert(view_port);
|
||||
if (view_port->on_hide) {
|
||||
view_port->on_hide(view_port->app);
|
||||
if (view_port->onHide) {
|
||||
view_port->onHide(view_port->app);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,16 +8,21 @@ namespace tt::service::gui {
|
||||
/** ViewPort Draw callback
|
||||
* @warning called from GUI thread
|
||||
*/
|
||||
typedef void (*ViewPortShowCallback)(app::App app, lv_obj_t* parent);
|
||||
typedef void (*ViewPortHideCallback)(app::App app);
|
||||
typedef void (*ViewPortShowCallback)(app::App& app, lv_obj_t* parent);
|
||||
typedef void (*ViewPortHideCallback)(app::App& app);
|
||||
|
||||
// TODO: Move internally, use handle publicly
|
||||
|
||||
typedef struct {
|
||||
app::App app;
|
||||
ViewPortShowCallback on_show;
|
||||
ViewPortHideCallback _Nullable on_hide;
|
||||
bool app_toolbar;
|
||||
typedef struct ViewPort {
|
||||
app::App& app;
|
||||
ViewPortShowCallback onShow;
|
||||
ViewPortHideCallback _Nullable onHide;
|
||||
|
||||
ViewPort(
|
||||
app::App& app,
|
||||
ViewPortShowCallback on_show,
|
||||
ViewPortHideCallback _Nullable on_hide
|
||||
) : app(app), onShow(on_show), onHide(on_hide) {}
|
||||
} ViewPort;
|
||||
|
||||
/** ViewPort allocator
|
||||
@@ -30,7 +35,7 @@ typedef struct {
|
||||
* @return ViewPort instance
|
||||
*/
|
||||
ViewPort* view_port_alloc(
|
||||
app::App app,
|
||||
app::App& app,
|
||||
ViewPortShowCallback on_show,
|
||||
ViewPortHideCallback on_hide
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user