Class: TkWrapper::Widgets::Base::Widget
- Inherits:
-
Object
- Object
- TkWrapper::Widgets::Base::Widget
show all
- Extended by:
- Forwardable
- Includes:
- Enumerable, TkExtensions
- Defined in:
- lib/widgets/base/widget.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config: {}, childs: [], id: nil) ⇒ Widget
Returns a new instance of Widget.
Instance Attribute Details
#cell ⇒ Object
Returns the value of attribute cell.
21
22
23
|
# File 'lib/widgets/base/widget.rb', line 21
def cell
@cell
end
|
#childs ⇒ Object
Returns the value of attribute childs.
21
22
23
|
# File 'lib/widgets/base/widget.rb', line 21
def childs
@childs
end
|
#config ⇒ Object
Returns the value of attribute config.
20
21
22
|
# File 'lib/widgets/base/widget.rb', line 20
def config
@config
end
|
#ids ⇒ Object
Returns the value of attribute ids.
21
22
23
|
# File 'lib/widgets/base/widget.rb', line 21
def ids
@ids
end
|
#parent ⇒ Object
Returns the value of attribute parent.
21
22
23
|
# File 'lib/widgets/base/widget.rb', line 21
def parent
@parent
end
|
Class Method Details
.config(matcher = nil, configuration = nil, **configurations) ⇒ Object
29
30
31
|
# File 'lib/widgets/base/widget.rb', line 29
def self.config(matcher = nil, configuration = nil, **configurations)
manager.add_configurations(matcher, configuration, **configurations)
end
|
.modify(matcher, &callback) ⇒ Object
33
34
35
|
# File 'lib/widgets/base/widget.rb', line 33
def self.modify(matcher, &callback)
manager.add_modification(matcher, &callback)
end
|
Instance Method Details
#add_ids(ids) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/widgets/base/widget.rb', line 60
def add_ids(ids)
return unless ids
ids = [ids] unless ids.is_a?(Array)
@ids.concat(ids)
end
|
#build(parent, configure: true) ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/widgets/base/widget.rb', line 83
def build(parent, configure: true)
@parent = parent
tk_widget @font = TkWrapper::Util::Tk::Font.new(tk_widget)
self.configure if configure
manager.execute_modifications(self)
@childs.each { |child| child.build(self) }
end
|
97
98
99
100
101
|
# File 'lib/widgets/base/widget.rb', line 97
def configure
@config.merge_global_configurations(manager, self)
@config.configure_tk_widget(tk_widget)
@config.configure_tearoff
end
|
67
68
69
70
71
72
73
|
# File 'lib/widgets/base/widget.rb', line 67
def create_tk_widget(parent)
tk_class = @config[:tk_class] || self.tk_class
return unless tk_class
parent&.tk_widget ? tk_class.new(parent.tk_widget) : tk_class.new
end
|
#each(&block) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/widgets/base/widget.rb', line 41
def each(&block)
nodes_to_walk = [self]
until nodes_to_walk.empty?
node = nodes_to_walk.pop
block.call(node)
nodes_to_walk = node.childs + nodes_to_walk
end
end
|
#modify(matchers, &callback) ⇒ Object
103
104
105
106
107
|
# File 'lib/widgets/base/widget.rb', line 103
def modify(matchers, &callback)
items = find_all(matchers)
callback.call(items)
end
|
#modify_each(matchers, &callback) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/widgets/base/widget.rb', line 109
def modify_each(matchers, &callback)
items = find_all(matchers)
return unless items
with_match = items[0].is_a?(Array)
items.each do |item|
with_match ? callback.call(item[0], item[1]) : callback.call(item)
end
end
|
#push(child) ⇒ Object
92
93
94
95
|
# File 'lib/widgets/base/widget.rb', line 92
def push(child)
@childs.push(child)
child.build(self)
end
|
#tk_class ⇒ Object
23
|
# File 'lib/widgets/base/widget.rb', line 23
def tk_class() end
|
if parent is provided and self has no tk_class, the tk_widget of the parent is returned, if parent is not nil
77
78
79
80
81
|
# File 'lib/widgets/base/widget.rb', line 77
def tk_widget(parent = @parent)
return @tk_widget if @tk_widget
(@tk_widget = create_tk_widget(parent)) || parent&.tk_widget
end
|