Class: SparkleMotion::LaunchPad::Widgets::Toggle

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

Overview

Class to represent a single toggle button.

Direct Known Subclasses

Button

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:, position: nil, x: nil, y: nil, on:, off:, down:, on_press: nil, value: 0) ⇒ Toggle

Returns a new instance of Toggle.



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

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

Instance Attribute Details

#on_pressObject

Returns the value of attribute on_press.



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

def on_press
  @on_press
end

Instance Method Details

#renderObject



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

def render
  val = (value != 0) ? on : off
  if @x
    change_grid(x: 0, y: 0, color: val)
  else
    change_command(position: @position, color: val)
  end
  super
end

#update(new_val) ⇒ Object



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

def update(new_val)
  @value = new_val ? 1 : 0
  render
end