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.



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

def self.configure(window, options = None)
  if options == None
    Tk.execute('place', 'configure', window)
  else
    Tk.execute_only('place', 'configure', window, options)
  end
end

.forget(window) ⇒ Object



42
43
44
# File 'lib/ffi-tk/command/place.rb', line 42

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

.info(window) ⇒ Object



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

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

  array = info.split.each_slice(2).map{|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
  }

  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].



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

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

.slaves(window) ⇒ Object



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

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

Instance Method Details

#place(options = {}) ⇒ Object



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

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

#place_configure(options = None) ⇒ Object



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

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

#place_forgetObject



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

def place_forget
  Place.forget(self)
end

#place_infoObject



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

def place_info
  Place.info(self)
end

#place_slavesObject



87
88
89
# File 'lib/ffi-tk/command/place.rb', line 87

def place_slaves
  Place.slaves(self)
end