Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!elroy.jpl.nasa.gov!decwrl!adobe!baer From: baer@adobe.com (Larry Baer) Newsgroups: comp.windows.x.motif Subject: Re: Aligning side-by-side RowColumn widgets Keywords: RowColumn Message-ID: <9881@adobe.UUCP> Date: 10 Jan 91 22:33:03 GMT References: <2506@apctrc.UUCP> <1991Jan10.153947.20059@convex.com> Sender: news@adobe.COM Reply-To: baer@adobe.COM (Larry Baer) Organization: Adobe Systems Incorporated, Mountain View Lines: 250 Joe M. Wade writes: >.... What I'm trying to do is this: > >label1 text >label2 text >label3 text >label4 text >label5 toggle >etc.. > >The problem arises from the fact that the text widgets are larger than >the label widgets. ... My approach to this has been to make sure that both RowColumns have the same margins and spacing, and that the corresponding widgets in each RowColumn have the same total height, figuring in margins, shadows, fontheight, etc. Then let the RowColumns do the positioning by themselves, and everything lines up. I've appended below a modified version of Mr. Wade's original program, together with a couple of choices of resource specifications that give the desired result. This appears to work in Motif 1.0 and Motif 1.1. I use XmPACK_TIGHT on rowcol1, to force all labels to be full-width, so that entryAlignment of XmALIGNMENT_END is meaningful. I am interested in hearing criticism of this approach, and other ways of achieving the effect. --Larry Baer (baer@adobe.com) Adobe Systems Incorporated ==========================Test.c========================================= #include #include #include #include #include #include #include #include char *labels[] = { "labelA","labelB","labelC","labelD", "labelE - with this extra garbage" }; char *text[] = { "entryA","entryB","entryC","entryD" }; void popup(widget,client_data,call_data) Widget widget; caddr_t client_data; caddr_t call_data; { XtManageChild((Widget)client_data); } void popdown(widget,client_data,call_data) Widget widget; caddr_t client_data; caddr_t call_data; { XtUnmanageChild((Widget)client_data); } void killit(widget,client_data,call_data) Widget widget; caddr_t client_data; caddr_t call_data; { exit(0); } main (argc,argv) int argc; char *argv[]; { Arg args[5]; Widget root,trigger,dismiss,quit; Widget form,rowcol1,rowcol2,label_widget[5],text_widget[4],toggle; int i,nargs,spacing,height[5],y_offset; XmString item_label; root = XtInitialize(NULL, "Test", NULL, 0, &argc, argv); trigger = XmCreatePushButton(root,"trigger",NULL,0); XtManageChild(trigger); nargs = 0; XtSetArg(args[nargs],XmNmappedWhenManaged,FALSE); nargs++; form = XmCreateFormDialog(root,"form",args,nargs); XtAddCallback(trigger, XmNactivateCallback, popup, (caddr_t) form); nargs = 0; XtSetArg(args[nargs],XmNpacking, XmPACK_TIGHT); nargs++; XtSetArg(args[nargs],XmNorientation,XmVERTICAL); nargs++; XtSetArg(args[nargs],XmNentryAlignment,XmALIGNMENT_END); nargs++; XtSetArg(args[nargs],XmNisAligned,TRUE); nargs++; rowcol1 = XmCreateRowColumn(form,"rowcol1",args,nargs); nargs = 0; XtSetArg(args[nargs],XmNleftAttachment,XmATTACH_WIDGET); nargs++; XtSetArg(args[nargs],XmNleftWidget,rowcol1); nargs++; rowcol2 = XmCreateRowColumn(form,"rowcol2",args,nargs); for (i=0; i<4; i++) { nargs = 0; XtSetArg(args[nargs],XmNvalue,text[i]); nargs++; text_widget[i] = XmCreateText(rowcol2,text[i],args,nargs); } XtManageChildren(text_widget, 4); nargs = 0; item_label = XmStringCreateLtoR("Yes",XmSTRING_DEFAULT_CHARSET); XtSetArg(args[nargs],XmNlabelString,item_label); nargs++; XtSetArg(args[nargs],XmNset,TRUE); nargs++; toggle = XmCreateToggleButton(rowcol2,"toggle",args,nargs); XtManageChild(toggle); XtManageChild(rowcol2); nargs = 0; XtSetArg(args[nargs],XmNmappedWhenManaged,TRUE); nargs++; XtSetValues(form,args,nargs); for (i=0; i<5; i++) { nargs = 0; item_label = XmStringCreateLtoR(labels[i],XmSTRING_DEFAULT_CHARSET); XtSetArg(args[nargs],XmNlabelString,item_label); nargs++; label_widget[i] = XmCreateLabel(rowcol1,labels[i],args,nargs); } XtManageChildren(label_widget, 5); XtManageChild(rowcol1); nargs = 0; XtSetArg(args[nargs],XmNtopAttachment,XmATTACH_WIDGET); nargs++; XtSetArg(args[nargs],XmNtopWidget,rowcol2); nargs++; dismiss = XmCreatePushButton(form,"dismiss",args,nargs); XtAddCallback(dismiss, XmNactivateCallback, popdown, (caddr_t) form); XtManageChild(dismiss); nargs = 0; XtSetArg(args[nargs],XmNtopAttachment,XmATTACH_WIDGET); nargs++; XtSetArg(args[nargs],XmNtopWidget,rowcol2); nargs++; XtSetArg(args[nargs],XmNleftAttachment,XmATTACH_WIDGET); nargs++; XtSetArg(args[nargs],XmNleftWidget,dismiss); nargs++; quit = XmCreatePushButton(form,"quit",args,nargs); XtAddCallback(quit, XmNactivateCallback, killit, NULL); XtManageChild(quit); XtRealizeWidget(root); XtMainLoop(); } ====================Resource Sample 1==================================== !! Height of XmLabel == fontHeight + 2 * ( borderWidth !! + highlightThickness !! + shadowThickness !! + marginHeight !! ) !! Height of XmText == fontHeight + 2 * ( borderWidth !! + highlightThickness !! + shadowThickness !! + marginHeight !! ) !! Height of XmToggle == max(fontHeight, indicatorSize) + 2 * ( borderWidth !! + highlightThickness !! + shadowThickness !! + marginHeight !! ) Test*traversalOn: true Test*XmLabel.borderWidth: 0 Test*XmLabel.highlightThickness: 0 Test*XmLabel.shadowThickness: 0 Test*XmLabel.marginHeight: 9 Test*XmToggleButton.borderWidth: 0 Test*XmToggleButton.highlightThickness: 2 Test*XmToggleButton.shadowThickness: 0 Test*XmToggleButton.marginHeight: 7 Test*XmText.borderWidth: 0 Test*XmText.highlightThickness: 2 Test*XmText.shadowThickness: 2 Test*XmText.marginHeight: 5 ====================Resource Sample 2==================================== ! Labels get big font, texts get smaller font Test*fontList: fg-22 Test*traversalOn: true Test*XmLabel.borderWidth: 0 Test*XmLabel.highlightThickness: 0 Test*XmLabel.shadowThickness: 0 Test*XmLabel.marginHeight: 6 Test*XmToggleButton.borderWidth: 0 Test*XmToggleButton.highlightThickness: 2 Test*XmToggleButton.shadowThickness: 0 Test*XmToggleButton.marginHeight: 4 Test*XmText.borderWidth: 0 Test*XmText.highlightThickness: 2 Test*XmText.shadowThickness: 2 Test*XmText.marginHeight: 5 Test*XmText.fontList: fg-16 ====================Resource Sample 3==================================== ! draw thin boxes around lables Test*traversalOn: true Test*XmLabel.borderWidth: 1 Test*XmLabel.highlightThickness: 0 Test*XmLabel.shadowThickness: 0 Test*XmLabel.marginHeight: 8 Test*XmToggleButton.borderWidth: 0 Test*XmToggleButton.highlightThickness: 2 Test*XmToggleButton.shadowThickness: 0 Test*XmToggleButton.marginHeight: 7 Test*XmText.borderWidth: 0 Test*XmText.highlightThickness: 2 Test*XmText.shadowThickness: 2 Test*XmText.marginHeight: 5 ====================Resource Sample 4==================================== ! Make ALL widgets have a shadow thickness of 2 (including XmLabels and ! XmToggleButtons. Make ALL widgets have topShadowColor of white and ! bottomShadowColor of black. With Motif 1.0, XmLabel's shadows are ! invisible, but geometry is correct. With Motif 1.1, XmLabel's shadows ! are invisible and XmToggleButton appears too large. I think this is ! a Motif bug. Test*traversalOn: true Test*shadowThickness: 2 Test*topShadowColor: white Test*bottomShadowColor: black Test*XmLabel.borderWidth: 1 Test*XmLabel.highlightThickness: 0 Test*XmLabel.marginHeight: 8 Test*XmToggleButton.borderWidth: 0 Test*XmToggleButton.highlightThickness: 2 Test*XmToggleButton.marginHeight: 7 Test*XmText.borderWidth: 0 Test*XmText.highlightThickness: 2 Test*XmText.marginHeight: 5