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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



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

def initialize(parent: nil, config: {}, childs: [], manager: nil, ids: [], id: [])
  @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)
  @manager = manager
  @ids = init_id(id) + init_id(ids)
  @parent = parent
  modify_configuration(@config)
  @childs = normalize_childs(childs)
  parent&.push(self)
end

Instance Attribute Details

#cellObject (readonly)

Returns the value of attribute cell.



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

def cell
  @cell
end

#childsObject (readonly)

Returns the value of attribute childs.



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

def childs
  @childs
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#idsObject (readonly)

Returns the value of attribute ids.



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

def ids
  @ids
end

#managerObject (readonly)

Returns the value of attribute manager.



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

def manager
  @manager
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#winfoObject (readonly)

Returns the value of attribute winfo.



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

def winfo
  @winfo
end

Instance Method Details

#create_tk_widget(parent) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/widgets/base/widget.rb', line 43

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



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

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

#init_id(id) ⇒ Object



34
35
36
# File 'lib/widgets/base/widget.rb', line 34

def init_id(id)
  id.is_a?(Array) ? id : [id]
end

#normalize_childs(childs) ⇒ Object



38
39
40
41
# File 'lib/widgets/base/widget.rb', line 38

def normalize_childs(childs)
  childs = create_childs || childs
  childs.is_a?(Array) ? childs : [childs]
end

#push(child) ⇒ Object



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

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

#tk_classObject



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

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



53
54
55
56
57
# File 'lib/widgets/base/widget.rb', line 53

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

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