class PPCurses::MenuItem
Attributes
selectable[RW]
state[RW]
target[RW]
Who to notify when menu is selected chosen? The target should be a method selector, and
title[RW]
Public Class Methods
new( title )
click to toggle source
# File lib/ppcurses/menu/menu_item.rb, line 20 def initialize( title ) @title = title @state = PP_OFF_STATE @selectable = false end
Public Instance Methods
call_target()
click to toggle source
# File lib/ppcurses/menu/menu_item.rb, line 47 def call_target unless @target.nil? case @target.arity when 0 @target.call when 1 @target.call(self) else raise ArgumentError, "Too many parameters for target don't know what to do" end end end
display_string()
click to toggle source
# File lib/ppcurses/menu/menu_item.rb, line 26 def display_string if @state == PP_OFF_STATE return ' ' + @title end SELECTED_CHAR + ' ' + @title end
handle_key(key)
click to toggle source
# File lib/ppcurses/menu/menu_item.rb, line 62 def handle_key(key) if key == ' ' and @selectable toggle_on_off_state call_target return true end if key == ENTER call_target return true end false end
toggle_on_off_state()
click to toggle source
# File lib/ppcurses/menu/menu_item.rb, line 35 def toggle_on_off_state if @state == PP_OFF_STATE @state = PP_ON_STATE return end if @state == PP_ON_STATE @state = PP_OFF_STATE end end