CENTERING TEXT [message #13059] |
Fri, 02 October 1998 00:00  |
dsheerin
Messages: 8 Registered: June 1998
|
Junior Member |
|
|
Hi
Can anyone tell me how to center text in a text widget?
Thanks for any help received.
David
|
|
|
Re: CENTERING TEXT [message #13122 is a reply to message #13059] |
Wed, 07 October 1998 00:00  |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
David Fanning wrote:
>
> Phillip David (pdavid@earthling.net) writes:
>
>> If you really want to do this, the answer is simple. Just don't use a
>> proportionally spaced font.
>
> I hate to keep harping on this, but sometimes the simple
> answers are the hardest to implement. :-)
>
> I would send a book (of your choice and my modest means)
> to anyone who can reliably center text in a text widget
> using *any* kind of text. :-)
Maybe I'm missing something, but I seem to be able to center
non-proportional-font text just fine with CENTER_TEXT.PRO .
I've included it here (again). Prove me wrong. Make my day...
Dave
;=========================================================== =====
; CENTER_TEXT.PRO 10-02-98 DSFoster
;
; Procedure to center a message within a text widget.
PRO center_text, text_wid, message
if (widget_info(text_wid, /valid_id) eq 0) then begin
message, 'Invalid widget identifier: ' + strmid(text_wid,2), /info
endif else if (widget_info(text_wid, /name) ne 'TEXT') then begin
message, 'Widget ID not a text widget: ' + strmid(text_wid,2), /info
endif else if (n_params() lt 2) then begin
message, 'Missing required parameters', /info
endif else begin
geom = widget_info(text_wid, /geometry)
xsize = round(geom.xsize) ; Size of text widget in chars
ok = execute( "str = string(' ', format='(a" + $
strtrim(xsize,2) + ")')" )
start = 0 > round((xsize - strlen(message))/2)
strput, str, message, start
widget_control, text_wid, set_value=str
endelse
return
END
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|