Tuesday, September 18, 2012

Text Zooming

The widgets in the Tk package have the really nifty sub-command cget which enables the settings for widget options to be extracted. Implementation of cget functionality within Gnocl is patchy for the most part as in most cases custom code needs to be added to extract settings. I've just added cget -baseFont for the text widget. This means that simple text zooming can be implemented in conjunction with the -onScroll option.

# text widget zoom
# arguments
#    w    text widget id
#    d    direction of scroll, ie up or down.
#    s    state of keytboard modifiers, must be Ctrl+scroll to run.
# returns
#    nil
proc TextZoom {w d s} {
  if { [$w class] != "text" } { return -1 }
  set fnt "[$w cget -baseFont]"
  set fsize [lindex $fnt 1]

  if {$s != 4} { return }

  switch $d {
      up { incr fsize 2 }
      down {incr fsize -2 }
  lset fnt 1 $fsize  
  eval $w configure -baseFont [list $fnt]