Module: Tk::Place

Included in:
Widget
Defined in:
lib/ffi-tk/command/place.rb

Overview

Geometry manager for fixed or rubber-sheet placement

The placer is a geometry manager for Tk. It provides simple fixed placement of windows, where you specify the exact size and location of one window, called the slave, within another window, called the master. The placer also provides rubber-sheet placement, where you specify the size and location of the slave in terms of the dimensions of the master, so that the slave changes size and location in response to changes in the size of the master. Lastly, the placer allows you to mix these styles of placement so that, for example, the slave has a fixed width and height but is centered inside the master.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure(window, options = None) ⇒ Object

Query or modify the geometry options of the slave given by window. If no option is specified, this command returns a list describing the available options (see Tk_ConfigureInfo for information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more options are specified, then the command modifies the given option(s) to have the given value(s); in this case the command returns nil.



35
36
37
# File 'lib/ffi-tk/command/place.rb', line 35

def self.configure(window, options = None)
  Configure.common(Tk, [:place, :configure, window], options)
end

.forget(window) ⇒ Object



39
40
41
# File 'lib/ffi-tk/command/place.rb', line 39

def self.forget(window)
  Tk.execute_only('place', 'forget', window)
end

.info(window) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ffi-tk/command/place.rb', line 43

def self.info(window)
  info = Tk.execute('place', 'info', window).to_s

  array = info.split.each_slice(2).map do |key, value|
    case key = key[1..-1].to_sym
    when :anchor, :in
      [key, value]
    when :bordermode
      [key, value.to_sym]
    when :height, :width, :x, :y
      [key, value.to_i]
    when :relheight, :relwidth, :relx, :rely
      [key, value.to_f]
    else
      raise 'Unknown info pair: %p => %p' % [key, value]
    end
  end

  Hash[array]
end

.place(window, options = {}) ⇒ Object

Arrange for the placer to manage the geometry of a window. The remaining arguments consist of a hash that specifies the way in which window‘s geometry is managed. Option may have any of the values accepted by [Place.configure].



20
21
22
23
# File 'lib/ffi-tk/command/place.rb', line 20

def self.place(window, options = {})
  args = options.map { |k, v| ["-#{k}", v] }.flatten
  Tk.execute_only('place', window, *args)
end

.slaves(window) ⇒ Object



64
65
66
# File 'lib/ffi-tk/command/place.rb', line 64

def self.slaves(window)
  Tk.execute('place', 'slaves', window)
end

Instance Method Details

#place(options = {}) ⇒ Object



68
69
70
# File 'lib/ffi-tk/command/place.rb', line 68

def place(options = {})
  Place.place(self, options)
end

#place_configure(options = None) ⇒ Object



72
73
74
# File 'lib/ffi-tk/command/place.rb', line 72

def place_configure(options = None)
  Place.configure(self, options)
end

#place_forgetObject



76
77
78
# File 'lib/ffi-tk/command/place.rb', line 76

def place_forget
  Place.forget(self)
end

#place_infoObject



80
81
82
# File 'lib/ffi-tk/command/place.rb', line 80

def place_info
  Place.info(self)
end

#place_slavesObject



84
85
86
# File 'lib/ffi-tk/command/place.rb', line 84

def place_slaves
  Place.slaves(self)
end