From db32a639a7a4dc603c6f81e0959ce0165b451576 Mon Sep 17 00:00:00 2001 From: Ray Chason Date: Thu, 20 Aug 2026 01:56:58 -0400 Subject: [PATCH] Extend last column to end of line If a line in the menu has fewer columns than the others, the last one is deemed to extend to the right margin, and does not count toward the maximum width of that column. Also, revert the change to NetHack.font_menu. --- win/X11/NetHack.ad | 2 +- win/X11/winlabel.c | 10 +++++----- win/X11/winmenu.c | 12 +++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/win/X11/NetHack.ad b/win/X11/NetHack.ad index 10f1e7a73..f12110f6f 100644 --- a/win/X11/NetHack.ad +++ b/win/X11/NetHack.ad @@ -31,7 +31,7 @@ NetHack*text*borderWidth: 0 ! These correspond to the .nethackrc settings font_map, font_menu, ! font_message, font_status and font_text NetHack.font_map: mono-10 -NetHack.font_menu: sans-10 +NetHack.font_menu: mono-10 NetHack.font_message: sans-10 NetHack.font_status: sans-10 NetHack.font_text: mono-10 diff --git a/win/X11/winlabel.c b/win/X11/winlabel.c index 075346dde..2f9e5e68c 100644 --- a/win/X11/winlabel.c +++ b/win/X11/winlabel.c @@ -185,11 +185,11 @@ X11_set_column_widths(Widget w, const int *col_widths, unsigned num_cols) WidgetData *data = get_widget_data(w); if (data != NULL) { free(data->columns); - data->columns = (int *) alloc(sizeof(data->columns[0]) * num_cols); + data->columns = (int *) alloc(sizeof(data->columns[0]) * (num_cols + 1)); + data->columns[0] = 0; if (num_cols != 0) { - data->columns[0] = 0; - for (unsigned i = 1; i < num_cols; ++i) { - data->columns[i] = data->columns[i-1] + col_widths[i-1]; + for (unsigned i = 0; i < num_cols; ++i) { + data->columns[i+1] = data->columns[i] + col_widths[i]; } } data->num_cols = num_cols; @@ -421,7 +421,7 @@ update_label(Widget w, WidgetData *data) pos = 0; } else { line3 = min(strcspn(label + i + j, "\t\n"), line2); - pos = data->columns[min(col, data->num_cols-1)]; + pos = data->columns[min(col, data->num_cols)]; } #ifdef USE_XFT XftDrawString8(draw, &fgcolor, font, x + pos, y, diff --git a/win/X11/winmenu.c b/win/X11/winmenu.c index 7b8b3450c..e8d0eead2 100644 --- a/win/X11/winmenu.c +++ b/win/X11/winmenu.c @@ -1471,13 +1471,15 @@ menu_create_entries(struct xwindow *wp, struct menu *curr_menu) } /* Determine widths of columns */ +/* The last column is deemed to extend to the right margin, and is not included + in the returned array */ static unsigned get_col_widths(Widget w, X11_Font *font, const char *str, int **col_widths) { int col_spacing = X11_column_width(XtDisplay(w), font, "# ", 2); /* Determine the number of columns */ - unsigned num_cols = 1; + unsigned num_cols = 0; size_t i = 0; while (str[i] != '\0') { size_t len = strcspn(str + i, "\t"); @@ -1497,16 +1499,16 @@ get_col_widths(Widget w, X11_Font *font, const char *str, int **col_widths) i = 0; while (str[i] != '\0') { size_t len = strcspn(str + i, "\t"); + if (str[i+len] == '\0') { + break; + } cwidths[col] = X11_column_width(XtDisplay(w), font, str + i, len); if (len > 1) { col_spacing = X11_font_height(font) * 2; } cwidths[col] += col_spacing; ++col; - i += len; - if (str[i] == '\t') { - ++i; - } + i += len + 1; } /* Return */