class Tk::TkGeometry

Public Class Methods

new(tcl_string) click to toggle source
# File lib/ffi-tk/geometry.rb, line 4
def initialize(tcl_string)
  str = tcl_string.to_s

  if /^\=?(?<width>\d+)x(?<height>\d+)(?<x>[+-]\d+)(?<y>[+-]\d+)$/ =~ str
    self.width = Integer(width)
    self.height = Integer(height)
    self.x = Integer(x)
    self.y = Integer(y)
  elsif /^\=?(?<width>\d+)x(?<height>\d+)$/ =~ str
    self.width = Integer(width)
    self.height = Integer(height)
  elsif /^\=?(?<x>[+-]\d+)(?<y>[+-]\d+)$/ =~ str
    self.x = Integer(x)
    self.y = Integer(y)
  else
    raise 'Invalid geometry: %p' % [tcl_string]
  end
end

Public Instance Methods

to_tcl() click to toggle source
# File lib/ffi-tk/geometry.rb, line 23
def to_tcl
  if width && height && x && y
    '=%dx%d%+d%+d' % [width, height, x, y]
  elsif width && height
    '=%dx%d%' % [width, height]
  elsif x && y
    '=+d%+d' % [x, y]
  else
    raise 'Incomplete geometry: %p' % [self]
  end
end