User:Compyx: Difference between revisions
(Start collection observations on the SDL UI code on my personal Wiki paga) |
|||
Line 1: | Line 1: | ||
= | = Personal notes, observations and rants = | ||
== SDL UI code == | |||
Since I'm tasked with updating the SDL code to use the generic UI actions and hotkeys code and use those UI actions from the menu items, hotkeys and custom joystick mappings, and the code is poorly documented, I'll be writing down some observations on how the SDL UI code works here. | |||
== | === Menu items === | ||
Menu items are defined with the type <b><tt>ui_menu_entry_t</tt></b> (in <tt>uimenu.h</tt>): | |||
<syntaxhighlight lang="C"> | |||
typedef struct ui_menu_entry_s { | |||
char *string; | |||
ui_menu_entry_type_t type; | |||
* | ui_callback_t callback; | ||
ui_callback_data_t data; | |||
ui_menu_status_type_t status; | |||
} ui_menu_entry_t; | |||
</syntaxhighlight> | |||
The <i><tt>string</tt></i> is used to display the item text in the menus. It is used by <tt>sdl_ui_display_item()</tt> to render a menu item. | |||
The <i><tt>type</tt></i> determines what to do when the user activates the item, types include radio buttons, toggle buttons, submenus, and dialogs. | |||
When an item is activated the <i><tt>callback</tt></i> is called with <i><tt>data</i></tt> as its argument. The return value of the <i><tt>callback</i></tt> (a <tt>const char*</tt>) is used to update the item's state or to exit the UI (more on that later). | |||
The <tt><i>status</tt></i> field is used for radio buttons to display the selection's state (or something like that). | |||
The | The various menu item types are defined as: | ||
<syntaxhighlight lang="C"> | |||
typedef enum { | |||
/* Text item (no operation): if data == 1 text colors are inverted */ | |||
MENU_ENTRY_TEXT = 0, | |||
* | /* Resource toggle: no UI needed, callback is used */ | ||
:: | MENU_ENTRY_RESOURCE_TOGGLE, | ||
/* Resource radio: no UI needed, callback is used, data is the resource value */ | |||
MENU_ENTRY_RESOURCE_RADIO, | |||
/* Resource int: needs UI, callback is used */ | |||
MENU_ENTRY_RESOURCE_INT, | |||
/* Resource string: needs UI, callback is used */ | |||
MENU_ENTRY_RESOURCE_STRING, | |||
/* Submenu: needs UI, data points to the submenu */ | |||
MENU_ENTRY_SUBMENU, | |||
/* Dynamic submenu: needs UI, data points to the submenu, hotkeys disabled */ | |||
MENU_ENTRY_DYNAMIC_SUBMENU, | |||
/* Custom dialog: needs UI */ | |||
MENU_ENTRY_DIALOG, | |||
/* Other: no UI needed */ | |||
MENU_ENTRY_OTHER, | |||
/* Other: no UI needed */ | |||
MENU_ENTRY_OTHER_TOGGLE | |||
} ui_menu_entry_type_t; | |||
</syntaxhighlight> |
Revision as of 21:55, 16 June 2023
Personal notes, observations and rants
SDL UI code
Since I'm tasked with updating the SDL code to use the generic UI actions and hotkeys code and use those UI actions from the menu items, hotkeys and custom joystick mappings, and the code is poorly documented, I'll be writing down some observations on how the SDL UI code works here.
Menu items
Menu items are defined with the type ui_menu_entry_t (in uimenu.h):
typedef struct ui_menu_entry_s {
char *string;
ui_menu_entry_type_t type;
ui_callback_t callback;
ui_callback_data_t data;
ui_menu_status_type_t status;
} ui_menu_entry_t;
The string is used to display the item text in the menus. It is used by sdl_ui_display_item() to render a menu item. The type determines what to do when the user activates the item, types include radio buttons, toggle buttons, submenus, and dialogs. When an item is activated the callback is called with data as its argument. The return value of the callback (a const char*) is used to update the item's state or to exit the UI (more on that later). The status field is used for radio buttons to display the selection's state (or something like that).
The various menu item types are defined as:
typedef enum {
/* Text item (no operation): if data == 1 text colors are inverted */
MENU_ENTRY_TEXT = 0,
/* Resource toggle: no UI needed, callback is used */
MENU_ENTRY_RESOURCE_TOGGLE,
/* Resource radio: no UI needed, callback is used, data is the resource value */
MENU_ENTRY_RESOURCE_RADIO,
/* Resource int: needs UI, callback is used */
MENU_ENTRY_RESOURCE_INT,
/* Resource string: needs UI, callback is used */
MENU_ENTRY_RESOURCE_STRING,
/* Submenu: needs UI, data points to the submenu */
MENU_ENTRY_SUBMENU,
/* Dynamic submenu: needs UI, data points to the submenu, hotkeys disabled */
MENU_ENTRY_DYNAMIC_SUBMENU,
/* Custom dialog: needs UI */
MENU_ENTRY_DIALOG,
/* Other: no UI needed */
MENU_ENTRY_OTHER,
/* Other: no UI needed */
MENU_ENTRY_OTHER_TOGGLE
} ui_menu_entry_type_t;