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

#childs, #config, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Widget

#check_match, config, #configure, #create_tk_widget, #find, #find_all, #ids, #initialize, manager, #manager, modify, #push, #tk_widget

Constructor Details

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

Class Method Details

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



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

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

.create_subentries(structure) ⇒ Object



38
39
40
41
42
43
# File 'lib/widgets/menu.rb', line 38

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



45
46
47
48
49
50
51
52
# File 'lib/widgets/menu.rb', line 45

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) ⇒ Object



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

def build(parent)
  super(parent)
  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