Class: RETerm::Components::DropDownMenu

Inherits:
RETerm::Component show all
Includes:
RETerm::CDKComponent
Defined in:
lib/reterm/components/drop_down_menu.rb

Overview

CDK Drop Down Menu Component

Constant Summary

Constants included from LogHelpers

LogHelpers::LOG_FILE

Instance Attribute Summary

Attributes inherited from RETerm::Component

#activatable, #activate_focus, #highlight_focus, #window

Instance Method Summary collapse

Methods included from RETerm::CDKComponent

#activatable?, #bind_key, #cdk?, #colors=, #component, #deactivate!, #early_exit?, #erase, #escape_hit?, #init?, #init_cdk, #normal_exit?, #strip_formatting, #title_attrib=, #value

Methods inherited from RETerm::Component

#activatable?, #activate_focus?, #cdk?, #colored?, #colors=, #deactivate!, #deactivate?, #distance_from, #extra_padding, #reactivate!, #resize, #sync!, #sync_getch

Methods included from KeyBindings

#bind_key, #invoke_key_bindings, #key_bindings, #key_bound?

Methods included from LogHelpers

#logger

Methods included from EventDispatcher

#dispatch, #handle

Constructor Details

#initialize(args = {}) ⇒ DropDownMenu

Initialize the Menu component

Parameters:

  • args (Hash) (defaults to: {})

    menu params

Options Hash (args):

  • :menus (Array<Hash<String, Symbol>>)

    array of menus, each an hash of item labels / values

  • :locs (Array<Symbol>)

    locations of menus

  • :pos (Symbol)

    menu position (default top)

  • :color (ColorPair)

    color to assign to drop down menu items

  • :backound (ColorPair)

    color pair to assign to menu bar background color


18
19
20
21
22
23
24
25
26
27
# File 'lib/reterm/components/drop_down_menu.rb', line 18

def initialize(args={})
  super
  @menus = args[:menus] || []
  @locs  = args[:locs]  || 0.upto(size-1).collect { :left }
  @pos   = args[:pos]   || :top
  @color = args[:color]
  @background = args[:background]

  @prev = nil
end

Instance Method Details

#activate!(*input) ⇒ Object


87
88
89
90
91
92
93
94
# File 'lib/reterm/components/drop_down_menu.rb', line 87

def activate!(*input)
  r = super
  return nil if early_exit?
  m = r / 100
  i = r % 100

  @menus[m][@menus[m].keys[i+1]]
end

#background?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/reterm/components/drop_down_menu.rb', line 29

def background?
  !!@background
end

#colored_menu_listObject


41
42
43
44
# File 'lib/reterm/components/drop_down_menu.rb', line 41

def colored_menu_list
  return menu_list unless !!@color
  menu_list.collect { |ms| ms.collect { |m| "#{@color.cdk_fmt}#{m}" }}
end

#draw!Object


58
59
60
61
# File 'lib/reterm/components/drop_down_menu.rb', line 58

def draw!
  super
  @bgwin.mvaddstr(0, 0, ' ' * requested_cols) if background?
end

#finalize!Object


33
34
35
# File 'lib/reterm/components/drop_down_menu.rb', line 33

def finalize!
  @bgwin.finalize! if background?
end

#highlight_focus?Boolean

Returns:

  • (Boolean)

96
97
98
# File 'lib/reterm/components/drop_down_menu.rb', line 96

def highlight_focus?
  false
end

37
38
39
# File 'lib/reterm/components/drop_down_menu.rb', line 37

def menu_list
  @menus.collect { |m| m.keys }
end

#requested_colsObject


50
51
52
# File 'lib/reterm/components/drop_down_menu.rb', line 50

def requested_cols
  total_cols + total_sp + 3
end

#requested_rowsObject


54
55
56
# File 'lib/reterm/components/drop_down_menu.rb', line 54

def requested_rows
  max_items + 2
end

#selectedObject


83
84
85
# File 'lib/reterm/components/drop_down_menu.rb', line 83

def selected
  @menus[component.current_title][@menus[component.current_title].keys[component.current_subtitle+1]]
end

#sizeObject


46
47
48
# File 'lib/reterm/components/drop_down_menu.rb', line 46

def size
  @menus.size
end

79
80
81
# File 'lib/reterm/components/drop_down_menu.rb', line 79

def submenu_sizes
  @menus.collect { |m| m.size }
end

#window=(w) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/reterm/components/drop_down_menu.rb', line 63

def window=(w)
  win = super(w)

  # add a window to render menu bar background
  if background?
    c = win.create_child :x    => 0,
                         :y    => 0,
                         :rows => 1,
                         :cols => requested_cols - 2
    c.colors = @background
    @bgwin = c
  end

  win
end