📄 labeledframe.itk
字号:
# -----------------------------------------------------------------------------# OPTION: -labelmargin## Set the margin of the most adjacent side of the label to the hull# relief.# ----------------------------------------------------------------------------itcl::configbody iwidgets::Labeledframe::labelmargin { _positionLabel}# -----------------------------------------------------------------------------# OPTION: -labelpos## Set the position of the label within the relief of the hull frame# widget.# ----------------------------------------------------------------------------itcl::configbody iwidgets::Labeledframe::labelpos { _positionLabel}# -----------------------------------------------------------------------------# PROCS# -----------------------------------------------------------------------------# -----------------------------------------------------------------------------# PRIVATE PROC: _initTable## Initializes the _LAYOUT_TABLE common variable of the Labeledframe# class. The initialization is performed in its own proc ( as opposed# to in the class definition ) so that the initialization occurs only# once.## _LAYOUT_TABLE common array description:# Provides a table of the configuration option values# used to place the label widget within the grooved relief of the hull# frame for each of the 12 possible "-labelpos" values.## Each of the 12 rows is layed out as follows:# {"-relx" "-rely" <rowconfigure|columnconfigure> <row/column number>}# -----------------------------------------------------------------------------itcl::body iwidgets::Labeledframe::_initTable {} { array set _LAYOUT_TABLE { nw-relx 0.0 nw-rely 0.0 nw-wrap 0 nw-conf rowconfigure nw-num 0 n-relx 0.5 n-rely 0.0 n-wrap 0 n-conf rowconfigure n-num 0 ne-relx 1.0 ne-rely 0.0 ne-wrap 0 ne-conf rowconfigure ne-num 0 sw-relx 0.0 sw-rely 1.0 sw-wrap 0 sw-conf rowconfigure sw-num 2 s-relx 0.5 s-rely 1.0 s-wrap 0 s-conf rowconfigure s-num 2 se-relx 1.0 se-rely 1.0 se-wrap 0 se-conf rowconfigure se-num 2 en-relx 1.0 en-rely 0.0 en-wrap 1 en-conf columnconfigure en-num 2 e-relx 1.0 e-rely 0.5 e-wrap 1 e-conf columnconfigure e-num 2 es-relx 1.0 es-rely 1.0 es-wrap 1 es-conf columnconfigure es-num 2 wn-relx 0.0 wn-rely 0.0 wn-wrap 1 wn-conf columnconfigure wn-num 0 w-relx 0.0 w-rely 0.5 w-wrap 1 w-conf columnconfigure w-num 0 ws-relx 0.0 ws-rely 1.0 ws-wrap 1 ws-conf columnconfigure ws-num 0 } # # Since this is a one time only thing, we'll redefine the proc to be empty # afterwards so it only happens once. # # NOTE: Be careful to use the "body" command, or the proc will get lost! # itcl::body ::iwidgets::Labeledframe::_initTable {} {}}# -----------------------------------------------------------------------------# METHODS# -----------------------------------------------------------------------------# -----------------------------------------------------------------------------# PUBLIC METHOD:: childsite## -----------------------------------------------------------------------------itcl::body iwidgets::Labeledframe::childsite {} { return $itk_component(childsite)}# -----------------------------------------------------------------------------# PROTECTED METHOD: _positionLabel ?when?## Places the label in the relief of the hull. If "when" is "now", the# change is applied immediately. If it is "later" or it is not# specified, then the change is applied later, when the application# is idle.# -----------------------------------------------------------------------------itcl::body iwidgets::Labeledframe::_positionLabel {{when later}} { if {$when == "later"} { if {$_reposition == ""} { set _reposition [after idle [itcl::code $this _positionLabel now]] } return } set pos $itk_option(-labelpos) # # If there is not an entry for the "relx" value associated with # the given "-labelpos" option value, then it invalid. # if { [catch {set relx $_LAYOUT_TABLE($pos-relx)}] } { error "bad labelpos option\"$itk_option(-labelpos)\": should be\ nw, n, ne, sw, s, se, en, e, es, wn, w, or ws" } update idletasks $itk_component(label) configure -wraplength $_LAYOUT_TABLE($pos-wrap) set labelWidth [winfo reqwidth $itk_component(label)] set labelHeight [winfo reqheight $itk_component(label)] set borderwidth $itk_option(-borderwidth) set margin $itk_option(-labelmargin) switch $pos { nw { set labelThickness $labelHeight set minsize [expr {$labelThickness/2.0}] set xPos [expr {$minsize+$borderwidth+$margin}] set yPos -$minsize } n { set labelThickness $labelHeight set minsize [expr {$labelThickness/2.0}] set xPos [expr {-$labelWidth/2.0}] set yPos -$minsize } ne { set labelThickness $labelHeight set minsize [expr {$labelThickness/2.0}] set xPos [expr {-($minsize+$borderwidth+$margin+$labelWidth)}] set yPos -$minsize } sw { set labelThickness $labelHeight set minsize [expr {$labelThickness/2.0}] set xPos [expr {$minsize+$borderwidth+$margin}] set yPos -$minsize } s { set labelThickness $labelHeight set minsize [expr {$labelThickness/2.0}] set xPos [expr {-$labelWidth/2.0}] set yPos [expr {-$labelHeight/2.0}] } se { set labelThickness $labelHeight set minsize [expr {$labelThickness/2.0}] set xPos [expr {-($minsize+$borderwidth+$margin+$labelWidth)}] set yPos [expr {-$labelHeight/2.0}] } wn { set labelThickness $labelWidth set minsize [expr {$labelThickness/2.0}] set xPos -$minsize set yPos [expr {$minsize+$margin+$borderwidth}] } w { set labelThickness $labelWidth set minsize [expr {$labelThickness/2.0}] set xPos -$minsize set yPos [expr {-($labelHeight/2.0)}] } ws { set labelThickness $labelWidth set minsize [expr {$labelThickness/2.0}] set xPos -$minsize set yPos [expr {-($minsize+$borderwidth+$margin+$labelHeight)}] } en { set labelThickness $labelWidth set minsize [expr {$labelThickness/2.0}] set xPos -$minsize set yPos [expr {$minsize+$borderwidth+$margin}] } e { set labelThickness $labelWidth set minsize [expr {$labelThickness/2.0}] set xPos -$minsize set yPos [expr {-($labelHeight/2.0)}] } es { set labelThickness $labelWidth set minsize [expr {$labelThickness/2.0}] set xPos -$minsize set yPos [expr {-($minsize+$borderwidth+$margin+$labelHeight)}] } } _setMarginThickness $minsize place $itk_component(label) \ -relx $_LAYOUT_TABLE($pos-relx) -x $xPos \ -rely $_LAYOUT_TABLE($pos-rely) -y $yPos \ -anchor nw set what $_LAYOUT_TABLE($pos-conf) set number $_LAYOUT_TABLE($pos-num) grid $what $itk_interior $number -minsize $minsize set _reposition ""}# -----------------------------------------------------------------------------# PROTECTED METHOD: _collapseMargin## Resets the "-minsize" of all rows and columns of the hull's grid# used to set the label margin to 0# -----------------------------------------------------------------------------itcl::body iwidgets::Labeledframe::_collapseMargin {} { grid columnconfigure $itk_interior 0 -minsize 0 grid columnconfigure $itk_interior 2 -minsize 0 grid rowconfigure $itk_interior 0 -minsize 0 grid rowconfigure $itk_interior 2 -minsize 0}# -----------------------------------------------------------------------------# PROTECTED METHOD: _setMarginThickness## Set the margin thickness ( i.e. the hidden "-highlightthickness"# of the hull ) to the input value.## The "-highlightthickness" option of the hull frame is not intended to be# configured by users of this class, but does need to be configured to properly# place the label whenever the label is configured.## Therefore, since I can't find a better way at this time, I achieve this # configuration by: adding the "-highlightthickness" option back into# the hull frame; configuring the "-highlightthickness" option to properly# place the label; and then remove the "-highlightthickness" option from the# hull.## This way the option is not visible or configurable without some hacking.## -----------------------------------------------------------------------------itcl::body iwidgets::Labeledframe::_setMarginThickness {value} { itk_option add hull.highlightthickness $itk_component(hull) configure -highlightthickness $value itk_option remove hull.highlightthickness}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -