Class: RETerm::Components::Rocker

Inherits:
RETerm::Component show all
Includes:
RETerm::ComponentInput, ItemHelpers
Defined in:
lib/reterm/components/rocker.rb

Overview

Rocker component, allowing use to select one of several items

Constant Summary

Constants included from RETerm::CommonKeys

RETerm::CommonKeys::DEC_CONTROLS, RETerm::CommonKeys::ENTER_CONTROLS, RETerm::CommonKeys::INC_CONTROLS, RETerm::CommonKeys::QUIT_CONTROLS

Constants included from LogHelpers

LogHelpers::LOG_FILE

Instance Attribute Summary collapse

Attributes included from RETerm::CommonControls

#quit_on_enter

Attributes inherited from RETerm::Component

#activatable, #activate_focus, #highlight_focus, #window

Instance Method Summary collapse

Methods included from ItemHelpers

#max_item_size

Methods included from RETerm::ComponentInput

#bind_key, #handle_input, #key_bound?, #on_enter, #on_key

Methods included from RETerm::CommonControls

#quit_on_enter?

Methods inherited from RETerm::Component

#activate_focus?, #cdk?, #colored?, #colors=, #deactivate!, #deactivate?, #distance_from, #extra_padding, #finalize!, #highlight_focus?, #reactivate!, #resize, #sync!, #sync_getch

Methods included from KeyBindings

#bind_key, #invoke_key_bindings, #key_bindings, #key_bound?

Methods included from LogHelpers

#logger

Methods included from EventDispatcher

#dispatch, #handle

Constructor Details

#initialize(args = {}) ⇒ Rocker

Initialize the Rocker component

Examples:

using the Rocker

win    = Window.new
rocker = Rocker.new
win.component = rocker
rocker.items = ['Foo', 'Bar', 'Baz']
val = rocker.activate!

Parameters:

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

    rocker params



21
22
23
24
25
26
27
# File 'lib/reterm/components/rocker.rb', line 21

def initialize(args={})
  super
  @items = []
  @index  = nil
  @labels = true
  @index  = 0
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



8
9
10
# File 'lib/reterm/components/rocker.rb', line 8

def index
  @index
end

#itemsObject

Returns the value of attribute items.



8
9
10
# File 'lib/reterm/components/rocker.rb', line 8

def items
  @items
end

#labelsObject

Returns the value of attribute labels.



8
9
10
# File 'lib/reterm/components/rocker.rb', line 8

def labels
  @labels
end

Instance Method Details

#activatable?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/reterm/components/rocker.rb', line 41

def activatable?
  true
end

#activate!(*input) ⇒ Object



45
46
47
48
49
# File 'lib/reterm/components/rocker.rb', line 45

def activate!(*input)
  refresh_win
  handle_input(*input)
  @items[@index]
end

#draw!Object



37
38
39
# File 'lib/reterm/components/rocker.rb', line 37

def draw!
  refresh_win
end

#requested_colsObject



33
34
35
# File 'lib/reterm/components/rocker.rb', line 33

def requested_cols
  max_item_size + 3
end

#requested_rowsObject



29
30
31
# File 'lib/reterm/components/rocker.rb', line 29

def requested_rows
  @items.size + 3
end