| 177 | } |
| 178 | |
| 179 | lv_obj_t* toolbar_add_button_action(lv_obj_t* obj, const char* imageOrButton, bool isImage, lv_event_cb_t callback, void* user_data) { |
| 180 | auto* toolbar = reinterpret_cast<Toolbar*>(obj); |
| 181 | check(toolbar->action_count < TOOLBAR_ACTION_LIMIT, "max actions reached"); |
| 182 | toolbar->action_count++; |
| 183 | |
| 184 | auto ui_density = lvgl_get_ui_density(); |
| 185 | auto toolbar_height = getToolbarHeight(ui_density); |
| 186 | |
| 187 | auto* wrapper = create_action_wrapper(toolbar->action_container, ui_density); |
| 188 | |
| 189 | auto padding = getActionIconPadding(ui_density); |
| 190 | |
| 191 | lv_obj_t* action_button = lv_button_create(wrapper); |
| 192 | lv_obj_set_size(action_button, toolbar_height - padding, toolbar_height - padding); |
| 193 | lv_obj_set_style_pad_all(action_button, 0, LV_STATE_DEFAULT); |
| 194 | lv_obj_align(action_button, LV_ALIGN_CENTER, 0, 0); |
| 195 | if (ui_density == LVGL_UI_DENSITY_COMPACT) { |
| 196 | lv_obj_set_style_bg_opa(action_button, LV_OPA_TRANSP, LV_STATE_DEFAULT); |
| 197 | } |
| 198 | |
| 199 | lv_obj_add_event_cb(action_button, callback, LV_EVENT_SHORT_CLICKED, user_data); |
| 200 | lv_obj_t* button_content; |
| 201 | if (isImage) { |
| 202 | button_content = lv_image_create(action_button); |
| 203 | lv_image_set_src(button_content, imageOrButton); |
| 204 | } else { |
| 205 | button_content = lv_label_create(action_button); |
| 206 | lv_label_set_text(button_content, imageOrButton); |
| 207 | } |
| 208 | lv_obj_align(button_content, LV_ALIGN_CENTER, 0, 0); |
| 209 | |
| 210 | return action_button; |
| 211 | } |
| 212 | |
| 213 | lv_obj_t* toolbar_add_image_button_action(lv_obj_t* obj, const char* imagePath, lv_event_cb_t callback, void* user_data) { |
| 214 | return toolbar_add_button_action(obj, imagePath, true, callback, user_data); |
no test coverage detected