class Umbra::ToggleButton

A button that may be switched off an on. Extended by `RadioButton` and `Checkbox`. WARNING, pls do not override text otherwise checkboxes etc will stop functioning. TODO: add editable here and prevent toggling if not so.

Attributes

offvalue[RW]

set or get text to display for on value and off value

onvalue[RW]

set or get text to display for on value and off value

Public Class Methods

new(config={}) click to toggle source

Just calls super. @param config [Hash] config values such as row, col, onvalue, offvalue and value.

Calls superclass method Umbra::Button::new
# File lib/umbra/togglebutton.rb, line 35
def initialize config={}, &block
  super

end

Public Instance Methods

checked(tf) click to toggle source

set the value to true or false user may programmatically want to check or uncheck ## duplicate of value ??? 2018-05-26 -

# File lib/umbra/togglebutton.rb, line 106
def checked tf
  @value = tf
  @repaint_required = true
end
checked?() click to toggle source

is the button on or off @return [true, false] returns +@value+, has the button been checked or not.

# File lib/umbra/togglebutton.rb, line 55
def checked?
  @value
end
Also aliased as: selected?
fire() click to toggle source

Toggles the button's value. Called by toggle (when users pressed SPACE). Calls :PRESS event

# File lib/umbra/togglebutton.rb, line 93
def fire
  checked(!@value)
  #@item_event = ItemEvent.new self, self if @item_event.nil?
  #@item_event.set(@value ? :SELECTED : :DESELECTED)
  #fire_handler :PRESS, @item_event # should the event itself be ITEM_EVENT
  ## 2018-05-27 - trying to use self in most cases. Above was not needed.
  fire_handler :PRESS, self
end
getvalue() click to toggle source

@return [onvalue, offvalue] returns on or off value depending on +@value+.

# File lib/umbra/togglebutton.rb, line 41
def getvalue
  @value ? @onvalue : @offvalue
end
getvalue_for_paint() click to toggle source
# File lib/umbra/togglebutton.rb, line 60
def getvalue_for_paint
  # when the width is set externally then the surround chars sit outside the width
  #unless @width
  if @onvalue && @offvalue
    @width = [ @onvalue.length, @offvalue.length ].max 
  end
  #end
  buttontext = getvalue().center(@width)
  @text_offset = @surround_chars[0].length
  @surround_chars[0] + buttontext + @surround_chars[1]
end
handle_key(ch) click to toggle source

toggle button handle key. Handles only `space` (32), all others are passed to parent classes. @param ch [Integer] key received

Calls superclass method Umbra::Button#handle_key
# File lib/umbra/togglebutton.rb, line 75
def handle_key ch
  if ch == 32
    toggle
    @repaint_required = true # need to change the label
  else
    super
  end
end
selected?()
Alias for: checked?
toggle() click to toggle source

toggle the button value. Calls fire.

# File lib/umbra/togglebutton.rb, line 86
def toggle
  fire
end