Widget Placement [message #12748] |
Fri, 04 September 1998 00:00  |
Bernard Puc
Messages: 65 Registered: January 1998
|
Member |
|
|
Is there a neat way of locating a widget to appear flush against the
bottom and right edge of the screen? By neat I mean without having
to calculate the x and y dimensions of the widget and figuring out
the offsets.
Thanks.
--
Bernard Puc
AETC, INC
(703) 413-0500
bpuc@va.aetc.com
|
|
|
Re: Widget Placement [message #12816 is a reply to message #12748] |
Tue, 08 September 1998 00:00  |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
Bernard Puc wrote:
>
> Is there a neat way of locating a widget to appear flush against the
> bottom and right edge of the screen? By neat I mean without having
> to calculate the x and y dimensions of the widget and figuring out
> the offsets.
>
Bernard -
You might find my routine POS_WIDGET() useful. This routine positions
a widget relative to a parent widget, and there are options for
(1) centering; (2) cascading; and (3) positioning to the right,
relative to the parent widget. You could easily enhance this so
that the child is positioned at any corner of the screen you like.
I've included the source and a doc file below. Hope this is helpful.
Of course, there is no elegant way of accounting for those nasty
borders. You might try inserting a "fudge factor" (oh the humanity!...).
Dave
;=========================================================== =========
; POS_WIDGET.PRO 5-21-97 DSFoster
;
; Function to position a widget onscreen according to the following:
;
; If a valid parent widget is provided, center the widget
; within the parent widget. Otherwise, place the widget at the
; center of the screen. In both cases, account for the size of
; the widget to be positioned. Also, ensure that the widget
; is completely visible.
;
; This function may be called before or after a widget has been
; realized.
;
; Modifications:
;
; 5-21-97 DSF Created.
;
FUNCTION pos_widget, base, parent=parent, no_offset=no_offset, $
cascade=cascade, right=right
status = 0
if ( widget_info(long(base), /valid_id ) eq 0 ) then begin
message, 'Invalid widget ID specified', /continued
status = -1
endif else begin
device , get_screen_size=s_size ; Screen size
geom = widget_info( base, /geometry )
b_size = [ geom.scr_xsize + (2 * geom.margin), $ ; Size of widget
geom.scr_ysize + (2 * geom.margin) ]
if (keyword_set(PARENT)) then begin ; Center within parent
if ( widget_info(parent, /valid_id) ne 1 ) then begin
message, 'Keyword PARENT not a valid widget ID', /continue
xpos = s_size(0)/2 - b_size(0)/2
ypos = s_size(1)/2 - b_size(1)/2
endif else begin
geom = widget_info( parent, /geometry )
; Position of parent
p_offset = [ geom.xoffset, geom.yoffset ]
p_size = [ geom.scr_xsize + (2 * geom.margin), $
geom.scr_ysize + (2 * geom.margin) ]
if (keyword_set(CASCADE)) then begin
xpos = p_offset(0) + p_size(0)/5
ypos = p_offset(1) + p_size(1)/5
endif else if (keyword_set(RIGHT)) then begin
xpos = p_offset(0) + p_size(0)
ypos = p_offset(1) + p_size(1)/2 - b_size(1)/2
endif else begin
xpos = p_offset(0) + p_size(0)/2 - b_size(0)/2
ypos = p_offset(1) + p_size(1)/2 - b_size(1)/2
endelse
endelse
endif else if (keyword_set(NO_OFFSET)) then begin
xpos = 1
ypos = 1
endif else begin
xpos = s_size(0)/2 - b_size(0)/2
ypos = s_size(1)/2 - b_size(1)/2
endelse
; Make sure widget is entirely visible
xpos = ( 1 > xpos ) < (s_size(0) - b_size(0))
ypos = ( 1 > ypos ) < (s_size(1) - b_size(1))
widget_control, base, tlb_set_xoffset=xpos, tlb_set_yoffset=ypos
endelse
return, status
END
;=========== End of POS_WIDGET.PRO ==================================
;=========== POS_WIDGET.DOC =========================================
POS_WIDGET
Function to position a widget onscreen, before or after the
widget has been realized. The widget is positioned according
to the following:
If a valid parent widget is provided, center the widget
within the parent widget. Otherwise, place the widget at the
center of the screen. In both cases, account for the size of
the widget to be positioned. Also, ensure that the widget
is completely visible.
Other positioning options are available via keywords. This routine
always ensures that the widget will be entirely visible on-screen.
Calling Sequence
Status = POS_WIDGET( Base_wid )
Arguments
Base_wid
The top-level-base (TLB) of the widget to be positioned.
All child widgets must have been created; however,
POS_WIDGET may be called before or after the TLB
has been realized.
Keywords
CASCADE
Set this keyword to have the child widget positioned
"down and to the right" of the parent widget, by an
offset equal to 1/5th the size of the parent widget.
This allows a sequence of child widgets to be "cascaded".
NO_OFFSET
Set this keyword when the widget is to have to offset,
meaning that it is positioned in the upper left corner
of the screen.
RIGHT
Set this keyword to have the child widget positioned
just to the right of the parent widget (no overlap).
PARENT
Set this keyword to the TLB of a parent widget within which
the widget will be centered. If this parent is not a valid
widget, the widget is positioned in the center of the screen.
Outputs
Returns -1 if an invalid widget ID is specified for Base_wid,
otherwise returns 0.
Example
<create TLB widget Base and create its child widgets>
ret = pos_widget( Base, parent=parent ) ; Position the widget
widget_control, Base, /realize ; Realize the widget
;======== End of POS_WIDGET.DOC ======================================
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|