Class: Tk::TkGeometry

Inherits:
Struct
  • Object
show all
Defined in:
lib/ffi-tk/geometry.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (TkGeometry) initialize(tcl_string)

A new instance of TkGeometry



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ffi-tk/geometry.rb', line 3

def initialize(tcl_string)
  case tcl_string.to_s
  when /^\=?(?<width>\d+)x(?<height>\d+)(?<x>[+-]\d+)(?<y>[+-]\d+)$/
    md = $~
    self.width, self.height, self.x, self.y =
      md[:width].to_i, md[:height].to_i, md[:x].to_i, md[:y].to_i
  when /^\=?(?<width>\d+)x(?<height>\d+)$/
    md = $~
    self.width, self.height = md[:width].to_i, md[:height].to_i
  when /^\=?(?<x>[+-]\d+)(?<y>[+-]\d+)$/
    md = $~
    self.x, self.y = md[:x].to_i, md[:y].to_i
  else
    raise "Invalid geometry: %p" % [tcl_string]
  end
end

Instance Attribute Details

- (Object) height

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



2
3
4
# File 'lib/ffi-tk/geometry.rb', line 2

def height
  @height
end

- (Object) original

Returns the value of attribute original

Returns:

  • (Object)

    the current value of original



2
3
4
# File 'lib/ffi-tk/geometry.rb', line 2

def original
  @original
end

- (Object) width

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



2
3
4
# File 'lib/ffi-tk/geometry.rb', line 2

def width
  @width
end

- (Object) x

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



2
3
4
# File 'lib/ffi-tk/geometry.rb', line 2

def x
  @x
end

- (Object) y

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



2
3
4
# File 'lib/ffi-tk/geometry.rb', line 2

def y
  @y
end

Instance Method Details

- (Object) to_tcl



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ffi-tk/geometry.rb', line 20

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