Class: TkWrapper::Widgets::Menu

Inherits:
Base::Widget show all
Defined in:
lib/widgets/menu.rb

Defined Under Namespace

Classes: Cascade, Command

Instance Attribute Summary

Attributes inherited from Base::Widget

#cell, #childs, #config, #ids, #manager, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Widget

#configure, #create_tk_widget, #each, #initialize, #push, #tk_widget

Constructor Details

This class inherits a constructor from TkWrapper::Widgets::Base::Widget

Class Method Details

.create(structure: [], config: {}) ⇒ Object



34
35
36
37
38
39
# File 'lib/widgets/menu.rb', line 34

def self.create(structure: [], config: {})
  new(
    config: config,
    childs: structure.map { |entry| create_subentry(entry) }
  )
end

.create_subentries(structure) ⇒ Object



41
42
43
44
45
46
# File 'lib/widgets/menu.rb', line 41

def self.create_subentries(structure)
  return [] unless structure && !structure.nil?

  structure = [structure] unless structure.is_a?(Array)
  structure.map { |entry| create_subentry(**entry) }
end

.create_subentry(entry) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/widgets/menu.rb', line 48

def self.create_subentry(entry)
  case entry
  in { config: config, structure: st }
    return Cascade.new config: config, childs: create_subentries(st)
  else
    return Command.new config: entry
  end
end

Instance Method Details

#build(parent, **args) ⇒ Object



8
9
10
11
# File 'lib/widgets/menu.rb', line 8

def build(parent, **args)
  super(parent, **args)
  parent.tk_widget['menu'] = tk_widget
end

#tk_classObject



4
5
6
# File 'lib/widgets/menu.rb', line 4

def tk_class
  TkWidgets::TkMenu
end