Class: TkWrapper::Widgets::Base::Widget

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, TkExtensions
Defined in:
lib/widgets/base/widget.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: {}, childs: [], manager: nil, ids: []) ⇒ Widget

Returns a new instance of Widget.



20
21
22
23
24
25
26
27
28
# File 'lib/widgets/base/widget.rb', line 20

def initialize(config: {}, childs: [], manager: nil, ids: [])
  @cell = TkWrapper::Util::Tk::Cell.new(self)
  @winfo = TkWrapper::Widgets::Base::WindowInfo.new(self)
  @finder = TkWrapper::Util::Tk::Finder.new(widgets: self)
  @config = TkWrapper::Widgets::Base::Configuration.new(config)
  @childs = childs.is_a?(Array) ? childs : [childs]
  @manager = manager
  @ids = ids.is_a?(Array) ? ids : [ids]
end

Instance Attribute Details

#cellObject (readonly)

Returns the value of attribute cell.



16
17
18
# File 'lib/widgets/base/widget.rb', line 16

def cell
  @cell
end

#childsObject (readonly)

Returns the value of attribute childs.



16
17
18
# File 'lib/widgets/base/widget.rb', line 16

def childs
  @childs
end

#configObject

Returns the value of attribute config.



15
16
17
# File 'lib/widgets/base/widget.rb', line 15

def config
  @config
end

#idsObject (readonly)

Returns the value of attribute ids.



16
17
18
# File 'lib/widgets/base/widget.rb', line 16

def ids
  @ids
end

#managerObject (readonly)

Returns the value of attribute manager.



16
17
18
# File 'lib/widgets/base/widget.rb', line 16

def manager
  @manager
end

#parentObject (readonly)

Returns the value of attribute parent.



16
17
18
# File 'lib/widgets/base/widget.rb', line 16

def parent
  @parent
end

#winfoObject (readonly)

Returns the value of attribute winfo.



16
17
18
# File 'lib/widgets/base/widget.rb', line 16

def winfo
  @winfo
end

Instance Method Details

#build(parent, configure: true, manager: nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/widgets/base/widget.rb', line 50

def build(parent, configure: true, manager: nil)
  @parent = parent
  tk_widget # creates the widget if possible and not yet created
  @font = TkWrapper::Util::Tk::Font.new(tk_widget)
  @manager ||= manager
  @config.merge(*@manager.configurations(self)) if @manager
  self.configure if configure
  @manager&.execute_modifications(self)
  @manager&.widgets&.push(self)
  build_childs
end

#build_childsObject



46
47
48
# File 'lib/widgets/base/widget.rb', line 46

def build_childs
  @childs.each { |child| child.build(self, manager: @manager) }
end

#configureObject



62
63
64
65
# File 'lib/widgets/base/widget.rb', line 62

def configure
  @config.configure_tk_widget(tk_widget)
  @config.configure_tearoff
end

#create_tk_widget(parent) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/widgets/base/widget.rb', line 30

def create_tk_widget(parent)
  tk_class = @config[:tk_class] || self.tk_class

  return unless tk_class

  tk_class.new(parent&.tk_widget)
end

#each(&block) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/widgets/base/widget.rb', line 67

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

#push(child) ⇒ Object



76
77
78
79
# File 'lib/widgets/base/widget.rb', line 76

def push(child)
  @childs.push(child)
  child.build(self, manager: @manager)
end

#tk_classObject



18
# File 'lib/widgets/base/widget.rb', line 18

def tk_class() end

#tk_widget(parent = @parent) ⇒ Object

if parent is provided and self has no tk_class, the tk_widget of the parent is returned, if parent is not nil



40
41
42
43
44
# File 'lib/widgets/base/widget.rb', line 40

def tk_widget(parent = @parent)
  return @tk_widget if @tk_widget

  (@tk_widget = create_tk_widget(parent)) || parent&.tk_widget
end