Class: RETerm::Components::ButtonBox

Inherits:
RETerm::Component show all
Includes:
ButtonHelpers, RETerm::CDKComponent
Defined in:
lib/reterm/components/button_box.rb

Overview

CDK ButtonBox Component

Constant Summary

Constants included from LogHelpers

LogHelpers::LOG_FILE

Instance Attribute Summary collapse

Attributes inherited from RETerm::Component

#activatable, #activate_focus, #highlight_focus, #window

Instance Method Summary collapse

Methods included from ButtonHelpers

#total_button_size

Methods included from RETerm::CDKComponent

#activatable?, #bind_key, #cdk?, #colors=, #component, #deactivate!, #draw!, #early_exit?, #erase, #escape_hit?, #init?, #init_cdk, #normal_exit?, #strip_formatting, #title_attrib=, #value

Methods inherited from RETerm::Component

#activatable?, #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 = {}) ⇒ ButtonBox

Initialize the ButtonBox component

Parameters:

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

    button box params

Options Hash (args):

  • :widget (Component)

    component to include in the button box

  • :title (String)

    title to assign to button box

  • :buttons (String, Array<String>)

    string buttons to assign to dialog

[View source]

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

def initialize(args={})
  super
  @widget  = args[:widget]
  @title   = args[:title] || ""
  @buttons = [args[:buttons]].flatten.compact

  @buttons = ["OK", "Cancel"] if @buttons.empty?
end

Instance Attribute Details

#widgetObject

Returns the value of attribute widget.


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

def widget
  @widget
end

Instance Method Details

#activate!(*input) ⇒ Object

[View source]

53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/reterm/components/button_box.rb', line 53

def activate!(*input)
  widget.draw!
  component.draw(true)

  if widget.activatable?
    widget.activate!(*input)
  else
    super
  end

  @buttons[component.current_button]
end

#close!Object

[View source]

37
38
39
40
41
42
43
# File 'lib/reterm/components/button_box.rb', line 37

def close!
  widget.erase
  widget.finalize!

  window.erase
  window.finalize!
end

#requested_colsObject

[View source]

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

def requested_cols
  [@title.size, total_button_size, @widget.requested_cols].max
end

#requested_rowsObject

[View source]

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

def requested_rows
  @widget.requested_rows
end

#selectedObject

[View source]

66
67
68
# File 'lib/reterm/components/button_box.rb', line 66

def selected
  @buttons[component.current_button]
end

#window=(win) ⇒ Object

Raises:

  • (ArgumentError)
[View source]

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

def window=(win)
  super(win)
  cw = win.create_child :rows => widget.requested_rows,
                        :cols => [widget.requested_cols, requested_cols].max
  raise ArgumentError, "could not create child" if cw.win.nil?
  cw.component = widget
end