Key Pages

Projects

I think that with the right mega-widget framework it might also be possible to create a proc that produces scrollable widgets:

etc. For example, with BWidgets, you can do the following:

 package require BWidget 
 proc scroll { w args } {
    eval [linsert $args 0 ScrolledWindow $w#box]
    $w#box configure -borderwidth [$w cget -borderwidth] -relief [$w cget -relief]
    $w configure -borderwidth 0
    $w#box setwidget $w
    raise $w
    return $w#box
 } 
 pack [scroll [text .t -width 5 -height 3  -wrap no]] -fill both -expand yes
.t insert end "a1234567\nb\nc\nd\ne\nf\ng\n"


Posted at Aug 10/2003 09:52 AM:
Joe English: Tk's scrollbar protocol is simple enough that you _almost_ don't need a separate megawidget for this (it's only about twice as much work to create and hook up static scrollbars in plain Tcl than it takes to use the BWidget ScrolScrolledWindow, for instance).

This works OK for widgets with built-in scrolling (listbox, text, canvas); the major exception is scrolled frames containing a large gridded layout. The usual trick -- create a window canvas item and scroll the canvas -- has a number of drawbacks. Keyboard traversal to obscured subwidgets doesn't autoscroll like it should, it's very difficult to ensure that the viewport aligns with the underlying grid (so the topmost/leftmost widgets are often only partially visible), and the code required to set this up _is_ complicated enough that a megawidget is justified.

(I'll also add that, in my experience, scrolled frames are _usually_ best avoided: if you've got that many widgets to display in a single window, it's usually better to organize them into panes or some other hierarchical container. But sometimes this just isn't possible; for these cases a ScrolledGrid manager would be very useful.)


Posted at Aug 10/2003 01:05 PM:
As Alex Liebowitz points out on the wiki, scroll bars should appear in the same border as the widget they are scrolling[link], so the above code does not give proper Windows look and feel. The advantage of not rolling your own scroll bars is that these sorts of details could be managed by the scroll wrapper. I've added code to the above BWidget example to do this. There is still a look and feel issue with the BWidget auto-scrollbars. In windows apps the horizontal scrollbar is visible if any line is wider than the viewable area, not any visible line.


Posted at Aug 21/2003 02:07 PM:
Paul Kienzle: I fixed the example above so that the scroll bars and the widget are in the same relief frame (and tested it this time!). I also extended it so that it would accept extra arguments such as -scrollbar vertical

On unix, you have to go to some effort to remove the trough relief from the scrollbars, adding the following after creating ScrolledWindow:

    $w#box.hscroll configure -borderwidth 0 -elementborderwidth 1
    $w#box.vscroll configure -borderwidth 0 -elementborderwidth 1

I think it looks a bit better with the sunken trough, but all three ways are a bit ugly (separate relief, shared relief with flat trough, shared relief with sunken trough). Windows ignores the borderwidth options, so it doesn't matter which options we use for unix.



Forum Home  -  Site Home  -  Find Pages: