class PPCurses::MenuBar
The menubar is activated and deactivated by the ESCAPE key.
Any responders further down the responder chain will never receive ESCAPE key events.
Attributes
selected[RW]
Public Class Methods
new()
click to toggle source
# File lib/ppcurses/menu_bar.rb, line 13 def initialize @menu_items = [] @selected = false end
Public Instance Methods
key_down( key )
click to toggle source
# File lib/ppcurses/menu_bar.rb, line 55 def key_down( key ) if key == ESCAPE @selected = !@selected return end if @selected @menu_items.each do |menu_item| if key == menu_item.key menu_item.action.call return end end return end @next_responder.key_down(key) unless @next_responder.nil? end
show(screen)
click to toggle source
Expects screen to be a PPCurses::Screen
object Need to convert to work with a window or a view.
# File lib/ppcurses/menu_bar.rb, line 20 def show(screen) screen.set_pos_by_point(ZERO_POINT) if @selected screen.attron(A_REVERSE) else screen.attron(A_UNDERLINE) end @menu_items.each do |menu_item| screen.addstr( "#{menu_item} ") end p = screen.cur_point screen.addstr( ' ' * (screen.width - p.x) ) if @selected screen.attroff(A_REVERSE) else screen.attroff(A_UNDERLINE) end end