diff --git a/Tactility/Include/Tactility/lvgl/Toolbar.h b/Tactility/Include/Tactility/lvgl/Toolbar.h index 65ea2d23..381716f8 100644 --- a/Tactility/Include/Tactility/lvgl/Toolbar.h +++ b/Tactility/Include/Tactility/lvgl/Toolbar.h @@ -27,14 +27,24 @@ 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* userData); /** - * Create and add an action button to the toolbar (aligned to the right of the toolbar) + * Create and add an action button with an image 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] imagePath the path to an image file to shown 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 + * @param[in] callbackUserData the user data that is passed to the callback * @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); +lv_obj_t* toolbar_add_image_button_action(lv_obj_t* obj, const char* imagePath, lv_event_cb_t callback, void* callbackUserData); + +/** + * Create and add an action button with text to the toolbar (aligned to the right of the toolbar) + * @param[in] obj the toolbar instance + * @param[in] text the button text + * @param[in] callback the callback for the click action of the button + * @param[in] callbackUserData the user data that is passed to the callback + * @return an lv_button instance + */ +lv_obj_t* toolbar_add_text_button_action(lv_obj_t* obj, const char* text, lv_event_cb_t callback, void* callbackUserData); /** * Create and add a switch to the toolbar actions. diff --git a/Tactility/Source/app/files/View.cpp b/Tactility/Source/app/files/View.cpp index 88f27cf3..dd29b450 100644 --- a/Tactility/Source/app/files/View.cpp +++ b/Tactility/Source/app/files/View.cpp @@ -260,7 +260,7 @@ void View::init(const AppContext& appContext, lv_obj_t* parent) { lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT); auto* toolbar = lvgl::toolbar_create(parent, appContext); - navigate_up_button = lvgl::toolbar_add_button_action(toolbar, LV_SYMBOL_UP, &onNavigateUpPressedCallback, this); + navigate_up_button = lvgl::toolbar_add_image_button_action(toolbar, LV_SYMBOL_UP, &onNavigateUpPressedCallback, this); auto* wrapper = lv_obj_create(parent); lv_obj_set_width(wrapper, LV_PCT(100)); diff --git a/Tactility/Source/app/fileselection/View.cpp b/Tactility/Source/app/fileselection/View.cpp index ece9d28c..f4235aab 100644 --- a/Tactility/Source/app/fileselection/View.cpp +++ b/Tactility/Source/app/fileselection/View.cpp @@ -178,7 +178,7 @@ void View::init(lv_obj_t* parent, Mode mode) { lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT); auto* toolbar = lvgl::toolbar_create(parent, "Select File"); - navigate_up_button = lvgl::toolbar_add_button_action(toolbar, LV_SYMBOL_UP, &onNavigateUpPressedCallback, this); + navigate_up_button = lvgl::toolbar_add_image_button_action(toolbar, LV_SYMBOL_UP, &onNavigateUpPressedCallback, this); auto* wrapper = lv_obj_create(parent); lv_obj_set_width(wrapper, LV_PCT(100)); diff --git a/Tactility/Source/app/serialconsole/SerialConsole.cpp b/Tactility/Source/app/serialconsole/SerialConsole.cpp index d0ed2496..f756be23 100644 --- a/Tactility/Source/app/serialconsole/SerialConsole.cpp +++ b/Tactility/Source/app/serialconsole/SerialConsole.cpp @@ -65,7 +65,7 @@ public: auto* toolbar = lvgl::toolbar_create(parent, app); - disconnectButton = lvgl::toolbar_add_button_action(toolbar, LV_SYMBOL_POWER, onDisconnectPressed, this); + disconnectButton = lvgl::toolbar_add_image_button_action(toolbar, LV_SYMBOL_POWER, onDisconnectPressed, this); lv_obj_add_flag(disconnectButton, LV_OBJ_FLAG_HIDDEN); wrapperWidget = lv_obj_create(parent); diff --git a/Tactility/Source/lvgl/Toolbar.cpp b/Tactility/Source/lvgl/Toolbar.cpp index 308fe6e2..5047a9a5 100644 --- a/Tactility/Source/lvgl/Toolbar.cpp +++ b/Tactility/Source/lvgl/Toolbar.cpp @@ -158,7 +158,7 @@ void toolbar_set_nav_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callb lv_image_set_src(toolbar->close_button_image, icon); // e.g. LV_SYMBOL_CLOSE } -lv_obj_t* toolbar_add_button_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* imageOrButton, bool isImage, lv_event_cb_t callback, void* user_data) { auto* toolbar = reinterpret_cast(obj); tt_check(toolbar->action_count < TOOLBAR_ACTION_LIMIT, "max actions reached"); toolbar->action_count++; @@ -178,13 +178,27 @@ lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* icon, lv_event_cb lv_obj_align(action_button, LV_ALIGN_CENTER, 0, 0); lv_obj_add_event_cb(action_button, callback, LV_EVENT_SHORT_CLICKED, user_data); - lv_obj_t* action_button_image = lv_image_create(action_button); - lv_image_set_src(action_button_image, icon); - lv_obj_align(action_button_image, LV_ALIGN_CENTER, 0, 0); + lv_obj_t* button_content; + if (isImage) { + button_content = lv_image_create(action_button); + lv_image_set_src(button_content, imageOrButton); + } else { + button_content = lv_label_create(action_button); + lv_label_set_text(button_content, imageOrButton); + } + lv_obj_align(button_content, LV_ALIGN_CENTER, 0, 0); return action_button; } +lv_obj_t* toolbar_add_image_button_action(lv_obj_t* obj, const char* imagePath, lv_event_cb_t callback, void* user_data) { + return toolbar_add_button_action(obj, imagePath, true, callback, user_data); +} + +lv_obj_t* toolbar_add_text_button_action(lv_obj_t* obj, const char* text, lv_event_cb_t callback, void* user_data) { + return toolbar_add_button_action(obj, text, false, callback, user_data); +} + lv_obj_t* toolbar_add_switch_action(lv_obj_t* obj) { auto* toolbar = reinterpret_cast(obj); diff --git a/TactilityC/Include/tt_lvgl_toolbar.h b/TactilityC/Include/tt_lvgl_toolbar.h index 0cb88dd9..700b4d4a 100644 --- a/TactilityC/Include/tt_lvgl_toolbar.h +++ b/TactilityC/Include/tt_lvgl_toolbar.h @@ -14,7 +14,7 @@ lv_obj_t* tt_lvgl_toolbar_create_for_app(lv_obj_t* parent, AppHandle context); 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); +void tt_lvgl_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 @@ -22,31 +22,43 @@ void toolbar_set_title(lv_obj_t* obj, const char* title); * @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); +void tt_lvgl_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) + * Create and add an action button with an image 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] imagePath the path to an image file to shown 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 - * @return an instance created by lv_button_create() + * @param[in] callbackUserData the user data that is passed to the callback + * @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* callbackEventUserData); +lv_obj_t* tt_lvgl_toolbar_add_image_button_action(lv_obj_t* obj, const char* imagePath, lv_event_cb_t callback, void* callbackUserData); + +/** + * Create and add an action button with text to the toolbar (aligned to the right of the toolbar) + * @param[in] obj the toolbar instance + * @param[in] text the button text + * @param[in] callback the callback for the click action of the button + * @param[in] callbackUserData the user data that is passed to the callback + * @return an lv_button instance + + */ +lv_obj_t* tt_lvgl_toolbar_add_text_button_action(lv_obj_t* obj, const char* text, lv_event_cb_t callback, void* callbackUserData); /** * 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); +lv_obj_t* tt_lvgl_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); +lv_obj_t* tt_lvgl_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 7fcf6748..fb1ce6a9 100644 --- a/TactilityC/Source/tt_init.cpp +++ b/TactilityC/Source/tt_init.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,9 @@ const esp_elfsym main_symbols[] { ESP_ELFSYM_EXPORT(rand), ESP_ELFSYM_EXPORT(srand), ESP_ELFSYM_EXPORT(rand_r), + // esp random + ESP_ELFSYM_EXPORT(esp_random), + ESP_ELFSYM_EXPORT(esp_fill_random), // unistd.h ESP_ELFSYM_EXPORT(usleep), ESP_ELFSYM_EXPORT(sleep), @@ -233,6 +237,12 @@ const esp_elfsym main_symbols[] { ESP_ELFSYM_EXPORT(tt_lvgl_hardware_keyboard_set_indev), ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_create), ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_create_for_app), + ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_set_title), + ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_set_nav_action), + ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_add_image_button_action), + ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_add_text_button_action), + ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_add_switch_action), + ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_add_spinner_action), ESP_ELFSYM_EXPORT(tt_message_queue_alloc), ESP_ELFSYM_EXPORT(tt_message_queue_free), ESP_ELFSYM_EXPORT(tt_message_queue_put), @@ -488,6 +498,13 @@ const esp_elfsym main_symbols[] { ESP_ELFSYM_EXPORT(lv_spinbox_set_cursor_pos), ESP_ELFSYM_EXPORT(lv_spinbox_step_next), ESP_ELFSYM_EXPORT(lv_spinbox_step_prev), + // lv_indev + ESP_ELFSYM_EXPORT(lv_indev_get_type), + ESP_ELFSYM_EXPORT(lv_indev_get_point), + ESP_ELFSYM_EXPORT(lv_indev_get_display), + ESP_ELFSYM_EXPORT(lv_indev_get_key), + ESP_ELFSYM_EXPORT(lv_indev_get_gesture_dir), + ESP_ELFSYM_EXPORT(lv_indev_get_state), // delimiter ESP_ELFSYM_END }; diff --git a/TactilityC/Source/tt_lvgl_toolbar.cpp b/TactilityC/Source/tt_lvgl_toolbar.cpp index 532ae3ff..7c004929 100644 --- a/TactilityC/Source/tt_lvgl_toolbar.cpp +++ b/TactilityC/Source/tt_lvgl_toolbar.cpp @@ -11,23 +11,27 @@ 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) { +void tt_lvgl_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) { +void tt_lvgl_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* tt_lvgl_toolbar_add_image_button_action(lv_obj_t* obj, const char* imagePath, lv_event_cb_t callback, void* callbackUserData) { + return tt::lvgl::toolbar_add_image_button_action(obj, imagePath, callback, callbackUserData); } -lv_obj_t* toolbar_add_switch_action(lv_obj_t* obj) { +lv_obj_t* tt_lvgl_toolbar_add_text_button_action(lv_obj_t* obj, const char* text, lv_event_cb_t callback, void* callbackUserData) { + return tt::lvgl::toolbar_add_text_button_action(obj, text, callback, callbackUserData); +} + +lv_obj_t* tt_lvgl_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) { +lv_obj_t* tt_lvgl_toolbar_add_spinner_action(lv_obj_t* obj) { return tt::lvgl::toolbar_add_spinner_action(obj); }