lib/sup/horizontal-selector.rb in sup-0.12.1 vs lib/sup/horizontal-selector.rb in sup-0.13.0

- old
+ new

@@ -1,17 +1,18 @@ module Redwood class HorizontalSelector - attr_accessor :label + attr_accessor :label, :changed_by_user 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 def set_to val; @selection = @vals.index(val) end def val; @vals[@selection] end @@ -22,11 +23,11 @@ sprintf "%#{width}s ", @label else "#{@label} " end - [[@base_color, label]] + + [[@base_color, label]] + (0 ... @labels.length).inject([]) do |array, i| array + [ if i == @selection [@selected_color, @labels[i]] else @@ -35,13 +36,15 @@ end + [[@base_color, ""]] end def roll_left @selection = (@selection - 1) % @labels.length + @changed_by_user = true end def roll_right @selection = (@selection + 1) % @labels.length + @changed_by_user = true end end end