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

Re: Widget width in vertical base



David Fanning wrote:

> 
> I should think the work-around is to resize them
> at the same time you resize the draw widget. :-)
> 

Hi David, it all sounds good, but in practice, fails
to work.  At least on my platform.

Here is a sample program (just a slightly modified
version of an example program showing how resize events
on a tlb with a menubar give the wrong size - well, give
the size including the menubar (I don't think it's wrong))

Anyway, in this program, when you make the window smaller,
all looks OK, when you make the window larger, the horizontal
size of the scroll bar never exceeds its initial value.
If you get the geometry (using widget_info) it will tell
you that the slider is the correct size.  In fact, if you leave
out all size stuff on the slider, widget_info will tell
you that the slider has resized itself to be the same size as the
draw widget - but visually, that's not the case - it only ever
gets as large as it's initial setting.


NOTE: after playing with it, I think I may have just
found a workaround, and that is to initially set the
size of the slider to a very large value (larger than
the width of the screen) and then, before realizing the
widgets, use widget_control, to set the width of the slider
to its desired value.  Afterwards, setting the size to
anything smaller than the initial (very large) value works
OK

-------------------------------------------------------

pro slider_event, event
end

PRO RESIZE_EVENT, EVENT

  ;;- Get info structure

  widget_control, event.top, get_uvalue=info

  ;;- 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

  ;;- turn off updates to resize widgets
  widget_control, info.drawid, update=0

  ;;- Resize the slider
  widget_control, info.slider, xsize=info.draw_xsize

  ;;- Resize the draw widget

  widget_control, info.drawid, $
   draw_xsize=info.draw_xsize, draw_ysize=info.draw_ysize
  
  ;;- turn on updates after widgets are resized
  widget_control, info.drawid, update=1

  ;;- Display a plot

  plot, indgen(10)

END

;;----------------------------------------------------------------
PRO slider

  ;;- Check keywords

  ;;- Set initial size of draw widget

  draw_xsize = 400
  draw_ysize = 400

  ;;- Create base widget with menubar and draw widget

  tlb = widget_base( title='Slider Resize Example', $
                     tlb_size_events=1, mbar=menubase, /column )

  slider = widget_slider(tlb, xsize=draw_xsize,
event_pro='slider_event')

  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 = { drawid     : drawid, $
           slider     : slider, $
           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