diff --git a/ExternalApps/HelloWorld/main/Source/main.c b/ExternalApps/HelloWorld/main/Source/main.c index ff457b00..f50e0407 100644 --- a/ExternalApps/HelloWorld/main/Source/main.c +++ b/ExternalApps/HelloWorld/main/Source/main.c @@ -6,7 +6,7 @@ * Only C is supported for now (C++ symbols fail to link) */ static void onShow(AppHandle app, void* data, lv_obj_t* parent) { - lv_obj_t* toolbar = tt_lvgl_toolbar_create(parent, app); + lv_obj_t* toolbar = tt_lvgl_toolbar_create_for_app(parent, app); lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0); lv_obj_t* label = lv_label_create(parent); diff --git a/Tactility/Include/Tactility/lvgl/Toolbar.h b/Tactility/Include/Tactility/lvgl/Toolbar.h index 85d06050..eac3d747 100644 --- a/Tactility/Include/Tactility/lvgl/Toolbar.h +++ b/Tactility/Include/Tactility/lvgl/Toolbar.h @@ -9,12 +9,45 @@ namespace tt::lvgl { #define TOOLBAR_TITLE_FONT_HEIGHT 18 #define TOOLBAR_ACTION_LIMIT 4 -lv_obj_t* toolbar_create(lv_obj_t* parent, const std::string& title); +/** Create a toolbar widget that shows the app name as title */ lv_obj_t* toolbar_create(lv_obj_t* parent, const app::AppContext& app); + +/** Create a toolbar widget with the provided title*/ +lv_obj_t* toolbar_create(lv_obj_t* parent, const std::string& title); + +/** Sets the toolbar title */ void toolbar_set_title(lv_obj_t* obj, const std::string& title); -void toolbar_set_nav_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* user_data); -lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* user_data); + +/** Sets the navigation action of the toolbar (button on the top-left) + * @param[in] obj the toolbar instance + * @param[in] icon the icon to set on the button + * @param[in] callback the callback for the click action of the button + * @param[in] callbackEventUserData the user data that is attached to the callback event object + */ +void toolbar_set_nav_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* userData); + +/** + * Create and add an action button to the toolbar (aligned to the right of the toolbar) + * @param[in] obj the toolbar instance + * @param[in] icon the icon for the action + * @param[in] callback the callback for the click action of the button + * @param[in] callbackEventUserData the user data that is attached to the callback event object + * @return an lv_button instance + */ +lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* userData); + +/** + * Create and add a switch to the toolbar actions. + * @param[in] obj the toolbar instance + * @return an instance created by lv_switch_create() + */ lv_obj_t* toolbar_add_switch_action(lv_obj_t* obj); + +/** + * Create and add a spinner to the toolbar actions. + * @param[in] obj the toolbar instance + * @return an instance created by Tactility's spinner_create() + */ lv_obj_t* toolbar_add_spinner_action(lv_obj_t* obj); } // namespace diff --git a/TactilityC/Include/tt_lvgl_toolbar.h b/TactilityC/Include/tt_lvgl_toolbar.h index 96543587..0cb88dd9 100644 --- a/TactilityC/Include/tt_lvgl_toolbar.h +++ b/TactilityC/Include/tt_lvgl_toolbar.h @@ -8,10 +8,45 @@ extern "C" { #endif /** Create a toolbar widget that shows the app name as title */ -lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppHandle context); +lv_obj_t* tt_lvgl_toolbar_create_for_app(lv_obj_t* parent, AppHandle context); /** Create a toolbar widget with the provided title*/ -lv_obj_t* tt_lvgl_toolbar_create_simple(lv_obj_t* parent, const char* title); +lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, const char* title); + +/** Sets the toolbar title */ +void toolbar_set_title(lv_obj_t* obj, const char* title); + +/** Sets the navigation action of the toolbar (button on the top-left) + * @param[in] obj the toolbar instance + * @param[in] icon the icon to set on the button + * @param[in] callback the callback for the click action of the button + * @param[in] callbackEventUserData the user data that is attached to the callback event object + */ +void toolbar_set_nav_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* callbackEventUserData); + +/** + * Create and add an action button to the toolbar (aligned to the right of the toolbar) + * @param[in] obj the toolbar instance + * @param[in] icon the icon for the action + * @param[in] callback the callback for the click action of the button + * @param[in] callbackEventUserData the user data that is attached to the callback event object + * @return an instance created by lv_button_create() + */ +lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* callbackEventUserData); + +/** + * Create and add a switch to the toolbar actions. + * @param[in] obj the toolbar instance + * @return an instance created by lv_switch_create() + */ +lv_obj_t* toolbar_add_switch_action(lv_obj_t* obj); + +/** + * Create and add a spinner to the toolbar actions. + * @param[in] obj the toolbar instance + * @return an instance created by Tactility's spinner_create() + */ +lv_obj_t* toolbar_add_spinner_action(lv_obj_t* obj); #ifdef __cplusplus } diff --git a/TactilityC/Source/tt_init.cpp b/TactilityC/Source/tt_init.cpp index 88ad6174..83f1f99a 100644 --- a/TactilityC/Source/tt_init.cpp +++ b/TactilityC/Source/tt_init.cpp @@ -50,7 +50,7 @@ const struct esp_elfsym elf_symbols[] { ESP_ELFSYM_EXPORT(tt_hal_i2c_lock), ESP_ELFSYM_EXPORT(tt_hal_i2c_unlock), ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_create), - ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_create_simple), + ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_create_for_app), ESP_ELFSYM_EXPORT(tt_message_queue_alloc), ESP_ELFSYM_EXPORT(tt_message_queue_free), ESP_ELFSYM_EXPORT(tt_message_queue_put), @@ -92,6 +92,15 @@ const struct esp_elfsym elf_symbols[] { ESP_ELFSYM_EXPORT(tt_timer_set_thread_priority), // tt::lvgl ESP_ELFSYM_EXPORT(tt_lvgl_spinner_create), + // lv_event + ESP_ELFSYM_EXPORT(lv_event_get_code), + ESP_ELFSYM_EXPORT(lv_event_get_indev), + ESP_ELFSYM_EXPORT(lv_event_get_key), + ESP_ELFSYM_EXPORT(lv_event_get_param), + ESP_ELFSYM_EXPORT(lv_event_get_scroll_anim), + ESP_ELFSYM_EXPORT(lv_event_get_user_data), + ESP_ELFSYM_EXPORT(lv_event_get_target_obj), + ESP_ELFSYM_EXPORT(lv_event_get_target), // lv_obj ESP_ELFSYM_EXPORT(lv_obj_add_event_cb), ESP_ELFSYM_EXPORT(lv_obj_align), diff --git a/TactilityC/Source/tt_lvgl_toolbar.cpp b/TactilityC/Source/tt_lvgl_toolbar.cpp index 669f1fd2..532ae3ff 100644 --- a/TactilityC/Source/tt_lvgl_toolbar.cpp +++ b/TactilityC/Source/tt_lvgl_toolbar.cpp @@ -3,12 +3,32 @@ extern "C" { -lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppHandle context) { - return tt::lvgl::toolbar_create(parent, *(tt::app::AppContext*)context); -} - -lv_obj_t* tt_lvgl_toolbar_create_simple(lv_obj_t* parent, const char* title) { +lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, const char* title) { return tt::lvgl::toolbar_create(parent, title); } +lv_obj_t* tt_lvgl_toolbar_create_for_app(lv_obj_t* parent, AppHandle context) { + return tt::lvgl::toolbar_create(parent, *(tt::app::AppContext*)context); +} + +void toolbar_set_title(lv_obj_t* obj, const char* title) { + tt::lvgl::toolbar_set_title(obj, title); +} + +void toolbar_set_nav_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* callbackEventUserData) { + tt::lvgl::toolbar_set_nav_action(obj, icon, callback, callbackEventUserData); +} + +lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* callbackEventUserData) { + return tt::lvgl::toolbar_add_button_action(obj, icon, callback, callbackEventUserData); +} + +lv_obj_t* toolbar_add_switch_action(lv_obj_t* obj) { + return tt::lvgl::toolbar_add_switch_action(obj); +} + +lv_obj_t* toolbar_add_spinner_action(lv_obj_t* obj) { + return tt::lvgl::toolbar_add_spinner_action(obj); +} + }