Class: Redwood::HorizontalSelector
- Defined in:
- lib/sup/horizontal_selector.rb
Defined Under Namespace
Classes: UnknownValue
Instance Attribute Summary collapse
-
#changed_by_user ⇒ Object
Returns the value of attribute changed_by_user.
-
#label ⇒ Object
Returns the value of attribute label.
Instance Method Summary collapse
- #can_set_to?(val) ⇒ Boolean
-
#initialize(label, vals, labels, base_color = :horizontal_selector_unselected_color, selected_color = :horizontal_selector_selected_color) ⇒ HorizontalSelector
constructor
A new instance of HorizontalSelector.
- #line(width = nil) ⇒ Object
- #roll_left ⇒ Object
- #roll_right ⇒ Object
- #set_to(val) ⇒ Object
- #val ⇒ Object
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.
8 9 10 11 12 13 14 15 16 |
# File 'lib/sup/horizontal_selector.rb', line 8 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 @changed_by_user = false end |
Instance Attribute Details
#changed_by_user ⇒ Object
Returns the value of attribute changed_by_user.
6 7 8 |
# File 'lib/sup/horizontal_selector.rb', line 6 def changed_by_user @changed_by_user end |
#label ⇒ Object
Returns the value of attribute label.
6 7 8 |
# File 'lib/sup/horizontal_selector.rb', line 6 def label @label end |
Instance Method Details
#can_set_to?(val) ⇒ Boolean
23 24 25 |
# File 'lib/sup/horizontal_selector.rb', line 23 def can_set_to? val @vals.include? val end |
#line(width = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sup/horizontal_selector.rb', line 29 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_left ⇒ Object
48 49 50 51 |
# File 'lib/sup/horizontal_selector.rb', line 48 def roll_left @selection = (@selection - 1) % @labels.length @changed_by_user = true end |
#roll_right ⇒ Object
53 54 55 56 |
# File 'lib/sup/horizontal_selector.rb', line 53 def roll_right @selection = (@selection + 1) % @labels.length @changed_by_user = true end |
#set_to(val) ⇒ Object
18 19 20 21 |
# File 'lib/sup/horizontal_selector.rb', line 18 def set_to val raise UnknownValue, val.inspect unless can_set_to? val @selection = @vals.index(val) end |
#val ⇒ Object
27 |
# File 'lib/sup/horizontal_selector.rb', line 27 def val; @vals[@selection] end |