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 */