Class: SparkleMotion::LaunchPad::Widgets::RadioGroup

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

Overview

Class to represent a radio-button group 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_select: nil, on_deselect:, value: nil) ⇒ RadioGroup

Returns a new instance of RadioGroup.



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

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

Instance Attribute Details

#on_deselectObject

Returns the value of attribute on_deselect.



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

def on_deselect
  @on_deselect
end

#on_selectObject

Returns the value of attribute on_select.



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

def on_select
  @on_select
end

Instance Method Details

#renderObject



23
24
25
26
27
28
29
30
31
# File 'lib/sparkle_motion/launch_pad/widgets/radio_group.rb', line 23

def render
  (0..max_x).each do |xx|
    (0..max_y).each do |yy|
      col = (value == index_for(x: xx, y: yy)) ? on : off

      change_grid(x: xx, y: yy, color: col)
    end
  end
end

#update(*args) ⇒ Object



33
34
35
36
37
# File 'lib/sparkle_motion/launch_pad/widgets/radio_group.rb', line 33

def update(*args)
  super(*args)
  on_select.call(value) if on_select && value
  on_deselect.call(value) if on_deselect && !value
end