class RETerm::Components::DropDownMenu
CDK Drop Down Menu Component
Public Class Methods
new(args={})
click to toggle source
Initialize the Menu component
@param [Hash] args menu params @option args [Array<Hash<String, Symbol>>] :menus array of menus,
each an hash of item labels / values
@option args [Array<Symbol>] :locs locations of menus @option args [Symbol] :pos menu position (default top) @option args [ColorPair] :color color to assign to drop down
menu items
@option args [ColorPair] :backound color pair to assign to
menu bar background color
Calls superclass method
RETerm::Component::new
# 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
Public Instance Methods
activate!(*input)
click to toggle source
Calls superclass method
RETerm::CDKComponent#activate!
# 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?()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 29 def background? !!@background end
draw!()
click to toggle source
Calls superclass method
RETerm::CDKComponent#draw!
# File lib/reterm/components/drop_down_menu.rb, line 58 def draw! super @bgwin.mvaddstr(0, 0, ' ' * requested_cols) if background? end
finalize!()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 33 def finalize! @bgwin.finalize! if background? end
highlight_focus?()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 96 def highlight_focus? false end
requested_cols()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 50 def requested_cols total_cols + total_sp + 3 end
requested_rows()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 54 def requested_rows max_items + 2 end
selected()
click to toggle source
# 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
size()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 46 def size @menus.size end
window=(w)
click to toggle source
Calls superclass method
RETerm::Component#window=
# 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
Private Instance Methods
_component()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 114 def _component locs = @locs.collect { |l| (l == :left) ? CDK::LEFT : (l == :right ? CDK::RIGHT : l)} pos = (@pos == :top) ? CDK::TOP : (@pos == :bottom) ? CDK::BOTTOM : @pos c = CDK::MENU.new(window.cdk_scr, colored_menu_list, size, submenu_sizes, locs, pos, Ncurses::A_UNDERLINE, Ncurses::A_REVERSE) m = self callback = lambda do |cdktype, menu, component, key| component.dispatch :changed end c.setPostProcess(callback, self) c end
max_items()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 110 def max_items @menus.max { |m1, m2| m1.size <=> m2.size }.size end
total_cols()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 102 def total_cols menu_list.sum { |m| m.first.size } end
total_sp()
click to toggle source
# File lib/reterm/components/drop_down_menu.rb, line 106 def total_sp menu_list.size - 1 end