summaryrefslogtreecommitdiff
path: root/lib/vdr/osd/item.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vdr/osd/item.rb')
-rw-r--r--lib/vdr/osd/item.rb48
1 files changed, 44 insertions, 4 deletions
diff --git a/lib/vdr/osd/item.rb b/lib/vdr/osd/item.rb
index 4c78040..ce4a18a 100644
--- a/lib/vdr/osd/item.rb
+++ b/lib/vdr/osd/item.rb
@@ -20,20 +20,60 @@
module Vdr
module Osd
+ #
+ # An #Item represents an entry in an OSD #Menu.
+ # Each item has a #text that will be shown on the menu and a
+ # #context which can be used to store any kind of object
+ # associated with this menu item.
+ #
+ # == Example
+ #
+ # new_menu = Menu.new('A simple menu') do |menu|
+ # menu.add_item(Item.new('First Item').on_select { puts 'Item 1 selected' })
+ # new_item = Item.new('Second Item') do |item|
+ # item.context = { :first_name => 'James Tiberius', :last_name => 'Kirk' }
+ # item.on_select do |selected_item|
+ # name = selected_item.context
+ # puts "Selected #{name[:last_name]}, #{name[:first_name]}"
+ # end
+ # end
+ # menu.add_item(new_item)
+ # end
+ #
class Item < Vdr::Swig::COsdItem
+
+ # The text of the item which will be shown on its parent #Menu
attr_reader :text
+
+ # A free assignable context associated with an #Item
attr_accessor :context
- def initialize(text = nil)
+ #
+ # Creates a new item. If _text_ is given, it will become the text displayed on the
+ # parent menu for this item.
+ #
+ # Item.new('my item') #=> Creates a new item shown with 'my item'
+ # Item.new {|i| i.title = 'another item'} #=> Creates a new item and sets its title to 'another item'
+ #
+ def initialize(text = nil) # :yields: item
@text = text
super(text)
+ yield self if block_given?
+ end
+
+ # Change the item text
+ def text=(text)
+ @text = text
+ set_text(text)
end
- def on_select(&block)
- @select = block
+ # The block assigned to on_select will be executed, when
+ # the item is selected from the menu
+ def on_select(&block) # :yields: item
+ @select = block
end
- def process_key(key)
+ def process_key(key) # :nodoc:
state = super(key)
if key == Vdr::Swig::KOk
if @select