Merge branch 'menu-columns' of https://github.com/chasonr/NetHack into NetHack-5.0

This commit is contained in:
nhmall
2026-08-24 07:28:33 -04:00
7 changed files with 56 additions and 29 deletions
+13 -5
View File
@@ -165,7 +165,7 @@ NetHackQtMenuWindow::NetHackQtMenuWindow(QWidget *parent) :
{
// setFont() was in SelectMenu(), in time to be rendered but too late
// when measuring the width and height that will be needed
QFont tablefont(qt_settings->normalFixedFont());
QFont tablefont(qt_settings->normalFont());
table->setFont(tablefont);
QGridLayout *grid = new QGridLayout();
@@ -400,9 +400,8 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
continue;
// determine column widths of sub-fields within description
QStringList columns = itemlist[row].str.split("\t");
for (int fld = 0; fld < (int) columns.size(); ++fld) {
bool lastcol = (fld == (int) columns.size() - 1);
int w = fm.QFM_WIDTH(columns[fld] + (lastcol ? "" : " "));
for (int fld = 0; fld < (int) columns.size() - 1; ++fld) {
int w = fm.QFM_WIDTH(columns[fld] + " ");
if (fld >= (int) col_widths.size()) {
col_widths.push_back(w); // add another element
} else if (col_widths[fld] < w) {
@@ -432,12 +431,21 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
continue;
QString text = twi->text();
if (split_descr) {
static const QChar u_200A(0x200A); // U+200A HAIR SPACE
QStringList columns = text.split("\t");
int spc0020_width = fm.QFM_WIDTH(" ");
int spc200A_width = fm.QFM_WIDTH(u_200A);
// Track errors in column widths and adjust subsequent columns so
// that these errors do not accumulate across a row
int error = 0;
for (int fld = 0; fld < (int) columns.size() - 1; ++fld) {
//columns[fld] += "\t"; /* (used to pad with tabs) */
int width = col_widths[fld];
while (fm.QFM_WIDTH(columns[fld]) < width)
while (fm.QFM_WIDTH(columns[fld]) + error + spc0020_width <= width)
columns[fld] += " "; //"\t";
while (fm.QFM_WIDTH(columns[fld]) + error + spc200A_width/2 < width)
columns[fld] += u_200A;
error += fm.QFM_WIDTH(columns[fld]) - width;
}
text = columns.join("");
twi->setText(text);
+1 -1
View File
@@ -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: mono-10
NetHack.font_menu: sans-10
NetHack.font_message: sans-10
NetHack.font_status: sans-10
NetHack.font_text: mono-10
+14 -8
View File
@@ -684,11 +684,16 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
DrawText(hDC, NH_A2W(p1, wbuf, BUFSZ), strlen(p1), &drawRect,
DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_EXPANDTABS
| DT_SINGLELINE);
data->menui.menu.tab_stop_size[column] =
max(data->menui.menu.tab_stop_size[column],
drawRect.right - drawRect.left);
menuitemwidth += data->menui.menu.tab_stop_size[column];
int width = drawRect.right - drawRect.left;
/* The last column overhangs any subsequent columns in other
lines */
if (p != NULL) {
data->menui.menu.tab_stop_size[column] =
max(data->menui.menu.tab_stop_size[column], width);
menuitemwidth += data->menui.menu.tab_stop_size[column];
} else {
menuitemwidth += width;
}
if (p != NULL)
*p = '\t';
@@ -1182,7 +1187,8 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
p = strchr(item->str, '\t');
column = 0;
SetRect(&drawRect, x, lpdis->rcItem.top,
min(x + data->menui.menu.tab_stop_size[0], lpdis->rcItem.right),
p != NULL ? x + data->menui.menu.tab_stop_size[0]
: lpdis->rcItem.right,
lpdis->rcItem.bottom);
for (;;) {
TCHAR wbuf2[BUFSZ];
@@ -1199,8 +1205,8 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
p = strchr(p1, '\t');
drawRect.left = drawRect.right + TAB_SEPARATION;
++column;
drawRect.right = min(drawRect.left + data->menui.menu.tab_stop_size[column],
lpdis->rcItem.right);
drawRect.right = p != NULL ? drawRect.left + data->menui.menu.tab_stop_size[column]
: lpdis->rcItem.right;
}
/* draw focused item */