Class: Redwood::HorizontalSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/sup/horizontal-selector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, vals, labels, base_color = :horizontal_selector_unselected_color, selected_color = :horizontal_selector_selected_color) ⇒ HorizontalSelector

Returns a new instance of HorizontalSelector.



6
7
8
9
10
11
12
13
# File 'lib/sup/horizontal-selector.rb', line 6

def initialize label, vals, labels, base_color=:horizontal_selector_unselected_color, selected_color=:horizontal_selector_selected_color
  @label = label
  @vals = vals
  @labels = labels
  @base_color = base_color
  @selected_color = selected_color
  @selection = 0
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



4
5
6
# File 'lib/sup/horizontal-selector.rb', line 4

def label
  @label
end

Instance Method Details

#line(width = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sup/horizontal-selector.rb', line 19

def line width=nil
  label =
    if width
      sprintf "%#{width}s ", @label
    else
      "#{@label} "
    end

  [[@base_color, label]] + 
    (0 ... @labels.length).inject([]) do |array, i|
      array + [
        if i == @selection
          [@selected_color, @labels[i]]
        else
          [@base_color, @labels[i]]
        end] + [[@base_color, "  "]]
    end + [[@base_color, ""]]
end

#roll_leftObject



38
39
40
# File 'lib/sup/horizontal-selector.rb', line 38

def roll_left
  @selection = (@selection - 1) % @labels.length
end

#roll_rightObject



42
43
44
# File 'lib/sup/horizontal-selector.rb', line 42

def roll_right
  @selection = (@selection + 1) % @labels.length
end

#set_to(val) ⇒ Object



15
# File 'lib/sup/horizontal-selector.rb', line 15

def set_to val; @selection = @vals.index(val) end

#valObject



17
# File 'lib/sup/horizontal-selector.rb', line 17

def val; @vals[@selection] end