Changeset 785 for trunk/gui/scripts/panes.tcl
- Timestamp:
- Jul 19, 2007, 5:21:51 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/panes.tcl
r428 r785 33 33 public method insert {pos args} 34 34 public method pane {pos} 35 public method visibility {pos {newval ""}} 35 36 public method fraction {pos {newval ""}} 36 37 public method hilite {state sash} … … 44 45 private variable _dispatcher "" ;# dispatcher for !events 45 46 private variable _panes "" ;# list of pane frames 47 private variable _visibility "" ;# list of visibilities for panes 46 48 private variable _counter 0 ;# counter for auto-generated names 47 private variable _frac 1.0 ;# list of fractions49 private variable _frac 0.0 ;# list of fractions 48 50 } 49 51 … … 74 76 75 77 lappend _panes $pname 78 lappend _visibility 1 79 set _frac 0.5 76 80 77 81 eval itk_initialize $args … … 128 132 frame $itk_interior.$pname 129 133 } 130 lappend _panes $pname 131 132 # fix the fractional sizes 133 set f $params(-fraction) 134 set _frac [list [expr {1-$f}] $f] 134 set _panes [linsert $_panes $pos $pname] 135 set _visibility [linsert $_visibility $pos 1] 136 set _frac [linsert $_frac $pos $params(-fraction)] 135 137 136 138 # fix sash characteristics … … 157 159 158 160 # ---------------------------------------------------------------------- 161 # USAGE: visibility <pos> ?<newval>? 162 # 163 # Clients use this to get/set the visibility of the pane at position 164 # <pos>. 165 # ---------------------------------------------------------------------- 166 itcl::body Rappture::Panes::visibility {pos {newval ""}} { 167 if {"" == $newval} { 168 return [lindex $_visibility $pos] 169 } 170 if {![string is boolean $newval]} { 171 error "bad value \"$newval\": should be boolean" 172 } 173 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_visibility])} { 174 set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]] 175 $_dispatcher event -idle !layout 176 } else { 177 error "bad index \"$pos\": out of range" 178 } 179 } 180 181 # ---------------------------------------------------------------------- 159 182 # USAGE: fraction <pos> ?<newval>? 160 183 # … … 170 193 } 171 194 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_frac])} { 172 # if there are other panes, adjust their size according to this 173 if {[llength $_frac] > 1} { 174 set oldval [lindex $_frac $pos] 175 set delta [expr {double($oldval-$newval)/([llength $_frac]-1)}] 176 for {set i 0} {$i < [llength $_frac]} {incr i} { 177 set v [lindex $_frac $i] 178 set _frac [lreplace $_frac $i $i [expr {$v+$delta}]] 179 } 180 } 181 set _frac [lreplace $_frac $pos $pos $newval] 195 set len [llength $_frac] 196 set _frac [lreplace $_frac $pos $pos xxx] 197 set total 0 198 foreach f $_frac { 199 if {"xxx" != $f} { 200 set total [expr {$total+$f}] 201 } 202 } 203 for {set i 0} {$i < $len} {incr i} { 204 set f [lindex $_frac $i] 205 if {"xxx" == $f} { 206 set f $newval 207 } else { 208 set f [expr {$f/$total - $newval/double($len-1)}] 209 } 210 set _frac [lreplace $_frac $i $i $f] 211 } 182 212 $_dispatcher event -idle !layout 183 213 } else { … … 243 273 set frac 0.95 244 274 } 245 246 set _frac [list $frac [expr {1-$frac}]] 275 if {[llength $_frac] == 2} { 276 set _frac [list $frac [expr {1-$frac}]] 277 } else { 278 set i [expr {[lsearch $_panes $pname]-1}] 279 if {$i >= 0} { 280 set _frac [lreplace $_frac $i $i $frac] 281 } 282 } 247 283 _fixLayout 248 284 … … 267 303 itcl::body Rappture::Panes::_fixLayout {args} { 268 304 set h [winfo height $itk_component(hull)] 269 foreach p [lrange $_panes 1 end] { 270 set h [expr {$h - [winfo height $itk_component(${p}sash)]}] 271 } 272 305 306 set plist "" 307 set flist "" 308 foreach p $_panes f $_frac v $_visibility { 309 set sash ${p}sash 310 if {$v} { 311 # this pane is visible -- make room for it 312 lappend plist $p 313 lappend flist $f 314 if {[info exists itk_component($sash)]} { 315 set h [expr {$h - [winfo height $itk_component($sash)]}] 316 } 317 } else { 318 # this pane is not visible -- remove sash 319 if {[info exists itk_component($sash)]} { 320 place forget $itk_component($sash) 321 } 322 place forget $itk_component($p) 323 } 324 } 325 326 # normalize the fractions so they add up to 1 327 set total 0 328 foreach f $flist { set total [expr {$total+$f}] } 329 set newflist "" 330 foreach f $flist { 331 lappend newflist [expr {double($f)/$total}] 332 } 333 set flist $newflist 334 335 # lay out the various panes 273 336 set y 0 274 foreach p $ _panes f $_frac{337 foreach p $plist f $flist { 275 338 set sash ${p}sash 276 339 if {[info exists itk_component($sash)]} {
Note: See TracChangeset
for help on using the changeset viewer.