Sha256: 25a11c6888427439cc9c96907d678139e4639c56462707d5114fb8b065f4d960
Contents?: true
Size: 1.88 KB
Versions: 3
Compression:
Stored size: 1.88 KB
Contents
require 'vedeu' require 'vedeu/support/events' module Vedeu class Menu def initialize(collection) @collection = collection @current = 0 @selected = nil @events = events end def events @_events ||= Vedeu.events.add(self) do on(:menu_next) { next_item } on(:menu_prev) { prev_item } on(:menu_top) { top_item } on(:menu_bottom) { bottom_item } on(:menu_select) { select_item } on(:menu_deselect) { deselect_item } on(:menu_selected) { selected_item } on(:menu_current) { current_item } on(:menu_items) { items } end end def current @current end def selected @selected end def current_item @collection[@current] end def selected_item return nil unless @selected @collection[@selected] end def items items = [] @collection.each_with_index do |item, index| if index == @current && index == @selected items << [true, true, item] elsif index == @current items << [false, true, item] elsif index == @selected items << [true, false, item] else items << [false, false, item] end end items end def view items[@current, @collection.size] end def top_item @current = 0 items end def bottom_item @current = last items end def next_item @current += 1 if @current < last items end def prev_item @current -= 1 if @current > 0 items end def select_item @selected = @current items end def deselect_item @selected = nil items end def last @collection.size - 1 end def size @collection.size end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.1.2 | lib/vedeu/support/menu.rb |
vedeu-0.1.1 | lib/vedeu/support/menu.rb |
vedeu-0.1.0 | lib/vedeu/support/menu.rb |