Hi! finally finished making TUI menus for my app. I had some difficulties with menu sizing and accounting for borders and style while making it but when I finally figured out that issue it was pretty straightforward to implement everything.
What was interesting about all of this
In this part of development I’m really understanding the difficulties of creating things we take for granted, like menus or just simple boxes of text, implementing menu scrolling and other types of utilities to make them usable was a pain for sure, but it was also interesting to see my changes in code affecting something as immediate as graphics (well TUI graphics but still graphics non the less). This is the first time i programmed something that could be seen and used and it’s honestly pretty sweet.
The stars of the show
All this time I spent working on this was to implement mainly three functions: create_menu_handle, draw_menu and menu_driver, those three functions regulate how the menu looks, feels, and takes input:
menu_handle_t* create_menu_handle(WINDOW* parent,
const char* menu_label,
point_t pos,
int max_height,
int pad_y,
int pad_x,
int n_options,
const char** option_labels,
void (**opt_funcs)(void*),
void **opt_args,
chtype menu_attrs,
chtype menu_color,
chtype highlight_attrs,
chtype highlight_color,
int inside_shading,
enum MenuBorderTypes border,
int mouse_enabled);
this is a beefy boy (look at all those parameters) but it’s pretty configurable and allows some real customization of your menu! It calculates available option space from the max height, and implements scrolling automatically
int draw_menu(menu_handle_t* menu);
Pretty much self explanatory, draws the menu and its borders.
int menu_driver(menu_handle_t* menu, int input_type, MEVENT* mouse);
Really cool function that given an input handles option selection/scrolling mechanics and highlighting of the selected option.