Class: TkAlignBox

Inherits:
TkFrame show all
Defined in:
sample/tkalignbox.rb

Direct Known Subclasses

TkHBox, TkVBox

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ TkAlignBox

Returns a new instance of TkAlignBox.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'sample/tkalignbox.rb', line 14

def initialize(*args)
  if self.class == TkAlignBox
    fail RuntimeError, "TkAlignBox is an abstract class"
  end
  @padx = 0
  @pady = 0
  if args[-1].kind_of? Hash
    keys = _symbolkey2str(args.pop)
    @padx = keys.delete('padx') || 0
    @pady = keys.delete('pady') || 0
    args.push(keys)
  end
  super(*args)
  @max_width = 0
  @max_height = 0
  @propagate = true
  @widgets = []
end

Instance Attribute Details

#propagateObject

Returns the value of attribute propagate.



117
118
119
# File 'sample/tkalignbox.rb', line 117

def propagate
  @propagate
end

Instance Method Details

#<<(widget) ⇒ Object



69
70
71
# File 'sample/tkalignbox.rb', line 69

def <<(widget)
  add(widget)
end

#add(*widgets) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'sample/tkalignbox.rb', line 54

def add(*widgets)
  widgets.each{|w|
    unless w.kind_of? TkWindow
      fail RuntimeError, "#{w.inspect} is not a widget instance."
    end
    @widgets.delete(w)
    @widgets << w
    sz = w.winfo_reqwidth
    @max_width = sz if @max_width < sz
    sz = w.winfo_reqheight
    @max_height = sz if @max_height < sz
  }
  align
end

#alignObject



43
44
45
46
47
48
49
50
51
52
# File 'sample/tkalignbox.rb', line 43

def align
  widgets = []
  @widgets.each{|w| widgets << w if w.winfo_exist?}
  @widgets = widgets
  cnt = @widgets.size.to_f
  @widgets.each_with_index{|w, idx| _place_config(w, idx, cnt)}
  @widgets = widgets
  _set_framesize if @propagate
  self
end

#delete(idx) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'sample/tkalignbox.rb', line 86

def delete(idx)
  ret = @widgets.delete_at(idx)
  @req_size = 0
  @widget.each{|w|
    sz = w.winfo_reqwidth
    @max_width = sz if @max_width < sz
    sz = w.winfo_reqheight
    @max_height = sz if @max_height < sz
  }
  align
  ret
end

#insert(idx, widget) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'sample/tkalignbox.rb', line 73

def insert(idx, widget)
  unless widget.kind_of? TkWindow
    fail RuntimeError, "#{widget.inspect} is not a widget instance."
  end
  @widgets.delete(widget)
  @widgets[idx,0] = widget
  sz = widget.winfo_reqwidth
  @max_width = sz if @max_width < sz
  sz = widget.winfo_reqheight
  @max_height = sz if @max_height < sz
  align
end

#padx(size = nil) ⇒ Object



99
100
101
102
103
104
105
106
# File 'sample/tkalignbox.rb', line 99

def padx(size = nil)
  if size
    @padx = size
    align
  else
    @padx
  end
end

#pady(size = nil) ⇒ Object



108
109
110
111
112
113
114
115
# File 'sample/tkalignbox.rb', line 108

def pady(size = nil)
  if size
    @pady = size
    align
  else
    @pady
  end
end