I'm using D4D in an K22F, and have created a menu object INRAM. I can easily change the data that is displayed on this menu, but if I change the number of items in the list, the scroll bar never changes.
It appears that the range of the scroll bar is set during the initialization of the screen with no way to add or subtract from that range value for the life of the screen.
Can anyone tell me how I might be able to dynamically change the position count of that scroll bar so that the menu will display any new menu items?
Thanks,
Mike Thomas
Solved! Go to Solution.
Hello Mike,
As you may know, a list is declared and defined trough macros. I show an example below.
_D4D_DECLARE_COMBO_BOX_BEGIN(D4D_NO_CONST, grpBx_name, SET_OFFSET_X, SET_RB_POS_Y(0), SET_SIZE_CB_X, SET_SIZE_CB_Y, 68, SET_RADIUS, NULL, &scrSett_grpBx_name, D4D_COMBO_BOX_F_DEFAULT, NULL, FONT_SYSTEM, 20, 0, 0, NULL, ComboBoxName_OnChange, NULL)
D4D_DECLARE_COMBO_BOX_ITEM(D4D_DEFSTR("Example"), EXAMPLE)
D4D_DECLARE_COMBO_BOX_END()
If you expand these macros, you will see that the box items are stored in the array D4D_LIST_BOX_ITEM name##_items[] (where name## is replaced by the parameter name, in this case grpBx_name), this array ends with an item defined as NULL (D4D_DECLARE_COMBO_BOX_END() is expanded as { NULL, NULL} };) so if you want to add a new item dynamically you need to replace this NULL element and then add a new NULL one.
I am thinking in a workaround where in compile time you declare all the items you think you will need to reserve the memory and in execution time replace the memory for this items for NULL.
Best regards,
Earl.
Hello Mike,
As you may know, a list is declared and defined trough macros. I show an example below.
_D4D_DECLARE_COMBO_BOX_BEGIN(D4D_NO_CONST, grpBx_name, SET_OFFSET_X, SET_RB_POS_Y(0), SET_SIZE_CB_X, SET_SIZE_CB_Y, 68, SET_RADIUS, NULL, &scrSett_grpBx_name, D4D_COMBO_BOX_F_DEFAULT, NULL, FONT_SYSTEM, 20, 0, 0, NULL, ComboBoxName_OnChange, NULL)
D4D_DECLARE_COMBO_BOX_ITEM(D4D_DEFSTR("Example"), EXAMPLE)
D4D_DECLARE_COMBO_BOX_END()
If you expand these macros, you will see that the box items are stored in the array D4D_LIST_BOX_ITEM name##_items[] (where name## is replaced by the parameter name, in this case grpBx_name), this array ends with an item defined as NULL (D4D_DECLARE_COMBO_BOX_END() is expanded as { NULL, NULL} };) so if you want to add a new item dynamically you need to replace this NULL element and then add a new NULL one.
I am thinking in a workaround where in compile time you declare all the items you think you will need to reserve the memory and in execution time replace the memory for this items for NULL.
Best regards,
Earl.
This is the same conclusion that we arrived at. On startup, we calculate the number of items we will have in a menu, based on model information. We fill the default Menu item with some junk text so that the scroll bar will calculate the correct amount of menu items. Then we can later dynamically change the information on each line of the menu.