class Canis::ToggleButton

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

Public Class Methods

new(form, config={}) click to toggle source
Calls superclass method Canis::Button::new
# File lib/canis/core/widgets/rwidget.rb, line 3378
def initialize form, config={}, &block
  super
  
  @value ||= (@variable.nil? ? false : @variable.get_value(@name)==true)
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

# File lib/canis/core/widgets/rwidget.rb, line 3439
def checked tf
  @value = tf
  if @variable
    if @value 
      @variable.set_value((@onvalue || 1), @name)
    else
      @variable.set_value((@offvalue || 0), @name)
    end
  end
end
checked?() click to toggle source

added for some standardization 2010-09-07 20:28 alias :text :getvalue # NEXT VERSION change existing text to label

is the button on or off added 2008-12-09 19:05

# File lib/canis/core/widgets/rwidget.rb, line 3395
def checked?
  @value
end
Also aliased as: selected?
fire() click to toggle source

called on :PRESS event caller should check state of itemevent passed to block

# File lib/canis/core/widgets/rwidget.rb, line 3430
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
end
getvalue() click to toggle source
# File lib/canis/core/widgets/rwidget.rb, line 3383
def getvalue
  @value ? @onvalue : @offvalue
end
getvalue_for_paint() click to toggle source
# File lib/canis/core/widgets/rwidget.rb, line 3400
def getvalue_for_paint
  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 @param [int] key received

Calls superclass method Canis::Button#handle_key
# File lib/canis/core/widgets/rwidget.rb, line 3414
def handle_key ch
  if ch == 32
    toggle
  else
    super
  end
end
selected?()
Alias for: checked?
toggle() click to toggle source

toggle the button value

# File lib/canis/core/widgets/rwidget.rb, line 3424
def toggle
  fire
end