Tk Library Source Code

View Ticket
Login
Ticket UUID: 1731101
Title: ScrollableFrame invalid scrollbar
Type: Patch Version: None
Submitter: nobody Created on: 2007-06-05 00:34:34
Subsystem: bwidget Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-06-16 22:09:46
Resolution: Works For Me Closed By: oehhar
    Closed on: 2009-06-16 15:09:46
Description:
Hi,
I've had quite an annoying bug with Bwidget's ScrollableFrame. Whenever we have data in the frame that doesn't need a scrollbar, at first, there is no scrollbar, but if we resize the window to give it a smaller size, then a scrollbar appears even though it is still not needed. Clicking on the scrollbar will make it disappear instantly. 
In other words, you create a toplevel of size 500x500, you put a ScrollableFrame in a ScrolledWindow in it, you put widgets in the ScrollableFrame where the internal frame takes 100x100, no scrollbar needed, if we resize the toplevel to 400x400 for example, then a scrollbar appear even though it shouldn't until the size gets under 100x100. Clicking on the scrollbar makes it disappear, if we resize again to 300x300, it appears again. If we resize to 500x500, no scrollbar, if we resize again to 400x400, still no scrollbar.

I found out the reason behind this. It's pretty simple. The ScrollableFrame is in fact a canvas which contains a frame. This allows the scrollbar to work with the canvas. ScrollableFrame creates the frame and adds a binding on its <Configure> which calls ::ScrollableFrame::_frameConfigure 
That proc checks the [winfo width] and [winfo height] of the frame and takes the maximum width/height between the width/height of the frame and the width/height of the canvas and sets that as the -scrollregion of the canvas.

In other words, in the above example, the width/height of the frame is 100x100 and the one of the canvas is 500x500, so the -scrollregion of the canvas becomes [list 0 0 500 500].

Once we resize the window to 400x400 the scrollregion being [list 0 0 500 500] the scrollbar appears. And the reason why the -scrollregion doesn't get modified is that the frame doesn't get <Configured> since we resize to 400x400 and the frame is in 100x100 so its boundaries aren't touched, so the frame is not <Configured> so the ::ScrollableFrame::_frameConfigure doesn't get called, which is why the scrollregion isn't changed and the scrollbar appears.

I hope this isn't too confusing.. Anyways, my solution was to simply replace the _frameConfigure proc by a one lines : 
$canvas:cmd configure -scrollregion [$canvas:cmd bbox all]
This makes the scrollregion of the canvas be set to the frame's width/height so when we resize, the scrollbar doesn't appear, and if we resize to let's say 99x99, then the scrollbar appears because of the [$canvas:cmd bbox all]. If the frame's size is modified, then you get the <Configure> and the bbox will report the new size of the scrollregion.

Can you please make sure this patch gets into the next version of bwidget. 

p.s.: sorry if it's too long and difficult to understand, I'm not very good at explaining things...


Thank you,
KaKaRoTo
User Comments: oehhar added on 2009-06-16 22:09:46:
By direct mail, KaKaRoTo provided the following test script:

Anyways, the latest release is from 2006 and is 1.8.0 which is the same that we have in aMSN.. I just tried again to reproduce it (removing our workaround) and the issue is still there.. I wrote a small test program to reproduce it :
#!/usr/bin/wish
package require BWidget
wm geometry . 500x500
ScrolledWindow .sw
ScrollableFrame .sw.sf -constrainedwidth 1
.sw setwidget .sw.sf
pack .sw -anchor n -side top -expand true -fill both
set frm [.sw.sf getframe]
canvas $frm.c -width 100 -height 100 -bg white
pack $frm.c -expand false  
All you have to do is *slowly* resize the window to a smaller size and you'll see the scrollbar appearing..If you only resize the height (without modifying the width), then the scrollbar will become smaller and you can move it.. as soon as you click on it, it will disappear...
If you add these lines to the end of the script, the issue will disappear :
proc ::ScrollableFrame::_frameConfigure {canvas frame width height} {
   $canvas:cmd configure -scrollregion [$canvas:cmd bbox all]
}
I hope this was helpful and I hope you can fix it upstream soon!
Thank you,
KaKaRoTo

I have checked it:
- Release 1.8.0: issue is there
- current cvs: issue is not there (I don't know why but I don't bother
at the moment).

So if you allow, I will close the ticket without modifications on the current code.

oehhar added on 2009-06-11 15:15:53:
Hello KaKaRoTo,

thank you for the report.
I have tried to emulate the situation with the following script.
Unfortunately, I could not reproduce the situation.
May you:
- check if the issue is still there with the current implementation
- provide a demo script.

Thank you,
Harald

#-- Test script ---
wm geometry . 500x500
pack [ScrolledWindow .w -bg red] -fill both -expand true
ScrollableFrame .w.f -constrainedwidth 1 -bg green -height 500 -width 500
.w setwidget .w.f
set f [.w.f getframe]
pack [frame $f.f -bg yellow -width 100 -height 100]

kakaroto added on 2007-06-06 06:30:10:
Logged In: YES 
user_id=686750
Originator: NO

oups.. submitted as nobody. should be submitted as 'kakaroto'.