TactilityC and Toolbar improvements (#355)

This commit is contained in:
Ken Van Hoeylandt
2025-10-02 23:40:40 +02:00
committed by GitHub
parent b214a3358e
commit 00347cbd29
8 changed files with 83 additions and 26 deletions
+14 -4
View File
@@ -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.
+1 -1
View File
@@ -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));
+1 -1
View File
@@ -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));
@@ -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);
+18 -4
View File
@@ -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<Toolbar*>(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<Toolbar*>(obj);