Class: SparkleMotion::LaunchPad::Widgets::HorizontalSlider

Inherits:
SparkleMotion::LaunchPad::Widget show all
Defined in:
lib/sparkle_motion/launch_pad/widgets/horizontal_slider.rb

Overview

Class to represent a slider-style control on a Novation Launchpad.

Instance Attribute Summary collapse

Attributes inherited from SparkleMotion::LaunchPad::Widget

#down, #height, #off, #on, #value, #width, #x, #y

Instance Method Summary collapse

Methods inherited from SparkleMotion::LaunchPad::Widget

#blank, #max_v

Constructor Details

#initialize(launchpad:, x:, y:, size:, on:, off:, down:, on_change: nil, value: 0) ⇒ HorizontalSlider

Returns a new instance of HorizontalSlider.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sparkle_motion/launch_pad/widgets/horizontal_slider.rb', line 8

def initialize(launchpad:, x:, y:, size:, on:, off:, down:, on_change: nil, value: 0)
  super(launchpad: launchpad,
        x:         x,
        y:         y,
        width:     size,
        height:    1,
        on:        on,
        off:       off,
        down:      down,
        value:     value)
  @on_change = on_change
end

Instance Attribute Details

#on_changeObject

Returns the value of attribute on_change.



6
7
8
# File 'lib/sparkle_motion/launch_pad/widgets/horizontal_slider.rb', line 6

def on_change
  @on_change
end

Instance Method Details

#renderObject



21
22
23
24
25
26
# File 'lib/sparkle_motion/launch_pad/widgets/horizontal_slider.rb', line 21

def render
  (0..max_v).each do |xx|
    change_grid(x: xx, y: 0, color: (value && value >= xx) ? on : off)
  end
  super
end

#update(*args) ⇒ Object



28
29
30
31
# File 'lib/sparkle_motion/launch_pad/widgets/horizontal_slider.rb', line 28

def update(*args)
  super(*args)
  on_change.call(value) if on_change
end