commit 6c90cdbb2c32be26662e2214a236494e4e629053
parent 94dabfc3559c54e4d8c1603029c3bfda5eedceb4
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Sat, 8 Dec 2007 22:13:33 +0000
whoops, forgot to add this to svn
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@748 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
1 file changed, 66 insertions(+), 0 deletions(-)
diff --git a/lib/sup/horizontal-selector.rb b/lib/sup/horizontal-selector.rb
@@ -0,0 +1,66 @@
+module Redwood
+
+class HorizontalSelector
+ attr_accessor :label
+
+ 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
+
+ def set_to val; @selection = @vals.index(val) end
+
+ def val; @vals[@selection] end
+
+ def old_line width=nil
+ label =
+ if width
+ sprintf "%#{width}s ", @label
+ else
+ "#{@label} "
+ end
+
+ [[:none, label]] +
+ (0 ... @labels.length).inject([]) do |array, i|
+ array + [
+ if i == @selection
+ [@selected_color, "[" + @labels[i] + "]"]
+ else
+ [@base_color, " " + @labels[i] + " "]
+ end] + [[:none, " "]]
+ end + [[:none, ""]]
+ end
+
+ def line width=nil
+ label =
+ if width
+ sprintf "%#{width}s ", @label
+ else
+ "#{@label} "
+ end
+
+ [[:none, label]] +
+ (0 ... @labels.length).inject([]) do |array, i|
+ array + [
+ if i == @selection
+ [@selected_color, @labels[i]]
+ else
+ [@base_color, @labels[i]]
+ end] + [[:none, " "]]
+ end + [[:none, ""]]
+ end
+
+ def roll_left
+ @selection = (@selection - 1) % @labels.length
+ end
+
+ def roll_right
+ @selection = (@selection + 1) % @labels.length
+ end
+end
+
+end