Sha256: 30c90316e7018fc8aece95f92ea2d4452d2dc3635998cd8c6d84bb2cce851e10

Contents?: true

Size: 1.01 KB

Versions: 14

Compression:

Stored size: 1.01 KB

Contents

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 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

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

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

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sup-0.12.1 lib/sup/horizontal-selector.rb
sup-0.12 lib/sup/horizontal-selector.rb
sup-0.11 lib/sup/horizontal-selector.rb
sup-0.10.2 lib/sup/horizontal-selector.rb
sup-0.10.1 lib/sup/horizontal-selector.rb
sup-0.10 lib/sup/horizontal-selector.rb
sup-0.9.1 lib/sup/horizontal-selector.rb
sup-0.9 lib/sup/horizontal-selector.rb
sup-0.8.1 lib/sup/horizontal-selector.rb
sup-0.6 lib/sup/horizontal-selector.rb
sup-0.7 lib/sup/horizontal-selector.rb
sup-0.4 lib/sup/horizontal-selector.rb
sup-0.5 lib/sup/horizontal-selector.rb
sup-0.8 lib/sup/horizontal-selector.rb