Class: Redwood::HorizontalSelector
- Inherits:
-
Object
- Object
- Redwood::HorizontalSelector
- Defined in:
- lib/sup/horizontal-selector.rb
Instance Attribute Summary (collapse)
-
- (Object) label
Returns the value of attribute label.
Instance Method Summary (collapse)
-
- (HorizontalSelector) initialize(label, vals, labels, base_color = :horizontal_selector_unselected_color, selected_color = :horizontal_selector_selected_color)
constructor
A new instance of HorizontalSelector.
- - (Object) line(width = nil)
- - (Object) roll_left
- - (Object) roll_right
- - (Object) set_to(val)
- - (Object) val
Constructor Details
- (HorizontalSelector) initialize(label, vals, labels, base_color = :horizontal_selector_unselected_color, selected_color = :horizontal_selector_selected_color)
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
- (Object) label
Returns the value of attribute label
4 5 6 |
# File 'lib/sup/horizontal-selector.rb', line 4 def label @label end |
Instance Method Details
- (Object) line(width = nil)
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 |
- (Object) roll_left
38 39 40 |
# File 'lib/sup/horizontal-selector.rb', line 38 def roll_left @selection = (@selection - 1) % @labels.length end |
- (Object) roll_right
42 43 44 |
# File 'lib/sup/horizontal-selector.rb', line 42 def roll_right @selection = (@selection + 1) % @labels.length end |
- (Object) set_to(val)
15 |
# File 'lib/sup/horizontal-selector.rb', line 15 def set_to val; @selection = @vals.index(val) end |
- (Object) val
17 |
# File 'lib/sup/horizontal-selector.rb', line 17 def val; @vals[@selection] end |