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
set or get text to display for on value and off value
set or get text to display for on value and off value
Public Class Methods
Just calls super. @param config [Hash] config values such as row, col, onvalue, offvalue and value.
Umbra::Button::new
# File lib/umbra/togglebutton.rb, line 35 def initialize config={}, &block super end
Public Instance Methods
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
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
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
@return [onvalue, offvalue] returns on or off value depending on +@value+.
# File lib/umbra/togglebutton.rb, line 41 def getvalue @value ? @onvalue : @offvalue end
# 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
toggle button handle key. Handles only `space` (32), all others are passed to parent classes. @param ch [Integer] key received
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
toggle the button value. Calls fire
.
# File lib/umbra/togglebutton.rb, line 86 def toggle fire end