diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-12-15 00:37:04 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2022-01-01 23:56:51 -0500 |
commit | a7703e4926075ee41269ca96d1806444107e65f2 (patch) | |
tree | a9b5c6a5df97267c71b0c1ad0613ca0be0d66c4d /apps/plugins/rb_info.c | |
parent | edc68b06574b57684a7fad4263dd59eed7f65f2f (diff) | |
download | rockbox-a7703e4926075ee41269ca96d1806444107e65f2.tar.gz rockbox-a7703e4926075ee41269ca96d1806444107e65f2.zip |
gui lists add callback for owner drawn items
allow the guts of gui_sync_list to be used with owner drawn items
WIP
printcell_helper--
goal: allow data to be displayed in a spreadsheet format with an easy to use interface
printcell_set_columns(gui_synclist, title, icon)
sets title and calculates cell widths
each column is identified by '$' character
ex 3 columns title = "Col1$Col2$Col3"
also accepts $*WIDTH$
ex 3 columns varying width title = "$*64$Col1$*128$Col2$Col3
printcell_enable(gui_synclist, enable)
sets the printcell function enabled
After setting the columns and enabling the printcell function
items can be added to the list like normal
column items are supplied delimited by '$'
ex item = "Item1$item2$item3"
they will be placed in cells defined by set_columns and scroll if the cell is too small
--Fixed for 1 bit & 2 bit displays
Change-Id: I49bd7903005d7a54e93af4379b0cdea63c860656
Diffstat (limited to 'apps/plugins/rb_info.c')
-rw-r--r-- | apps/plugins/rb_info.c | 110 |
1 files changed, 93 insertions, 17 deletions
diff --git a/apps/plugins/rb_info.c b/apps/plugins/rb_info.c index f82c80c0cf..e0ec117dfb 100644 --- a/apps/plugins/rb_info.c +++ b/apps/plugins/rb_info.c | |||
@@ -29,8 +29,9 @@ | |||
29 | #include "lib/action_helper.h" | 29 | #include "lib/action_helper.h" |
30 | #include "lib/button_helper.h" | 30 | #include "lib/button_helper.h" |
31 | #include "lib/pluginlib_actions.h" | 31 | #include "lib/pluginlib_actions.h" |
32 | #include "lib/printcell_helper.h" | ||
32 | 33 | ||
33 | #define MENU_ID(x) (((void*)&"RPBUTACNGX\0" + x)) | 34 | #define MENU_ID(x) (((void*)&"RPBUTACNGSX\0" + x)) |
34 | enum { | 35 | enum { |
35 | M_ROOT = 0, | 36 | M_ROOT = 0, |
36 | M_PATHS, | 37 | M_PATHS, |
@@ -41,6 +42,7 @@ enum { | |||
41 | M_CONTEXTS, | 42 | M_CONTEXTS, |
42 | M_ACTTEST, | 43 | M_ACTTEST, |
43 | M_PLUGINS, | 44 | M_PLUGINS, |
45 | M_TESTPUT, | ||
44 | M_EXIT, | 46 | M_EXIT, |
45 | M_LAST_ITEM //ITEM COUNT | 47 | M_LAST_ITEM //ITEM COUNT |
46 | }; | 48 | }; |
@@ -96,7 +98,8 @@ static const struct paths paths[] = { | |||
96 | {"Fm Presets", ""FMPRESET_PATH}, | 98 | {"Fm Presets", ""FMPRESET_PATH}, |
97 | {"MAX_PATH", ""MACROVAL(MAX_PATH)" bytes"}, | 99 | {"MAX_PATH", ""MACROVAL(MAX_PATH)" bytes"}, |
98 | }; | 100 | }; |
99 | 101 | #define TESTPUT_HEADER "$*64$col1$col2$*128$col3$col4$col5$col6$*64$col7$col8" | |
102 | static int testput_cols = 0; | ||
100 | struct mainmenu { const char *name; void *menuid; int items;}; | 103 | struct mainmenu { const char *name; void *menuid; int items;}; |
101 | static struct mainmenu mainmenu[M_LAST_ITEM] = { | 104 | static struct mainmenu mainmenu[M_LAST_ITEM] = { |
102 | #define MENU_ITEM(ID, NAME, COUNT) [ID]{NAME, MENU_ID(ID), (int)COUNT} | 105 | #define MENU_ITEM(ID, NAME, COUNT) [ID]{NAME, MENU_ID(ID), (int)COUNT} |
@@ -109,6 +112,7 @@ MENU_ITEM(M_ACTIONS, "Actions", LAST_ACTION_PLACEHOLDER), | |||
109 | MENU_ITEM(M_CONTEXTS, "Contexts", LAST_CONTEXT_PLACEHOLDER ), | 112 | MENU_ITEM(M_CONTEXTS, "Contexts", LAST_CONTEXT_PLACEHOLDER ), |
110 | MENU_ITEM(M_ACTTEST, "Action test", 3), | 113 | MENU_ITEM(M_ACTTEST, "Action test", 3), |
111 | MENU_ITEM(M_PLUGINS, ID2P(LANG_PLUGINS), MENU_ID_PLUGINS_ITEMS), | 114 | MENU_ITEM(M_PLUGINS, ID2P(LANG_PLUGINS), MENU_ID_PLUGINS_ITEMS), |
115 | MENU_ITEM(M_TESTPUT, "Printcell test", 36), | ||
112 | MENU_ITEM(M_EXIT, ID2P(LANG_MENU_QUIT), 0), | 116 | MENU_ITEM(M_EXIT, ID2P(LANG_MENU_QUIT), 0), |
113 | #undef MENU_ITEM | 117 | #undef MENU_ITEM |
114 | }; | 118 | }; |
@@ -125,8 +129,16 @@ static const struct mainmenu *mainitem(int selected_item) | |||
125 | static void cleanup(void *parameter) | 129 | static void cleanup(void *parameter) |
126 | { | 130 | { |
127 | (void)parameter; | 131 | (void)parameter; |
132 | } | ||
128 | 133 | ||
134 | #if 0 | ||
135 | static enum themable_icons menu_icon_cb(int selected_item, void * data) | ||
136 | { | ||
137 | (void)data; | ||
138 | (void)selected_item; | ||
139 | return Icon_NOICON; | ||
129 | } | 140 | } |
141 | #endif | ||
130 | 142 | ||
131 | static const char *menu_plugin_name_cb(int selected_item, void* data, | 143 | static const char *menu_plugin_name_cb(int selected_item, void* data, |
132 | char* buf, size_t buf_len) | 144 | char* buf, size_t buf_len) |
@@ -247,7 +259,7 @@ static const char* list_get_name_cb(int selected_item, void* data, | |||
247 | buf[0] = '\0'; | 259 | buf[0] = '\0'; |
248 | if (data == MENU_ID(M_ROOT)) | 260 | if (data == MENU_ID(M_ROOT)) |
249 | return mainitem(selected_item)->name; | 261 | return mainitem(selected_item)->name; |
250 | else if (selected_item == 0) /*header text*/ | 262 | else if (selected_item == 0 && data != MENU_ID(M_TESTPUT)) /*header text*/ |
251 | return mainitem(main_last_sel)->name; | 263 | return mainitem(main_last_sel)->name; |
252 | else if (selected_item >= mainitem(main_last_sel)->items - 1) | 264 | else if (selected_item >= mainitem(main_last_sel)->items - 1) |
253 | return ID2P(LANG_BACK); | 265 | return ID2P(LANG_BACK); |
@@ -286,6 +298,11 @@ static const char* list_get_name_cb(int selected_item, void* data, | |||
286 | { | 298 | { |
287 | return menu_plugin_name_cb(selected_item - 1, data, buf, buf_len); | 299 | return menu_plugin_name_cb(selected_item - 1, data, buf, buf_len); |
288 | } | 300 | } |
301 | else if (data == MENU_ID(M_TESTPUT)) | ||
302 | { | ||
303 | rb->snprintf(buf, buf_len, "put_line item: [ %d ]$Text %d$Text LONGER TEST text %d $4$5$6$7$8$9", selected_item, 1, 2); | ||
304 | return buf; | ||
305 | } | ||
289 | return buf; | 306 | return buf; |
290 | } | 307 | } |
291 | 308 | ||
@@ -331,16 +348,38 @@ static int list_voice_cb(int list_index, void* data) | |||
331 | return 0; | 348 | return 0; |
332 | } | 349 | } |
333 | 350 | ||
334 | int menu_action_cb(int action, int selected_item, bool* exit, struct gui_synclist *lists) | 351 | int menu_action_cb(int *action, int selected_item, bool* exit, struct gui_synclist *lists) |
335 | { | 352 | { |
336 | if (lists->data == MENU_ID(M_ACTTEST)) | 353 | if (lists->data == MENU_ID(M_TESTPUT) && (selected_item < (mainitem(M_TESTPUT)->items) - 1)/*back*/) |
354 | { | ||
355 | if (*action == ACTION_STD_OK) | ||
356 | { | ||
357 | printcell_increment_column(lists, 1, true); | ||
358 | *action = ACTION_NONE; | ||
359 | } | ||
360 | else if (*action == ACTION_STD_CANCEL) | ||
361 | { | ||
362 | if (printcell_increment_column(lists, -1, true) != testput_cols - 1) | ||
363 | { | ||
364 | *action = ACTION_NONE; | ||
365 | } | ||
366 | } | ||
367 | else if (*action == ACTION_STD_CONTEXT) | ||
368 | { | ||
369 | char buf[PRINTCELL_MAXLINELEN]; | ||
370 | char* bufp = buf; | ||
371 | bufp = printcell_get_selected_column_text(lists, bufp, PRINTCELL_MAXLINELEN); | ||
372 | rb->splashf(HZ * 2, "Item: %s", bufp); | ||
373 | } | ||
374 | } | ||
375 | else if (lists->data == MENU_ID(M_ACTTEST)) | ||
337 | { | 376 | { |
338 | if (selected_item == 2) /* context */ | 377 | if (selected_item == 2) /* context */ |
339 | { | 378 | { |
340 | int ctx = m_test.context; | 379 | int ctx = m_test.context; |
341 | if (action == ACTION_STD_OK) | 380 | if (*action == ACTION_STD_OK) |
342 | m_test.context++; | 381 | m_test.context++; |
343 | else if (action == ACTION_STD_CANCEL) | 382 | else if (*action == ACTION_STD_CANCEL) |
344 | m_test.context--; | 383 | m_test.context--; |
345 | 384 | ||
346 | if (m_test.context < 0) | 385 | if (m_test.context < 0) |
@@ -353,7 +392,7 @@ int menu_action_cb(int action, int selected_item, bool* exit, struct gui_synclis | |||
353 | 392 | ||
354 | goto default_handler; | 393 | goto default_handler; |
355 | } | 394 | } |
356 | if (action == ACTION_STD_OK) | 395 | if (*action == ACTION_STD_OK) |
357 | { | 396 | { |
358 | if (selected_item == 1 || selected_item == 3) | 397 | if (selected_item == 1 || selected_item == 3) |
359 | { | 398 | { |
@@ -364,7 +403,7 @@ int menu_action_cb(int action, int selected_item, bool* exit, struct gui_synclis | |||
364 | } | 403 | } |
365 | else if (lists->data == MENU_ID(M_BTNTEST)) | 404 | else if (lists->data == MENU_ID(M_BTNTEST)) |
366 | { | 405 | { |
367 | if (action == ACTION_STD_OK) | 406 | if (*action == ACTION_STD_OK) |
368 | { | 407 | { |
369 | if (selected_item == 1 || selected_item == 2) | 408 | if (selected_item == 1 || selected_item == 2) |
370 | { | 409 | { |
@@ -373,18 +412,38 @@ int menu_action_cb(int action, int selected_item, bool* exit, struct gui_synclis | |||
373 | } | 412 | } |
374 | } | 413 | } |
375 | } | 414 | } |
376 | if (action == ACTION_STD_OK) | 415 | /* common */ |
416 | if (*action == ACTION_STD_OK) | ||
377 | { | 417 | { |
378 | if (lists->data == MENU_ID(M_ROOT)) | 418 | if (lists->data == MENU_ID(M_ROOT)) |
379 | { | 419 | { |
380 | rb->memset(&m_test, 0, sizeof(struct menu_test_t)); | 420 | rb->memset(&m_test, 0, sizeof(struct menu_test_t)); |
381 | const struct mainmenu *cur = mainitem(selected_item); | 421 | const struct mainmenu *cur = mainitem(selected_item); |
422 | |||
382 | if (cur->menuid == NULL || cur->menuid == MENU_ID(M_EXIT)) | 423 | if (cur->menuid == NULL || cur->menuid == MENU_ID(M_EXIT)) |
383 | *exit = true; | 424 | *exit = true; |
384 | else | 425 | else |
385 | { | 426 | { |
386 | main_last_sel = selected_item; | 427 | main_last_sel = selected_item; |
387 | synclist_set(cur->menuid, 1, cur->items, 1); | 428 | |
429 | if (cur->menuid == MENU_ID(M_TESTPUT)) | ||
430 | { | ||
431 | //rb->gui_list_screen_scroll_out_of_view(true); | ||
432 | synclist_set(cur->menuid, 0, cur->items, 1); | ||
433 | #if LCD_DEPTH > 1 | ||
434 | /* If line sep is set to automatic then outline cells */ | ||
435 | bool showlinesep = (rb->global_settings->list_separator_height < 0); | ||
436 | #else | ||
437 | bool showlinesep = (rb->global_settings->cursor_style == 0); | ||
438 | #endif | ||
439 | printcell_enable(lists, true, showlinesep); | ||
440 | //lists->callback_draw_item = test_listdraw_fn; | ||
441 | } | ||
442 | else | ||
443 | { | ||
444 | printcell_enable(lists, false, false); | ||
445 | synclist_set(cur->menuid, 1, cur->items, 1); | ||
446 | } | ||
388 | rb->gui_synclist_draw(lists); | 447 | rb->gui_synclist_draw(lists); |
389 | } | 448 | } |
390 | } | 449 | } |
@@ -394,7 +453,11 @@ int menu_action_cb(int action, int selected_item, bool* exit, struct gui_synclis | |||
394 | } | 453 | } |
395 | else if (selected_item >= (mainitem(main_last_sel)->items) - 1)/*back*/ | 454 | else if (selected_item >= (mainitem(main_last_sel)->items) - 1)/*back*/ |
396 | { | 455 | { |
397 | action = ACTION_STD_CANCEL; | 456 | *action = ACTION_STD_CANCEL; |
457 | } | ||
458 | else if (lists->data == MENU_ID(M_TESTPUT)) | ||
459 | { | ||
460 | |||
398 | } | 461 | } |
399 | else if (lists->data == MENU_ID(M_ACTIONS) || | 462 | else if (lists->data == MENU_ID(M_ACTIONS) || |
400 | lists->data == MENU_ID(M_CONTEXTS)) | 463 | lists->data == MENU_ID(M_CONTEXTS)) |
@@ -406,8 +469,14 @@ int menu_action_cb(int action, int selected_item, bool* exit, struct gui_synclis | |||
406 | rb->button_get(true); | 469 | rb->button_get(true); |
407 | } | 470 | } |
408 | } | 471 | } |
409 | if (action == ACTION_STD_CANCEL) | 472 | if (*action == ACTION_STD_CANCEL) |
410 | { | 473 | { |
474 | if (lists->data == MENU_ID(M_TESTPUT)) | ||
475 | { | ||
476 | //rb->gui_list_screen_scroll_out_of_view(false); | ||
477 | //lists->callback_draw_item = NULL; | ||
478 | printcell_enable(lists, false, false); | ||
479 | } | ||
411 | if (lists->data != MENU_ID(M_ROOT)) | 480 | if (lists->data != MENU_ID(M_ROOT)) |
412 | { | 481 | { |
413 | const struct mainmenu *mainm = &mainmenu[0]; | 482 | const struct mainmenu *mainm = &mainmenu[0]; |
@@ -418,7 +487,7 @@ int menu_action_cb(int action, int selected_item, bool* exit, struct gui_synclis | |||
418 | *exit = true; | 487 | *exit = true; |
419 | } | 488 | } |
420 | default_handler: | 489 | default_handler: |
421 | if (rb->default_event_handler_ex(action, cleanup, NULL) == SYS_USB_CONNECTED) | 490 | if (rb->default_event_handler_ex(*action, cleanup, NULL) == SYS_USB_CONNECTED) |
422 | { | 491 | { |
423 | *exit = true; | 492 | *exit = true; |
424 | return PLUGIN_USB_CONNECTED; | 493 | return PLUGIN_USB_CONNECTED; |
@@ -436,7 +505,14 @@ static void synclist_set(char* menu_id, int selected_item, int items, int sel_si | |||
436 | list_voice_cb(0, menu_id); | 505 | list_voice_cb(0, menu_id); |
437 | rb->gui_synclist_init(&lists,list_get_name_cb, | 506 | rb->gui_synclist_init(&lists,list_get_name_cb, |
438 | menu_id, false, sel_size, NULL); | 507 | menu_id, false, sel_size, NULL); |
439 | 508 | if (menu_id == MENU_ID(M_TESTPUT)) | |
509 | { | ||
510 | testput_cols = printcell_set_columns(&lists, TESTPUT_HEADER, Icon_Rockbox); | ||
511 | } | ||
512 | else | ||
513 | { | ||
514 | rb->gui_synclist_set_title(&lists, NULL,-1); | ||
515 | } | ||
440 | rb->gui_synclist_set_icon_callback(&lists,NULL); | 516 | rb->gui_synclist_set_icon_callback(&lists,NULL); |
441 | rb->gui_synclist_set_voice_callback(&lists, list_voice_cb); | 517 | rb->gui_synclist_set_voice_callback(&lists, list_voice_cb); |
442 | rb->gui_synclist_set_nb_items(&lists,items); | 518 | rb->gui_synclist_set_nb_items(&lists,items); |
@@ -460,7 +536,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
460 | /* add header and back item to each submenu */ | 536 | /* add header and back item to each submenu */ |
461 | for (int i = 1; i < M_LAST_ITEM; i++) | 537 | for (int i = 1; i < M_LAST_ITEM; i++) |
462 | mainmenu[i].items += 2; | 538 | mainmenu[i].items += 2; |
463 | 539 | mainmenu[M_TESTPUT].items -= 1; | |
464 | if (!exit) | 540 | if (!exit) |
465 | { | 541 | { |
466 | const struct mainmenu *mainm = &mainmenu[0]; | 542 | const struct mainmenu *mainm = &mainmenu[0]; |
@@ -483,10 +559,10 @@ enum plugin_status plugin_start(const void* parameter) | |||
483 | } | 559 | } |
484 | else | 560 | else |
485 | redraw = true; | 561 | redraw = true; |
562 | ret = menu_action_cb(&action, selected_item, &exit, &lists); | ||
486 | if (rb->gui_synclist_do_button(&lists,&action,LIST_WRAP_UNLESS_HELD)) | 563 | if (rb->gui_synclist_do_button(&lists,&action,LIST_WRAP_UNLESS_HELD)) |
487 | continue; | 564 | continue; |
488 | selected_item = rb->gui_synclist_get_sel_pos(&lists); | 565 | selected_item = rb->gui_synclist_get_sel_pos(&lists); |
489 | ret = menu_action_cb(action, selected_item, &exit, &lists); | ||
490 | } | 566 | } |
491 | } | 567 | } |
492 | 568 | ||