Class: Tk::RbWidget::AlignBox

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

Direct Known Subclasses

HBox, VBox

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ AlignBox

Returns a new instance of AlignBox.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'sample/tkalignbox.rb', line 22

def initialize(*args)
  if self.class == Tk::RbWidget::AlignBox
    fail RuntimeError, "Tk::AlignBox 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



125
126
127
# File 'sample/tkalignbox.rb', line 125

def propagate
  @propagate
end

Instance Method Details

#<<(widget) ⇒ Object



77
78
79
# File 'sample/tkalignbox.rb', line 77

def <<(widget)
  add(widget)
end

#add(*widgets) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'sample/tkalignbox.rb', line 62

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



51
52
53
54
55
56
57
58
59
60
# File 'sample/tkalignbox.rb', line 51

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



94
95
96
97
98
99
100
101
102
103
104
105
# File 'sample/tkalignbox.rb', line 94

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



81
82
83
84
85
86
87
88
89
90
91
92
# File 'sample/tkalignbox.rb', line 81

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



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

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

#pady(size = nil) ⇒ Object



116
117
118
119
120
121
122
123
# File 'sample/tkalignbox.rb', line 116

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