📄 panewd.tcl
字号:
set frac(${num}) [expr {$frac([expr ${num} + 1]) - ${min}}] } } # ------------------------------------------------------------------ # METHOD start-grip - Starts the sash drag and drop operation # ------------------------------------------------------------------ method start-grip {where num} { grab $itk_component(hull).handle${num} raise $itk_component(hull).sep${num} raise $itk_component(hull).handle${num} $itk_component(hull).handle${num} configure -relief sunken set drag_start ${where} } # ------------------------------------------------------------------ # METHOD end-grip - Ends the sash drag and drop operation # ------------------------------------------------------------------ method end-grip {where num} { calc-fraction ${where} ${num} $itk_component(hull).handle${num} configure -relief raised grab release $itk_component(hull).handle${num} replace } # ------------------------------------------------------------------ # METHOD handle-grip - Motion action for sash # ------------------------------------------------------------------ method handle-grip {where num} { calc-fraction ${where} ${num} if {$itk_option(-orientation) == "y"} { place $itk_component(hull).sep${num} -in $itk_component(hull).pw -relx 0 -relwidth 1\ -rely $frac(${num}) -anchor w place $itk_component(hull).handle${num} -in $itk_component(hull).pw -relx ${handlePos}\ -rely $frac(${num}) -anchor center } else { place $itk_component(hull).sep${num} -in $itk_component(hull).pw -rely 0 -relheight 1\ -relx $frac(${num}) -anchor n place $itk_component(hull).handle${num} -in $itk_component(hull).pw -rely ${handlePos}\ -relx $frac(${num}) -anchor center } } # ------------------------------------------------------------------ # METHOD replace - Resets the panes of the window following # movement of the sash # ------------------------------------------------------------------ method replace {} { if {[winfo exists $itk_component(hull).pane0]} { if {$itk_option(-orientation) == "y"} { place $itk_component(hull).pane0 -in $itk_component(hull).pw -x 0 -rely 0 -relwidth 1\ -relheight $frac(1) for {set i 1} {${i} < $itk_option(-number)} {incr i} { place $itk_component(hull).sep${i} -in $itk_component(hull).pw -relx 0 -relwidth 1\ -rely $frac(${i}) -anchor w place $itk_component(hull).handle${i} -in $itk_component(hull).pw -relx ${handlePos}\ -rely $frac(${i}) -anchor center place $itk_component(hull).pane${i} -in $itk_component(hull).pw -x 0\ -rely $frac(${i}) -relwidth 1 -relheight\ [expr $frac([expr ${i} + 1]) - $frac(${i})] lower $itk_component(hull).sep${i} raise $itk_component(hull).handle${i} } } else { place $itk_component(hull).pane0 -in $itk_component(hull).pw -y 0 -relx 0 -relheight 1\ -relwidth $frac(1) for {set i 1} {${i} < $itk_option(-number)} {incr i} { place $itk_component(hull).sep${i} -in $itk_component(hull).pw -rely 0 -relheight 1\ -relx $frac(${i}) -anchor w place $itk_component(hull).handle${i} -in $itk_component(hull).pw -rely ${handlePos}\ -relx $frac(${i}) -anchor center place $itk_component(hull).pane${i} -in $itk_component(hull).pw -y 0\ -relx $frac(${i}) -relheight 1 -relwidth\ [expr $frac([expr ${i} + 1]) - $frac(${i})] lower $itk_component(hull).sep${i} raise $itk_component(hull).handle${i} } } } } # ------------------------------------------------------------------ # METHOD panes - Return the list of panes # ------------------------------------------------------------------ method panes {} { set panes "" for {set i 0} {${i} < $itk_option(-number)} {incr i} { lappend panes $itk_component(hull).pane${i} } return ${panes} } # ------------------------------------------------------------------ # METHOD fractions - Return the current list of fractions # ------------------------------------------------------------------ method fractions {} { set fracs "" for {set i 1} {${i} < $itk_option(-number)} {incr i} { lappend fracs $frac(${i}) } return ${fracs} } # ------------------------------------------------------------------ # ATTRIBUTE minimum - Minimum percentage of a pane # ------------------------------------------------------------------ itk_option define -min min Min 0.1 { if {[expr $itk_option(-min) < 0.0 || $itk_option(-min) > 1.0]} { error "min size must be 0.0-1.0" } } # ------------------------------------------------------------------ # ATTRIBUTE fraction - Initial percentage of visible area # ------------------------------------------------------------------ itk_option define -fraction fraction Fraction {0.5} { set i 0 set frac(0) 0 foreach f $itk_option(-fraction) { incr i set frac(${i}) ${f} if {$frac(${i}) <= $frac([expr ${i}-1])} { error "fractions must be in ascending order" } } incr i set frac(${i}) 1 if {$itk_option(-number) != ${i}} { configure -number ${i} } replace } # ------------------------------------------------------------------ # ATTRIBUTE width - Set the frame width # ------------------------------------------------------------------ itk_option define -width width Width 50 { if {[winfo exists $itk_component(hull)]} { $itk_component(hull).pw configure -width $itk_option(-width) } } # ------------------------------------------------------------------ # ATTRIBUTE height - Set the frame height # ------------------------------------------------------------------ itk_option define -height height Height 50 { if {[winfo exists $itk_component(hull)]} { $itk_component(hull).pw config -height $itk_option(-height) } } # ------------------------------------------------------------------ # ATTRIBUTE number - Set the number of panes # ------------------------------------------------------------------ itk_option define -number number Number 2 { if {$itk_option(-number) < 2} { error "number of panes must be 2 or more" } set frac(0) 0 if {[array size frac] != [expr $itk_option(-number) + 2]} { #-fraction not called yet set part [expr 1.0 / $itk_option(-number).0] for {set i 1} {${i} <= $itk_option(-number)} {incr i} { set frac(${i}) [expr ${i} * ${part}] } } } # ------------------------------------------------------------------ # ATTRIBUTE orientation - Set the pane orientation. "y" means the # sashes are horizontal (the children are packed from top to # bottom). "x" gives a vertical orientation. # ------------------------------------------------------------------ itk_option define -orientation orientation Orientation y { if {$itk_option(-orientation) != "y" && $itk_option(-orientation) != "x"} { error "orientation must be x or y" } } # ------------------------------------------------------------------ # ATTRIBUTE handleSide - Side of the sash on which to put the # handle. # ------------------------------------------------------------------ itk_option define -handleSide handleSide HandleSide end { if {$itk_option(-handleSide) == "begin"} { set handlePos 0.05 }\ elseif {$itk_option(-handleSide) == "end"} { set handlePos 0.95 } else { error "handleSide must be begin or end" } } protected variable drag_start protected variable frac protected variable handlePos 0.95}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -