Posted to tcl by aspect at Sat May 17 04:41:46 GMT 2014view pretty

# use as you would a labelframe: eg:
#  grid [CollapsingFrame .f -text "Clicky"] -sticky nsew
#  grid [text .t1] -in .f -sticky nsew

snit::widgetadaptor CollapsingFrame {
    component b
    delegate option -text to b
    delegate option -textvariable to b
    delegate option * to hull
    delegate method * to hull
    constructor args {
        installhull using labelframe
        install b using label $win.b
        $self configurelist $args
        $self configure -labelwidget $b
        bind $b <1> [mymethod collapse]
    }
    method collapse {} {
        set C "+" ;#\u25ba
        set O "-" ;#\u25bc
        set h [winfo height $b]
        incr h 2
        set f [winfo parent $b]
        set title [$b cget -text]
        set title [string trimleft $title "$C$O "]
        if {[grid propagate $f]} {
            grid propagate $f 0
            $f configure -height $h
            $b configure -text "$C $title"
        } else {
            grid propagate $f 1
            $f configure -height 0
            $b configure -text "$O $title"
        }
    }
}