Class: SparkleMotion::LaunchPad::Widgets::VerticalSlider

Inherits:
SparkleMotion::LaunchPad::Widget show all
Defined in:
lib/sparkle_motion/launch_pad/widgets/vertical_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) ⇒ VerticalSlider

Returns a new instance of VerticalSlider.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sparkle_motion/launch_pad/widgets/vertical_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:     1,
        height:    size,
        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/vertical_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/vertical_slider.rb', line 21

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

#update(*args) ⇒ Object



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

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