[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

TLB Widget resizing




In case you can't tell, I'm trying my hand at some more widget
programming and I am rusty.

One nice thing about widgets is that you can make them resizeable.
You can ask for resize events by setting the TLB_SIZE_EVENTS keyword
to WIDGET_BASE.  Then you are supposed to get a nice little widget
event whenever it changes in size.

Okay, we also know about the bug in IDL's widgets, which can cause
funny resizing behavior.  I refer the kind reader to David Fanning's
nice redux of the situation.

http://www.dfanning.com/idl5_info/tlb_resize_problem.html

I have a different question however.  There appear to be times when
you can resize a window to *smaller* than it is supposed to be.  That
is, try to resize a window so that there is no way for all of the
component widgets to fit.

In that case, you do get a resize event which describes the size of
the new, small window.  For a moment on my Linux screen, the window
does get smaller.  However, IDL smartly decides that the component
widgets can't fit inside, and the window "bounces" back to a larger
size.  It grows to a new size -- BUT a resize event is NEVER SENT.

Who cares right?  Well, I have a draw widget that is resized based on
the (incorrect) numbers in the resize event.  When the window
"bounces" to a new size, the resulting draw widget looks pretty goofy.
You can reproduce this in David Fanning (and my) XWINDOW program, and
also with the following RESIZE program, based on work by Liam Gumley.
Just run it, and resize the window to a very small width. 

Can anybody suggest a way to get a new resize event?  I have
considered requesting a timer event to periodically adjust the draw
widget's dimensions.

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------

;; ----------   BEGIN RESIZE.PRO
;;  Adapted from Liam Gumley's routine of the same name
PRO RESIZE_EVENT, EVENT

;- Get info structure

widget_control, event.top, get_uvalue=info

;- Resize the draw widget using one of two methods

case info.fix of

  ;- First method: widget grows vertically
  
  0 : widget_control, info.drawid, xsize=event.x, ysize=event.y

  ;- Second method: resizes widget correctly
  
  1 : begin
  
    ;- Get current tlb size

    widget_control, event.top, tlb_get_size=result
    tlb_xsize = result[0]
    tlb_ysize = result[1]

    ;- Compute difference between current and old tlb size

    xdiff = tlb_xsize - info.tlb_xsize
    ydiff = tlb_ysize - info.tlb_ysize

    ;- Set new tlb size

    info.tlb_xsize = tlb_xsize
    info.tlb_ysize = tlb_ysize   

    ;- Set new draw widget size

    info.draw_xsize = info.draw_xsize + xdiff
    info.draw_ysize = info.draw_ysize + ydiff

    ;- Resize the draw widget

    widget_control, info.drawid, $
      draw_xsize=info.draw_xsize, draw_ysize=info.draw_ysize

  end
  
endcase

;- Display a plot

plot, indgen(10)

END

;----------------------------------------------------------------
PRO RESIZE, FIX=FIX

;- Check keywords

if not keyword_set( fix ) then fix = 0

;- Set initial size of draw widget

draw_xsize = 400
draw_ysize = 400

;- Create base widget with menubar and draw widget

tlb = widget_base( title='Resize Example', $
  tlb_size_events=1, mbar=menubase, column=1 )
buttonbar = widget_base(tlb, row=1, /align_left)
button1 = widget_button(buttonbar, value='Button1')
button2 = widget_button(buttonbar, value='Button2')
drawid = widget_draw( tlb, xsize=draw_xsize, ysize=draw_ysize )
widget_control, tlb, /realize

;- Display a plot

plot, indgen(10)

;- Get size of top level base

widget_control, tlb, tlb_get_size=result
tlb_xsize = result[0]
tlb_ysize = result[1]

;- Create and store info structure

info = { fix        : fix, $
         drawid     : drawid, $
         draw_xsize : draw_xsize, $
         draw_ysize : draw_ysize, $
         tlb_xsize  : tlb_xsize, $
         tlb_ysize  : tlb_ysize }
widget_control, tlb, set_uvalue = info

;- Manage widget events

xmanager, 'resize', tlb

END