From: H.G. Muller Date: Sat, 11 Feb 2012 10:53:39 +0000 (+0100) Subject: Better solution to button-height problem X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=8494f25d6daad56084a6a6f677980cb4f94efde0;p=xboard.git Better solution to button-height problem In stead of adapting the height of text widgets to that of buttons, (as represented by the message widget), we now do the opposite, and adapt the button & label heights. This is made safe by obtaining textHeight from the fontSet's max_logical_extent, though an XExtendsFontSet() call. Turns out the default height of text widgets is not exactly that, but 4 pixels larger for borders and margin. The parameter XtNvertDistance is now used to align the checkboxes with the following text widget, and their size is derived from textHeight as well. The XtNvertDistance is set to -1 for the lower spin button, so that it its border coincides with that of the upper spin button. Their height is set to textHeight/2. This makes their combined height just 1 pixel more than that of the preceeding text widget. (Uh? 2 x tw/2 -1 > tw?), so for other buttons we use that too (i.e. textHeight = font_extent + 5). --- diff --git a/xboard.c b/xboard.c index 270295d..f9ba5cc 100644 --- a/xboard.c +++ b/xboard.c @@ -2175,10 +2175,13 @@ XBoard square size (hint): %d\n\ /* For the coordFont, use the 0th font of the fontset. */ XFontSet coordFontSet = CreateFontSet(appData.coordFont); XFontStruct **font_struct_list; + XFontSetExtents *fontSize; char **font_name_list; XFontsOfFontSet(coordFontSet, &font_struct_list, &font_name_list); coordFontID = XLoadFont(xDisplay, font_name_list[0]); coordFontStruct = XQueryFont(xDisplay, coordFontID); + fontSize = XExtentsOfFontSet(fontSet); // [HGM] figure out how much vertical space font takes + textHeight = fontSize->max_logical_extent.height + 5; // add borderWidth } #else appData.font = FindFont(appData.font, fontPxlSize); @@ -2460,8 +2463,8 @@ XBoard square size (hint): %d\n\ fprintf(stderr, _("%s: messageWidget geometry error %d %d %d %d %d\n"), programName, gres, w, h, wr, hr); } - textHeight = hr; // [HGM] save height for use in generic popup /* !! end hack */ + if(!textHeight) textHeight = hr; // [HGM] if !NLS textHeight is still undefined, and we grab it from here XtSetArg(args[0], XtNleft, XtChainLeft); // [HGM] glue ends for good run-time sizing XtSetArg(args[1], XtNright, XtChainRight); XtSetValues(messageWidget, args, 2); diff --git a/xoptions.c b/xoptions.c index 7de5912..d640e62 100644 --- a/xoptions.c +++ b/xoptions.c @@ -1095,9 +1095,8 @@ GenericPopUp (Option *option, char *title, int dlgNr) XtSetArg(args[j], XtNfromHoriz, dialog); j++; XtSetArg(args[j], XtNborderWidth, 1); j++; XtSetArg(args[j], XtNwidth, w); j++; - XtSetArg(args[j], XtNheight, textHeight); j++; // [HGM] use message widget if(option[i].type == TextBox && option[i].min) { - XtSetArg(args[j-1], XtNheight, option[i].min); // overwrite + XtSetArg(args[j], XtNheight, option[i].min); j++; if(option[i].value & 1) { XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways); j++; } if(option[i].value & 2) { XtSetArg(args[j], XtNscrollHorizontal, XawtextScrollAlways); j++; } if(option[i].value & 4) { XtSetArg(args[j], XtNautoFill, True); j++; } @@ -1131,9 +1130,10 @@ GenericPopUp (Option *option, char *title, int dlgNr) msg = _("browse"); w = 0; /* automatically scale to width of text */ XtSetArg(args[j], XtNwidth, (XtArgVal) NULL ); j++; + if(textHeight) XtSetArg(args[j], XtNheight, textHeight), j++; } else { w = 20; msg = "+"; - XtSetArg(args[j], XtNheight, 10); j++; + XtSetArg(args[j], XtNheight, textHeight/2); j++; XtSetArg(args[j], XtNwidth, w); j++; } edit = XtCreateManagedWidget(msg, commandWidgetClass, form, args, j); @@ -1145,7 +1145,8 @@ GenericPopUp (Option *option, char *title, int dlgNr) j=0; XtSetArg(args[j], XtNfromVert, edit); j++; XtSetArg(args[j], XtNfromHoriz, last); j++; - XtSetArg(args[j], XtNheight, 10); j++; + XtSetArg(args[j], XtNvertDistance, -1); j++; + XtSetArg(args[j], XtNheight, textHeight/2); j++; XtSetArg(args[j], XtNwidth, 20); j++; XtSetArg(args[j], XtNleft, XtChainRight); j++; XtSetArg(args[j], XtNright, XtChainRight); j++; @@ -1154,6 +1155,7 @@ GenericPopUp (Option *option, char *title, int dlgNr) break; case CheckBox: if(!currentCps) option[i].value = *(Boolean*)option[i].target; +#if 0 j=0; // space holder XtSetArg(args[j], XtNfromVert, last); j++; XtSetArg(args[j], XtNwidth, 10); j++; @@ -1163,10 +1165,12 @@ GenericPopUp (Option *option, char *title, int dlgNr) XtSetArg(args[j], XtNborderWidth, 0); j++; if(textHeight < 24) dialog = last; else dialog = XtCreateManagedWidget(" ", labelWidgetClass, form, args, j); +#endif j=0; - XtSetArg(args[j], XtNfromVert, dialog); j++; - XtSetArg(args[j], XtNwidth, 10); j++; - XtSetArg(args[j], XtNheight, 10); j++; + XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNvertDistance, (textHeight+2)/4 + 3); j++; + XtSetArg(args[j], XtNwidth, textHeight/2); j++; + XtSetArg(args[j], XtNheight, textHeight/2); j++; XtSetArg(args[j], XtNleft, XtChainLeft); j++; XtSetArg(args[j], XtNright, XtChainLeft); j++; XtSetArg(args[j], XtNstate, option[i].value); j++; @@ -1179,6 +1183,7 @@ GenericPopUp (Option *option, char *title, int dlgNr) j=0; XtSetArg(args[j], XtNfromVert, last); j++; XtSetArg(args[j], XtNfromHoriz, option[i].type != Label ? dialog : NULL); j++; + XtSetArg(args[j], XtNheight, textHeight); j++; XtSetArg(args[j], XtNleft, XtChainLeft); j++; XtSetArg(args[j], XtNborderWidth, 0); j++; XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; @@ -1198,6 +1203,7 @@ GenericPopUp (Option *option, char *title, int dlgNr) XtSetArg(args[j], XtNfromHoriz, NULL); j++; lastrow = forelast; } XtSetArg(args[j], XtNlabel, _(option[i].name)); j++; + if(textHeight) XtSetArg(args[j], XtNheight, textHeight), j++; if(option[i].max) { XtSetArg(args[j], XtNwidth, option[i].max); j++; } if(option[i].textValue) { // special for buttons of New Variant dialog XtSetArg(args[j], XtNsensitive, appData.noChessProgram || option[i].value < 0 @@ -1238,6 +1244,7 @@ GenericPopUp (Option *option, char *title, int dlgNr) XtSetArg(args[j], XtNleft, XtChainLeft); j++; XtSetArg(args[j], XtNmenuName, XtNewString(option[i].name)); j++; XtSetArg(args[j], XtNlabel, _(((char**)option[i].textValue)[option[i].value])); j++; + if(textHeight) XtSetArg(args[j], XtNheight, textHeight), j++; option[i].handle = (void*) (last = XtCreateManagedWidget(" ", menuButtonWidgetClass, form, args, j)); CreateComboPopup(last, option + i, i); @@ -1325,6 +1332,7 @@ GenericPopUp (Option *option, char *title, int dlgNr) XtSetArg(args[j], XtNtop, XtChainBottom); j++; XtSetArg(args[j], XtNleft, XtChainRight); j++; XtSetArg(args[j], XtNright, XtChainRight); j++; + if(textHeight) XtSetArg(args[j], XtNheight, textHeight), j++; b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j); XtAddCallback(b_ok, XtNcallback, GenericCallback, (XtPointer)(intptr_t) dlgNr + (dlgNr<<16));