Method: Fidgit::Slider#initialize

Defined in:
lib/fidgit/elements/slider.rb

#initialize(options = {}, &block) ⇒ Slider

Returns a new instance of Slider.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :range (Range) — default: 0.0..1.0
  • :value (Range) — default: minimum of :range


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fidgit/elements/slider.rb', line 54

def initialize(options = {}, &block)
  options = {
    range: 0.0..1.0,
    height: 25,
    background_color: default(:background_color),
    border_color: default(:border_color),
    groove_color: default(:groove_color),
    handle_color: default(:handle_color),
    groove_thickness: 5,
  }.merge! options

  @range = options[:range].dup
  @groove_color = options[:groove_color].dup
  @groove_thickness = options[:groove_thickness]
  @continuous = @range.min.is_a?(Float) || @range.max.is_a?(Float)

  super(options)

  @handle = Handle.new(parent: self, width: (height / 2 - padding_left), height: height - padding_top + padding_bottom,
                       background_color: options[:handle_color])

  self.value = options.has_key?(:value) ? options[:value] : @range.min
end