Re: Two widget questions [message #17712] |
Mon, 08 November 1999 00:00 |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
pln@egret1.stanford.edu (Patrick L. Nolan) writes:
>
> 2. My base window contains a menu bar, a scrolling list, and a draw
> widget. I want to handle resize events properly. At first I resized
> the draw widget to event.x and event.y. This doesn't work properly
> because of the space occupied by the menu bar and list. The user
> moves the window corner to the desired place, and then the thing
> grows a bit. By experimenting I found approximately how much padding
> is required to make it come out right, but this is a very fragile
> solution.
>
> So far I haven't found a reliable solution. I have been trying to
> use widget_info(/geometry) and widget_control,/tlb_get_size to
> find the actual sizes of the draw and base widgets before and after
> the resize. Unfortunately the results don't seem to be reliable, or
> I just don't understand how to interpret them. Indeed, the manual
> says that widget_info(/geometry) returns an incorrect value if there
> is a menu bar.
>
> Is there some general way to deal with this? Have I just missed
> the proper section in the book?
I never found a textbook way to solve this problem. The resizing bug
is truly a nuisance. Here is my best solution:
1. Create an encapsulating top level base with xpad=0 ypad=0 and then
put your practical top level base within that. Example:
tlb0 = widget_base(column=1, tlb_size_events=1, xpad=0, ypad=0)
tlb = widget_base(tlb0, column=1)
... fill up the tlb base ...
This doesn't work if you insist on a top-level menu. You can
create an IDL menu under tlb if you need to.
However, this seems to take care of the growing widget problem.
The rest of the steps are optional if you decide to add a menu
widget.
2. Create a menu if you need it under tlb.
3. Realize the widget and get the size of the menu.
4. If needed, enlarge the window to fully encompass the menu.
5. When resize events come, resize the widget taking into account the
menu size.
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Two widget questions [message #17713 is a reply to message #17712] |
Mon, 08 November 1999 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Patrick L. Nolan (pln@egret1.stanford.edu) writes:
> I'm back with more questions about my first widget program.
> My first question about flashing colors was solved nicely. Now
> I'm getting into more advanced details.
Oh, boy, this is great. :-)
> 1. Is it possible to have exclusive button under a menu bar?
No, it is not possible.
> I tried putting a widget_base,/exclusive or a cw_bgroup as
> children of a menu bar button. In both cases it told me that
> the parent was the wrong type.
Exactly. About the best you can do is have some
visual way of indicating the menu item is selected.
For example, you can put an asterisk in front of
selected items. Here is a small example of how to
do something like this:
************************************************************ ************
PRO Example_Button_Events, event
Widget_Control, event.id, Get_Value=buttonValue, Get_UValue=buttonUValue
Widget_Control, event.id, Set_Value=buttonUValue, Set_UValue=buttonValue
END
PRO EXAMPLE
tlb = Widget_Base(Column=1, Title='Make a Choice...')
selectID = Widget_Button(tlb, Value='Animal Selections...', /Menu, $
Event_Pro='Example_Button_Events', Scr_XSize=200)
choice1 = Widget_Button(selectID, Value='Choose Dogs', /Menu)
button = Widget_Button(choice1, Value='Retriever', UValue='* Retriever')
button = Widget_Button(choice1, Value='Boxer', UValue='* Boxer')
button = Widget_Button(choice1, Value='Great Dane', UValue='* Great Dane')
choice2 = Widget_Button(selectID, Value='Choose Cows', /Menu)
button = Widget_Button(choice2, Value='Holstein', UValue='* Holstein')
button = Widget_Button(choice2, Value='Angus', UValue='* Angus')
button = Widget_Button(choice2, Value='Jersey', UValue='* Jersey')
Widget_Control, tlb, /Realize
XManager, 'example', tlb, /No_Block
END
************************************************************ ************
> 2. My base window contains a menu bar, a scrolling list, and a draw
> widget. I want to handle resize events properly.
> Is there some general way to deal with this? Have I just missed
> the proper section in the book?
Uh, I'm sure it's in my book...somewhere. At least it *should*
be. :-(
Here is what I would do. Just before I realize the TLB
I would find out what size it is:
tlb_geom = Widget_Info(tlb, /Geometry)
I would use the screen X and Y sizes here. What I want to know
is how much space in my top-level base is NOT composed of the
draw widget.
draw_geom = Widget_Info(drawID, /Geometry)
extraXpixels = tlb_geom.scr_xsize - draw_geom.scr_xsize
extraYpixels = tlb_geom.scr_ysize - draw_geom.scr_ysize
Now, I would save these numbers in my info structure so that
when I do the resize I can do something like this:
Widget_Control, info.drawID, Draw_XSize=event.x - info.extraXpixels $
Draw_YSize=event.y - info.extraYpixels
This leaves enough space for the other widgets that are still in the
top-level base and doesn't change their position or size.
Sadly, you sometimes still need a "fudge" factor on various platforms,
since the reporting of sizes is not totally consistent from one platform
to another. Test it on all the computers you expect to run on. Something
like this usually works OK.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|