Tk Source Code

Artifact [fd10c33f]
Login

Artifact fd10c33f1c7ee8d91fbd3295d150d6b77d513b71:

Attachment "32k-pixels-test.tcl" to ticket [2891877f] added by kjnash 2009-11-04 19:34:28.
# Initialise global variables

set helpText {
Source this file to investigate sizing problems
with a scrolled frame on a canvas.

Use the command
    another n
(where n is a positive integer) to add n text
widgets to the scrolled frame.

To empty the scrolled frame and restart, use the command
    restart

The scrolled frame can be made extremely tall, but the vertical
range that can be viewed by scrolling is never much more than
32k pixels.
(tested with ActiveTcl 8.5.7.1 and ActiveTcl 8.6.0.0b2 on Linux x86)

When the i'th text widget is created, the command prints
(with heights in pixels):

i -- height of text widget -- height of scrolled frame

}

set numText 0

array set colors {
    0  #FFFFFF
    1  #CCFFFF
    2  #FFCCFF
    3  #FFFFCC
}


# Scrolled Canvas http://wiki.tcl.tk/9268

canvas .c -yscrollcommand {.vs set} -width 400 -height 600
scrollbar .vs -orient vertical   -command {.c yview}
grid .c  -row 0 -column 0 -sticky nsew
grid .vs -row 0 -column 1 -sticky ns

grid columnconfigure . 0 -weight 1
grid rowconfigure    . 0 -weight 1


# Frame item for canvas

frame .c.f
.c create window 0 0 -anchor nw -window .c.f
bind .c.f <Configure> RefreshCanvas


# Commands

# Create and map one more text widget in the scrolled frame

proc AnotherOne {} {
    global numText
    global colors

    incr numText
    set scrolledFrame .c.f
    set col [expr {$numText % 4}]
    set newText $scrolledFrame.text$numText

    text $newText -height 50 -bg $colors($col)
    pack $newText

    update idletasks
    set key "i -- height of text widget -- height of scrolled frame\n"
    set sizing "$numText -- [winfo height $newText] -- [winfo height $scrolledFrame]"
    $newText insert end "TEXT WIDGET $numText\n"
    $newText insert end $key
    $newText insert end $sizing
    puts $sizing
    return
}

# Create and map N more text widgets in the scrolled frame

proc another {N} {
    for {set i 0} {$i < $N} {incr i} {
        AnotherOne
    }
    return
}

# Re-initialise and start again

proc restart {} {
    ReInit
    StartUp
    return
}

# Reset to empty frame

proc ReInit {} {
    global numText
    set numText 0
    set scrolledFrame .c.f
    destroy {*}[winfo children $scrolledFrame]
    $scrolledFrame configure -height 20 -width 200
    return
}

# Print help text, draw one text widget, set width of "."

proc StartUp {} {
    global helpText
    puts $helpText

    another 1
    .c.f.text1 insert end "\n"
    .c.f.text1 insert end $helpText

    wm geometry . {}
    return
}

# Resize the canvas scrollregion - call this whenever the canvas contents change

proc RefreshCanvas {} {
    .c configure -scrollregion [.c bbox all]
    .c configure -width [winfo reqwidth .c.f]
    return
}


restart