MCPcopy Create free account
hub / github.com/NetHack/NetHack / menu_win_size

Function menu_win_size

win/curses/cursdial.c:1031–1129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1029/* Determine dimensions of menu window based on term size and entries */
1030
1031static void
1032menu_win_size(nhmenu *menu)
1033{
1034 int maxwidth, maxheight, curentrywidth, lastline;
1035 int maxentrywidth = 0;
1036 int maxheaderwidth = menu->prompt ? (int) strlen(menu->prompt) : 0;
1037 nhmenu_item *menu_item_ptr, *last_item_ptr = NULL;
1038 boolean only_if_no_headers = (iflags.menuobjsyms & 4) != 0;
1039
1040 /* check entire menu rather than one page at a time */
1041 menu->show_obj_syms = iflags.use_menu_glyphs;
1042 if (only_if_no_headers) {
1043 for (menu_item_ptr = menu->entries; menu_item_ptr != NULL;
1044 menu_item_ptr = menu_item_ptr->next_item)
1045 if (menu_item_ptr->identifier.a_void == 0) {
1046 menu->show_obj_syms = FALSE;
1047 break;
1048 }
1049 }
1050
1051#if 0 /* maxwidth is set below, so the value calculated here isn't used */
1052 if (program_state.gameover) {
1053 /* for final inventory disclosure, use full width */
1054 maxwidth = term_cols - 2; /* +2: borders assumed */
1055 } else {
1056 /* this used to be 38, which is 80/2 - 2 (half a 'normal' sized
1057 screen minus room for a border box), but some data files
1058 have been manually formatted for 80 columns (usually limited
1059 to 78 but sometimes 79, rarely 80 itself) and using a value
1060 less that 40 meant that a full line would wrap twice:
1061 1..38, 39..76, and 77..80 */
1062 maxwidth = 40; /* Reasonable minimum usable width */
1063 if ((term_cols / 2) > maxwidth)
1064 maxwidth = (term_cols / 2); /* Half the screen */
1065 }
1066#endif
1067 maxheight = menu_max_height();
1068
1069 /* First, determine the width of the longest menu entry */
1070 assert(menu->entries != NULL); /* at least one iteration will occur */
1071 for (menu_item_ptr = menu->entries; menu_item_ptr != NULL;
1072 menu_item_ptr = menu_item_ptr->next_item) {
1073 curentrywidth = (int) strlen(menu_item_ptr->str);
1074 if (menu_item_ptr->identifier.a_void == NULL) {
1075 if (curentrywidth > maxheaderwidth) {
1076 maxheaderwidth = curentrywidth;
1077 }
1078 } else {
1079 /* Add space for accelerator (selector letter) */
1080 curentrywidth += 4;
1081 if (menu_item_ptr->glyphinfo.glyph != NO_GLYPH
1082 && menu->show_obj_syms)
1083 curentrywidth += 2;
1084 }
1085 if (curentrywidth > maxentrywidth) {
1086 maxentrywidth = curentrywidth;
1087 }
1088

Callers 2

curses_display_nhmenuFunction · 0.85

Calls 2

menu_max_heightFunction · 0.85
menu_is_multipageFunction · 0.85

Tested by

no test coverage detected