[comp.windows.x.motif] centering widgets

ctday@lbl.gov (Christopher T. Day) (11/19/90)

Is it possible to center a widget in a resizable area using one of the standard
Motif widgets?  I would like to replicate the window resize behavior of the
three default buttons of a message dialog, but I can't figure out how to
center the middle button.  I don't want the buttons themselves to change size,
just the space between them.  My various attempts with Form widgets have all
failed so far.  (Buttons change size, circular constraints, not accurately
centered, edge of button positioned instead of center of button, etc.)  Help
appreciated.

Chris

colin@nbc1.ge.com (Colin Rafferty) (11/29/90)

In article <1990Nov18.103134@lbl.gov> ctday@lbl.gov (Christopher T. Day) writes:

> Is it possible to center a widget in a resizable area using one of
> the standard Motif widgets?
> ....I don't
> want the buttons themselves to change size, just the space between
> them. 

I tried to figure this one out, and it is possible using the form
widget.  The real trick is to have what I call a "Spot" which is
placed where you want the center of the button, and then the button is
placed around it.

Here is a simple uil module to do it.  No C, since I haven't seen a
reason to write an interface in C yet.

---------------- begin uil ----------------

module center
    version = 'V1.0'
    names = case_sensitive

value buttonWidth : 150;
value buttonHeight : 50;

object Form : XmForm widget {
    arguments {
	XmNwidth = buttonWidth;
	XmNheight = buttonHeight;
    };
    controls {
	XmSeparator Spot;
	XmPushButton Button;
    };
};

object Button : XmPushButton widget {
    arguments {
	XmNfontList = Bigfont;
	XmNlabelString = 'Centered';
	XmNleftAttachment = XmATTACH_WIDGET;
	XmNleftWidget = XmSeparator Spot;
	XmNleftOffset = - (buttonWidth / 2);
	XmNrightAttachment = XmATTACH_WIDGET;
	XmNrightWidget = XmSeparator Spot;
	XmNrightOffset = - (buttonWidth / 2);
	XmNtopAttachment = XmATTACH_WIDGET;
	XmNtopWidget = XmSeparator Spot;
	XmNtopOffset = - (buttonHeight / 2);
	XmNbottomAttachment = XmATTACH_WIDGET;
	XmNbottomWidget = XmSeparator Spot;
	XmNbottomOffset = - (buttonHeight / 2);
    };
};

object Spot : XmSeparator widget {
    arguments {
	XmNseparatorType = XmNO_LINE;
	XmNleftAttachment = XmATTACH_POSITION;
	XmNleftPosition = 50;
	XmNrightAttachment = XmATTACH_POSITION;
	XmNrightPosition = 50;
	XmNtopAttachment = XmATTACH_POSITION;
	XmNtopPosition = 50;
	XmNbottomAttachment = XmATTACH_POSITION;
	XmNbottomPosition = 50;
    };
};

end module;

---------------- end uil ----------------

  //=====================================\/==============================\\
  ||       Colin Owen Rafferty           ||  "Life is so complex, parts  ||
  ||        colin@nbc1.ge.com            ||   of it must be imaginary."  ||
  || {philabs,crdgw1,ge-dab}!nbc1!colin  ||               -Tim Thiel     ||
  \\=====================================/\==============================//

wohler@sapwdf.UUCP (Bill Wohler) (05/23/91)

  i can't believe that there isn't a way to center one, two or more
  widgets within another widget.

  i'd like to place one or more buttons horizontally within a row-column
  widget and then center the row-column widget horizontally within a
  wider widget.  alternatively, i would like to evenly space these
  buttons horizontally across the wider widget.

  i would appreciate any pointers to get me started...
-- 
						--bw
-----
Bill Wohler <wohler@sap-ag.de> <sapwdf!wohler>
Heidelberg Red Barons Ultimate Frisbee Team