Popup menu and ticks
Chris Mahoney (1684) 2165 posts |
Hi, I’m using the Toolbox and am trying to make a popup menu similar to Configure>Keyboard, where you click on the popup menu and select an option. This results in the selected item appearing in the display field, and the relevant option becoming ticked in the menu. I’ve filled my menu with tickable items, and am running the following code on Menu_Selection: int menu_id; char menu_text[50]; popup_get_menu(0, id_block->parent_id, component_id_of_popup, &menu_id); menu_get_entry_text(0, menu_id, id_block->self_component, menu_text, 50, 0); displayfield_set_value(0, id_block->parent_id, component_id_of_displayfield, menu_text); That displays the selected item in the display field, but naturally it doesn’t change the ticks at all. I’ve added this line: menu_set_tick(0, menu_id, id_block->self_component, 1); This ticks the selected item, but doesn’t untick anything. Therefore, as you change your menu selection, you end up with more and more items becoming ticked. I only want the latest one to show up. What’s the easiest way to accomplish this? I could enumerate through all of the items and untick them one by one, but that seems inefficient. Is there a better way to accomplish this? Thanks :) |
William Harden (2174) 244 posts |
Use the combined display field and stringset if you can – this handles this particular issue for you. If you can’t use that for whatever reason, have an int of id_block→self_component, called my_menu_selection (other variable names may apply). Start it with an invalid number (-1), or your default value if you have one. Ensure you receive the menu_selection event (so ensure you’ve declared that you’re listening for it on initialise, check that your objects are flagged to send the message and then you have registered a handler for your menu selection. Then in the menu_selection code you want to de_select the current value of my_menu_selection, then set my_menu_selection to be id_block→self_component. Ideally use one code file per window, and that file declares a series of ints and values with the current UI state in them. This reduces the need to call a load of SWIs to look up the UI state (and particularly calling them iteratively): just listen for events which would change the UI state and update them accordingly. Hope that helps. |
Mike Freestone (2564) 131 posts |
Can you just remember what the last setting was? menu_untick(setting) assuming only 1 entry can be ticked at a time |
Chris Mahoney (1684) 2165 posts |
I wasn’t aware that such a thing existed. It looks like I’ll be poking around a bit when I get home :) Other than that, thanks for the suggestions. Remembering the previous selection had occurred to me, but I apparently wasn’t thinking straight because for some reason I thought it wouldn’t work! |
Chris Mahoney (1684) 2165 posts |
Naturally I opened up ResEd to find “String set” staring me in the face. Thanks again for the tip! |